| name | kubernetes |
| description | 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. |
Kubernetes
Essential kubectl commands and Kubernetes patterns.
Context & Namespace
kubectl config get-contexts
kubectl config current-context
kubectl config use-context production
kubectl config set-context --current --namespace=my-app
kubectl get pods -n kube-system
kubectl get pods --all-namespaces
Pods
kubectl get pods
kubectl get pods -o wide
kubectl get pods -w
kubectl get pods --show-labels
kubectl get pods -l app=web
kubectl describe pod my-pod
kubectl get pod my-pod -o yaml
kubectl logs my-pod
kubectl logs my-pod -f
kubectl logs my-pod --tail=100
kubectl logs my-pod -c my-container
kubectl logs my-pod --previous
kubectl exec -it my-pod -- /bin/sh
kubectl exec -it my-pod -c my-container -- bash
kubectl port-forward my-pod 8080:80
kubectl port-forward svc/my-service 8080:80
kubectl cp my-pod:/app/file.txt ./file.txt
kubectl cp ./file.txt my-pod:/app/
kubectl delete pod my-pod
kubectl delete pod my-pod --grace-period=0 --force
Deployments
kubectl create deployment web --image=nginx:latest --replicas=3
kubectl get deployments
kubectl get deploy
kubectl scale deployment web --replicas=5
kubectl set image deployment/web nginx=nginx:1.25
kubectl rollout status deployment/web
kubectl rollout undo deployment/web
kubectl rollout undo deployment/web --to-revision=2
kubectl rollout history deployment/web
kubectl rollout restart deployment/web
Deployment YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.25
ports:
- containerPort: 80
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 256Mi
livenessProbe:
httpGet:
path: /health
port: 80
initialDelaySeconds: 10
periodSeconds: 30
readinessProbe:
httpGet:
path: /ready
port: 80
initialDelaySeconds: 5
periodSeconds: 10
env:
- name: NODE_ENV
value: "production"
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-secret
key: password
Services
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: web-public
spec:
type: LoadBalancer
selector:
app: web
ports:
- port: 80
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: web-nodeport
spec:
type: NodePort
selector:
app: web
ports:
- port: 80
targetPort: 8080
nodePort: 30080
kubectl expose deployment web --port=80 --target-port=8080
kubectl expose deployment web --type=LoadBalancer --port=80
kubectl get svc
kubectl describe svc web
ConfigMaps & Secrets
kubectl create configmap app-config --from-literal=key=value
kubectl create configmap app-config --from-file=config.yaml
kubectl create secret generic db-creds \
--from-literal=username=admin \
--from-literal=password=secret123
kubectl get configmap app-config -o yaml
kubectl get secret db-creds -o jsonpath='{.data.password}' | base64 -d
Apply & Delete
kubectl apply -f deployment.yaml
kubectl apply -f ./k8s/
kubectl apply -f https://example.com/manifest.yaml
kubectl delete -f deployment.yaml
kubectl delete deployment web
kubectl delete all -l app=web
kubectl apply -f deployment.yaml --dry-run=client
kubectl apply -f deployment.yaml --dry-run=server
Debugging Quick Reference
kubectl describe pod my-pod
kubectl get events --sort-by='.lastTimestamp'
kubectl logs my-pod --previous
kubectl get endpoints my-service
kubectl run debug --rm -it --image=busybox -- wget -qO- http://my-service
kubectl top pods
kubectl top nodes
kubectl describe node <node-name>
Reference
For debugging patterns: references/debugging.md
For YAML templates: references/manifests.md