Kubectl ist Ihr bester Freund bei der Arbeit mit Kubernetes. Hier sind 20 Befehle für die tägliche Arbeit.
Kontext und Namespace¶
kubectl config get-contexts kubectl config use-context production kubectl config set-context –current –namespace=app
Ressourcen-Übersicht¶
kubectl get pods -A kubectl get pods -o wide kubectl get pods –sort-by=.status.startTime
Logs¶
kubectl logs -f my-pod kubectl logs –previous my-pod kubectl logs -l app=frontend –all-containers
Exec und Port Forward¶
kubectl exec -it my-pod – /bin/sh kubectl port-forward svc/my-app 8080:80
Ressourcenverbrauch¶
kubectl top pods –sort-by=memory kubectl top nodes
Skalierung und Rollout¶
kubectl scale deployment my-app –replicas=5 kubectl rollout undo deployment/my-app kubectl rollout status deployment/my-app
Apply und Delete¶
kubectl apply -f manifest.yaml kubectl delete pod my-pod –grace-period=0 –force
JSONPath und Dry Run¶
kubectl get pods -o jsonpath=’{.items[*].metadata.name}’ kubectl create deployment nginx –image=nginx –dry-run=client -o yaml
Labels und Selektoren¶
kubectl label pods my-pod env=production kubectl get pods -l env=production
Debug und Events¶
kubectl debug my-pod -it –image=busybox kubectl get events –sort-by=.lastTimestamp kubectl describe pod my-pod
ConfigMap und Secret¶
kubectl create configmap my-config –from-file=config.yaml kubectl create secret generic db-pass –from-literal=password=s3cret kubectl get secret db-pass -o jsonpath=’{.data.password}’ | base64 -d
Aliase¶
alias k=kubectl alias kgp=”kubectl get pods” alias kl=”kubectl logs -f”
Tipp¶
Installieren Sie kubectx, kubens und richten Sie die zsh-Vervollständigung ein — ein Game Changer.