| name | kubernetes |
| description | Manage Kubernetes clusters via kubectl |
| metadata | {"openclaw":{"always":false,"emoji":"☸️"}} |
Kubernetes
Manage Kubernetes clusters via kubectl.
Setup
-
Check if installed:
command -v kubectl && kubectl version --client
-
Install:
brew install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl && sudo mv kubectl /usr/local/bin/
sudo apt update && sudo apt install -y kubectl
Basics
kubectl get pods -A
kubectl get pods -n <ns> -o wide
kubectl describe pod <pod> -n <ns>
kubectl logs <pod> -n <ns> --tail=100
kubectl logs <pod> -n <ns> -c <container>
kubectl exec -it <pod> -n <ns> -- sh
kubectl get deployments -n <ns>
kubectl describe deployment <name> -n <ns>
kubectl scale deployment <name> --replicas=3 -n <ns>
kubectl rollout status deployment <name> -n <ns>
kubectl rollout restart deployment <name> -n <ns>
kubectl rollout undo deployment <name> -n <ns>
kubectl get svc -n <ns>
kubectl describe svc <name> -n <ns>
kubectl port-forward svc/<name> 8080:80 -n <ns>
kubectl get configmap -n <ns>
kubectl get secret -n <ns>
kubectl get secret <name> -n <ns> -o jsonpath='{.data}'
Diagnostics
kubectl get events -n <ns> --sort-by='.lastTimestamp'
kubectl top pods -n <ns>
kubectl top nodes
kubectl get nodes -o wide
kubectl describe node <name>
kubectl cordon <node>
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
Apply & Delete
kubectl apply -f <file.yaml>
kubectl apply -f <directory>/
kubectl apply -f <file.yaml> --dry-run=client
kubectl delete -f <file.yaml>
kubectl delete pod <pod> -n <ns>
Contexts
kubectl config get-contexts
kubectl config use-context <name>
kubectl config current-context
Tips
- Use
-o yaml or -o json for detailed output
- Use
--watch to monitor changes in real time
- Use
-l app=myapp to filter by labels
- Always specify
-n <namespace> to avoid surprises