| name | kubectl-skill |
| description | Execute and manage Kubernetes clusters via kubectl commands. Query resources, deploy applications, debug containers, manage configurations, and monitor cluster health. Use when working with Kubernetes clusters, containers, deployments, or pod diagnostics. |
| license | MIT |
| metadata | {"author":"Dennis de Vaal <d.devaal@gmail.com>","version":"1.0.0","keywords":"kubernetes,k8s,container,docker,deployment,pods,cluster"} |
| compatibility | Requires kubectl binary (v1.20+) and active kubeconfig connection to a Kubernetes cluster. Works on macOS, Linux, and Windows (WSL). |
kubectl Skill
Execute Kubernetes cluster management operations using the kubectl command-line tool.
Overview
This skill enables agents to:
- Query Resources โ List and get details about pods, deployments, services, nodes, etc.
- Deploy & Update โ Create, apply, patch, and update Kubernetes resources
- Debug & Troubleshoot โ View logs, execute commands in containers, inspect events
- Manage Configuration โ Update kubeconfig, switch contexts, manage namespaces
- Monitor Health โ Check resource usage, rollout status, events, and pod conditions
- Perform Operations โ Scale deployments, drain nodes, manage taints and labels
Prerequisites
- kubectl binary installed and accessible on PATH (v1.20+)
- kubeconfig file configured with cluster credentials (default:
~/.kube/config)
- Active connection to a Kubernetes cluster
Quick Setup
Install kubectl
macOS:
brew install kubernetes-cli
Linux:
apt-get install -y kubectl
yum install -y kubectl
Verify:
kubectl version --client
kubectl cluster-info
Essential Commands
Query Resources
kubectl get pods
kubectl get pods -A
kubectl get pods -o wide
kubectl get nodes
kubectl describe pod POD_NAME
View Logs
kubectl logs POD_NAME
kubectl logs -f POD_NAME
kubectl logs POD_NAME -c CONTAINER
kubectl logs POD_NAME --previous
Execute Commands
kubectl exec -it POD_NAME -- /bin/bash
kubectl exec POD_NAME -- COMMAND
Deploy Applications
kubectl apply -f deployment.yaml
kubectl create -f deployment.yaml
kubectl apply -f deployment.yaml --dry-run=client
Update Applications
kubectl set image deployment/APP IMAGE=IMAGE:TAG
kubectl scale deployment/APP --replicas=3
kubectl rollout status deployment/APP
kubectl rollout undo deployment/APP
Manage Configuration
kubectl config view
kubectl config get-contexts
kubectl config use-context CONTEXT
Common Patterns
Debugging a Pod
kubectl describe pod POD_NAME
kubectl logs POD_NAME
kubectl logs POD_NAME --previous
kubectl exec -it POD_NAME -- /bin/bash
kubectl get events --sort-by='.lastTimestamp'
Deploying a New Version
kubectl set image deployment/MY_APP my-app=my-app:v2
kubectl rollout status deployment/MY_APP -w
kubectl get pods -l app=my-app
kubectl rollout undo deployment/MY_APP
Preparing Node for Maintenance
kubectl drain NODE_NAME --ignore-daemonsets
kubectl uncordon NODE_NAME
Output Formats
The --output (-o) flag supports multiple formats:
table โ Default tabular format
wide โ Extended table with additional columns
json โ JSON format (useful with jq)
yaml โ YAML format
jsonpath โ JSONPath expressions
custom-columns โ Define custom output columns
name โ Only resource names
Examples:
kubectl get pods -o json | jq '.items[0].metadata.name'
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
kubectl get pods -o custom-columns=NAME:.metadata.name,STATUS:.status.phase
Global Flags (Available to All Commands)
-n, --namespace=<ns>
-A, --all-namespaces
--context=<context>
-o, --output=<format>
--dry-run=<mode>
-l, --selector=<labels>
--field-selector=<selector>
-v, --v=<int>
Dry-Run Modes
--dry-run=client โ Fast client-side validation (test commands safely)
--dry-run=server โ Server-side validation (more accurate)
--dry-run=none โ Execute for real (default)
Always test with --dry-run=client first:
kubectl apply -f manifest.yaml --dry-run=client
Advanced Topics
For detailed reference material, command-by-command documentation, troubleshooting guides, and advanced workflows, see:
Helpful Tips
-
Use label selectors for bulk operations:
kubectl delete pods -l app=myapp
kubectl get pods -l env=prod,tier=backend
-
Watch resources in real-time:
kubectl get pods -w
-
Use -A flag for all namespaces:
kubectl get pods -A
-
Save outputs for later comparison:
kubectl get deployment my-app -o yaml > deployment-backup.yaml
-
Check before you delete:
kubectl delete pod POD_NAME --dry-run=client
Getting Help
kubectl help
kubectl COMMAND --help
kubectl explain pods
kubectl explain pods.spec
Environment Variables
KUBECONFIG โ Path to kubeconfig file (can include multiple paths separated by :)
KUBECTL_CONTEXT โ Override default context
Resources
Version: 1.0.0
License: MIT
Compatible with: kubectl v1.20+, Kubernetes v1.20+