Kubernetes and kubectl mastery for deployments, services, pods, debugging, and cluster management. Use when user asks to "deploy to k8s", "create deployment", "debug pod", "kubectl commands", "scale service", "check pod logs", "create ingress", or any Kubernetes tasks.
Essential kubectl commands and Kubernetes patterns.
# View contexts
kubectl config get-contexts
kubectl config current-context
# Switch context
kubectl config use-context production
# Set default namespace
kubectl config set-context --current --namespace=my-app
# Use namespace in command
kubectl get pods -n kube-system
kubectl get pods --all-namespaces # or -A
# List pods
kubectl get pods
kubectl get pods -o wide # More details
kubectl get pods -w # Watch mode
kubectl get pods --show-labels
kubectl get pods -l app=web # By label
# Pod details
kubectl describe pod my-pod
kubectl get pod my-pod -o yaml
# Logs
kubectl logs my-pod
kubectl logs my-pod -f # Follow
kubectl logs my-pod --tail=100
kubectl logs my-pod -c my-container # Specific container
kubectl logs my-pod --previous # Previous crash
# Exec into pod
kubectl exec -it my-pod -- /bin/sh
kubectl exec -it my-pod -c my-container -- bash
# Port forward
kubectl port-forward my-pod 8080:80
kubectl port-forward svc/my-service 8080:80
# Copy files
kubectl cp my-pod:/app/file.txt ./file.txt
kubectl cp ./file.txt my-pod:/app/
# Delete
kubectl delete pod my-pod
kubectl delete pod my-pod --grace-period=0 --force
# Create deployment
kubectl create deployment web --image=nginx:latest --replicas=3
# List
kubectl get deployments
kubectl get deploy
# Scale
kubectl scale deployment web --replicas=5
# Update image
kubectl set image deployment/web nginx=nginx:1.25
# Rollout status
kubectl rollout status deployment/web
# Rollback
kubectl rollout undo deployment/web
kubectl rollout undo deployment/web --to-revision=2
# History
kubectl rollout history deployment/web
# Restart (rolling)
kubectl rollout restart deployment/web
apiVersion: apps/v1