kubectl
npx machina-cli add skill typhoonzero/awesome-acp-skills/kubectl --openclawKubectl CLI
This skill covers the usage of kubectl for managing Kubernetes clusters.
Overview
kubectl is the standard command-line tool for communicating with a Kubernetes cluster's control plane.
Common Operations
Viewing Resources
List resources
# List all pods in the current namespace
kubectl get pods
# List all services in a specific namespace
kubectl get services -n <namespace>
# List all deployments in all namespaces
kubectl get deployments --all-namespaces
# List nodes
kubectl get nodes
Get detailed information
# Get details of a specific pod in YAML format
kubectl get pod <pod-name> -o yaml
# Get details in JSON format
kubectl get pod <pod-name> -o json
# Describe a resource (shows events and status)
kubectl describe pod <pod-name>
kubectl describe node <node-name>
Creating and Updating Resources
Apply configuration The most common way to manage resources is using YAML files.
# Create or update resources from a YAML file
kubectl apply -f <filename.yaml>
# Create or update resources from a directory of YAML files
kubectl apply -f <directory>/
# Apply from a remote URL
kubectl apply -f https://example.com/manifest.yaml
Imperative commands
# Create a namespace
kubectl create namespace <namespace-name>
# Create a configmap
kubectl create configmap <name> --from-literal=key=value
# Create a secret
kubectl create secret generic <name> --from-literal=password=123
Deleting Resources
# Delete resources defined in a YAML file
kubectl delete -f <filename.yaml>
# Delete a specific resource by name
kubectl delete pod <pod-name>
kubectl delete service <service-name>
# Delete all resources of a type in a namespace
kubectl delete pods --all -n <namespace>
Troubleshooting
# view logs of a pod
kubectl logs <pod-name>
# View logs of a specific container in a pod
kubectl logs <pod-name> -c <container-name>
# Stream logs
kubectl logs -f <pod-name>
# Execute a command in a container
kubectl exec -it <pod-name> -- /bin/bash
Context and Configuration
# View current config
kubectl config view
# Switch context (cluster)
kubectl config use-context <context-name>
# Set default namespace for current context
kubectl config set-context --current --namespace=<namespace>
Source
git clone https://github.com/typhoonzero/awesome-acp-skills/blob/master/kubectl/SKILL.mdView on GitHub Overview
kubectl is the standard command-line tool for communicating with a Kubernetes cluster's control plane. It lets you list resources, view details, apply YAML configurations, and delete resources across namespaces.
How This Skill Works
kubectl communicates with the Kubernetes API server to query and modify cluster state. It supports declarative config via kubectl apply -f and imperative actions (create/delete) and can format output in YAML, JSON, or human-friendly forms. Contexts and namespaces help you target the right cluster and scope.
When to Use It
- Viewing and listing resources like pods, services, deployments, and nodes
- Applying YAML manifests to create or update resources
- Deleting resources or cleaning up a namespace
- Troubleshooting with describe, logs, and exec
- Managing contexts and namespaces for multi-cluster workflows
Quick Start
- Step 1: Prepare a YAML manifest or choose a manifest URL
- Step 2: Apply it with kubectl apply -f <filename.yaml> (or -f <directory>/ or -f <URL>)
- Step 3: Verify deployment status with kubectl get <resource> and kubectl describe pod <pod-name>
Best Practices
- Prefer declarative config with kubectl apply -f over ad-hoc imperatives
- Keep manifests version-controlled and namespace-scoped
- Use -n/--namespace and contexts to avoid cross-namespace mistakes
- Validate manifests before applying and consider dry-run options
- Regularly verify state with kubectl get and describe; use logs/exec for troubleshooting
Example Use Cases
- List all pods in the current namespace: kubectl get pods
- List all services in a specific namespace: kubectl get services -n <namespace>
- List deployments in all namespaces: kubectl get deployments --all-namespaces
- Get details of a pod in YAML: kubectl get pod <pod-name> -o yaml
- Describe a pod: kubectl describe pod <pod-name>