Skip to content

Instantly share code, notes, and snippets.

@gourshete
Last active August 11, 2021 17:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gourshete/708460a86f5fdfbcd309e9cad23ee1f5 to your computer and use it in GitHub Desktop.
Save gourshete/708460a86f5fdfbcd309e9cad23ee1f5 to your computer and use it in GitHub Desktop.
Kubernetes useful commands
### List all pods from all namespaces in current cluster
kubectl get pods --all-namespaces
### Get info about specific pod
kubectl describe pods --namespace pod-name pod-id
### SSH to a pod
kubectl exec -it -n insert_namespace_here -c web insert_pod_name_here -- bash
### Investigate CrashLoopBackOff state by finding previous container logs
kubectl logs -n insert_namespace_here -c web insert_pod_name_here -p
### Open rails console on pod
kubectl exec -it -n insert_namespace_here -c web insert_pod_name_here -- rails c
### Run pending migrations on pod
kubectl exec -it -n insert_namespace_here -c web insert_pod_name_here -- rake db:migrate
Delete Namespace:
kubectl delete namespace insert_namespace_name_here
### Delete all Evicted pods from all namespaces from current cluster
kubectl get pods --all-namespaces -o json | jq '.items[]| select(.status.reason=="Evicted") | "kubectl delete pod \(.metadata.name) -n \(.metadata.namespace)"' | xargs -n 1 bash -c
### Delete pods
kubectl delete pods -n namespace_name pod_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment