- List all available contexts
kubectl config get-contexts
- Show current context
kubectl config curret-context
- Switch to a different context
kubectl config use-context {ctx_name}
- Set default namespace for a context
kubectl config set-context {ctx_name} --namespace={ns_name}
- Show cluster info
kubectl cluster-info
- List all namespaces
kubectl get namespaces
- Create namespace
kubectl create namespace {ns_name}
- Delete namespace
kubectl delete namespace {ns_name}
- List pods across all namespaces
kubectl get pods --all-namespaces
or
kubectl get pods --A
- List pods in current namespace (default)
kubectl get pods
- List pods for namespace
kubectl get pods --namespace {ns_name}
- List pods for namespace with more details
kubectl get pods --namespace {ns_name} -o wide
- Show details of a specific pod
kubectl describe pod {pod_name}
- Show CPU and memory usage for pods in namespace
kubectl top pod --namespace {ns_name}
- Fetch logs of a pod
kubectl logs {pod_name} --namespace {ns_name}
- Stream logs of a pod (stdout)
kubectl -f logs {pod_name} --namespace {ns_name}
- Access a running pod's shell
kubectl exec -it {pod_name} -- bash
- Show pod's ENV
kubectl exec -n {ns_name} {pod_name} -- env