- Use kubectx for switching between contexts / namespaces
- For all commands should specify
--namespace <NAMESPACE>or--all-namespacesor kubectl will use default namespace kubectl auth can-i create deployments --namespace <NAMESPACE>--> Check deployment permission- General grammar:
kubectl <verb> <noun> [options] - https://www.digitalocean.com/community/tutorials/how-to-inspect-kubernetes-networking
kubectl get pods --namespace=<NAMESPACE> -o wide | grep <SERVICE>--> Get all pods running a servicekubectl exec -it <POD> --namespace <NAMESPACE> -- /bin/bash--> Open shell inside some pod. Can also do other commands- Port forwarding to access service from localhost (Helm chart message upon successful deployment)
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace <NAMESPACE> -l "app.kubernetes.io/name=wm-server,app.kubernetes.io/instance=wm-server" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace <NAMESPACE> $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace <NAMESPACE> port-forward $POD_NAME 8080:$CONTAINER_PORT
kubectl get pod $(kubectl get pods --namespace api | grep <SERVICE> | awk '{print $1}') --namespace api--> Check pod status after deploying service- Prepare some swiss army debugging container. Examples: netshoot , cdebug
- Official cheatsheet
- Debug running containers
- Debugging
kubectl exec -it <pod_name> [-c container_name] -- /bin/bash--> Run /bin/bash in chosen pod / containerkubectl attach -it <pod_name> [-c container_name]--> Attach to the chosen pod / container to stream outputkubectl run -it busybox --image=busybox--> Spin up a new busybox debug container- kubectl debug
- others techniques