## Get Cluster Information
kubectl cluster-info
## List Available Contexts
kubectl config get-contexts
## View Current Context
kubectl config current-context
## List All Pods in the Current Namespace
kubectl get pods
## List Pods in All Namespaces
kubectl get pods --all-namespaces
## Describe a Specific Pod
kubectl describe pod <pod-name>
## Delete a Specific Pod
kubectl delete pod <pod-name>
## Create a Pod (or any resource) from a YAML file
kubectl apply -f <file.yaml>
## Get Logs from a Pod
kubectl logs <pod-name>
## Execute a Command in a Running Pod
kubectl exec -it <pod-name> -- /bin/bash
## List All Services
kubectl get services
## List All Deployments
kubectl get deployments
## Scale a Deployment
kubectl scale deployment <deployment-name> --replicas=<num>
## Perform a Rolling Restart of a Deployment
kubectl rollout restart deployment <deployment-name>
## Undo a Deployment Rollout
kubectl rollout undo deployment <deployment-name>
## List All Namespaces
kubectl get namespaces
## Set Default Namespace
kubectl config set-context --current --namespace=<namespace-name>
## Check Cluster Events
kubectl get events --sort-by='.metadata.creationTimestamp'
## Check Node Status
kubectl get nodes
## View Resource Usage (Pods)
kubectl top pod
## View Resource Usage (Nodes)
kubectl top node
## Expose a Deployment as a Service
kubectl expose deployment <deployment-name> --type=LoadBalancer --port=80
## Port Forward a Pod
kubectl port-forward pod/<pod-name> 8080:80
## View YAML Definition of a Pod
kubectl get pod <pod-name> -o yaml
k8s command collection
k8s command collection
2 minutes to read
ipang