A compact set of everyday-use commands for inspecting deployments, pods, logs, services, events, configmaps, and port-forwarding.
Replace /path/to/kubeconfig.yaml with your actual kubeconfig file.
kubectl --kubeconfig=/path/to/kubeconfig.yaml get deployment <name> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml describe deployment <name> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get deployment <name> -n <namespace> -o yamlkubectl --kubeconfig=/path/to/kubeconfig.yaml rollout status deployment/<name> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml rollout undo deployment/<name> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get pods -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get pods -n <namespace> -l app=<appname>kubectl --kubeconfig=/path/to/kubeconfig.yaml describe pod <pod-name> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get pod <pod-name> -n <namespace> -o yamlkubectl --kubeconfig=/path/to/kubeconfig.yaml logs <pod> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml logs -n <namespace> -l app=<appname>kubectl --kubeconfig=/path/to/kubeconfig.yaml logs -f <pod> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml logs <pod> -c <container> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get configmap -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get configmap <name> -n <namespace> -o yamlkubectl --kubeconfig=/path/to/kubeconfig.yaml describe configmap <name> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml describe secret <name> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get secret <name> -n <namespace> -o jsonpath="{.data}" \
| jq -r 'to_entries[] | "\(.key)=\(.value | @base64d)"'kubectl --kubeconfig=/path/to/kubeconfig.yaml get svc -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml describe svc <name> -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get events -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get events -n <namespace> \
--field-selector involvedObject.name=<name>kubectl --kubeconfig=/path/to/kubeconfig.yaml exec -it <pod> -n <namespace> -- /bin/bash
# or use /bin/sh if bash is not presentkubectl --kubeconfig=/path/to/kubeconfig.yaml port-forward pod/<pod-name> 8080:80 -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get nskubectl --kubeconfig=/path/to/kubeconfig.yaml apply -f ./deploy/kubectl --kubeconfig=/path/to/kubeconfig.yaml delete -f <file.yaml>kubectl --kubeconfig=/path/to/kubeconfig.yaml apply -f <file.yaml> --dry-run=client -o yamlexport KUBECONFIG=/path/to/kubeconfig.yaml
# then omit --kubeconfig in following commands:
kubectl get pods -n <namespace>KUBECONFIG=/path/to/kubeconfig.yaml kubectl get pods -n <namespace>Port-forwarding is very handy for quickly accessing pods/services locally without exposing them via Service type=LoadBalancer/NodePort/Ingress.
kubectl --kubeconfig=/path/to/kubeconfig.yaml port-forward pod/<pod-name> 8080:80 -n <namespace>
# access locally at http://localhost:8080kubectl --kubeconfig=/path/to/kubeconfig.yaml port-forward svc/<service-name> 8080:80 -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml port-forward pod/<pod-name> 8080:80 8443:443 -n <namespace>Pick a running pod from the deployment (one-liner to get a pod name):
POD=$(kubectl --kubeconfig=/path/to/kubeconfig.yaml get pod -n <namespace> -l app=<appname> -o jsonpath="{.items[0].metadata.name}")
kubectl --kubeconfig=/path/to/kubeconfig.yaml port-forward pod/$POD 8080:80 -n <namespace>Note: this launches in background but you should still capture logs or use a process supervisor for production usage.
kubectl --kubeconfig=/path/to/kubeconfig.yaml port-forward pod/<pod-name> 8080:80 -n <namespace> > /tmp/portforward.log 2>&1 &
echo $! > /tmp/portforward.pid
# to stop:
kill $(cat /tmp/portforward.pid)kubectl --kubeconfig=/path/to/kubeconfig.yaml port-forward pod/<pod-name> 18080:80 -n <namespace>kubectl --kubeconfig=/path/to/kubeconfig.yaml get endpoints <service-name> -n <namespace> -o yaml