VISI

Essential kubectl commands

Cluster and nodes:

kubectl cluster-info
kubectl get nodes
kubectl get nodes -o wide
kubectl describe node <name>
kubectl top nodes

Pods:

kubectl get pods -A                        # All namespaces
kubectl get pods -n <namespace>
kubectl describe pod <pod-name>
kubectl logs <pod-name>
kubectl exec -it <pod-name> -- /bin/bash
kubectl delete pod <pod-name>
kubectl top pods

Deployments and scaling:

kubectl get deployments
kubectl scale deployment <name> --replicas=3
kubectl scale deployment <name> --replicas=0    # Scale to zero
kubectl rollout status deployment/<name>
kubectl rollout restart deployment/<name>
kubectl rollout undo deployment/<name>           # Rollback

Troubleshooting:

kubectl get events --sort-by='.lastTimestamp'
kubectl describe pod <pod-name>              # Look at Events section
kubectl logs <pod> --previous               # Logs from crashed container
kubectl apply -f manifest.yaml
kubectl delete -f manifest.yaml

Quiz

A few quick questions based on this unit. Mark it complete when you are done.

Question 1 / 3

What is kubectl delete?