← Back to CLIs
Melvynx

kubectl

Kubernetes CLI - manage pods, deployments, services, config contexts. Use when user mentions 'kubectl', 'kubernetes', 'k8s', 'pods', or wants to manage Kubernetes clusters.

Install

$ npx api2cli install kubectl

Details

Skill type: Official CLI
Auth type: bearer
Version: 1.0.0
Author: Melvynx
Views: 0

README

kubectl

Setup

brew install kubectl

Verify installation:

kubectl version --client

Use -o json or -o yaml for machine-readable output.

Authentication

kubectl config use-context <context-name>

Resources

Viewing Resources

CommandDescription
kubectl get podsList all pods in current namespace
kubectl get pods -AList pods across all namespaces
kubectl get pods -o wideList pods with additional details
kubectl get servicesList all services
kubectl get deploymentsList all deployments
kubectl get nodesList cluster nodes
kubectl get namespacesList all namespaces
kubectl get allList all resources in current namespace
kubectl get ingressList all ingress resources
kubectl get configmapsList all config maps
kubectl get secretsList all secrets

Describing Resources

CommandDescription
kubectl describe pod <name>Show detailed pod info
kubectl describe service <name>Show detailed service info
kubectl describe deployment <name>Show detailed deployment info
kubectl describe node <name>Show detailed node info

Creating and Applying

CommandDescription
kubectl apply -f <file.yaml>Apply a configuration from file
kubectl apply -f <directory>/Apply all configs from a directory
kubectl apply -k <directory>/Apply a kustomize configuration
kubectl create namespace <name>Create a namespace
kubectl create secret generic <name> --from-literal=key=valueCreate a secret

Deleting Resources

CommandDescription
kubectl delete pod <name>Delete a pod
kubectl delete -f <file.yaml>Delete resources defined in file
kubectl delete deployment <name>Delete a deployment
kubectl delete namespace <name>Delete a namespace and all its resources

Logs and Debugging

CommandDescription
kubectl logs <pod>View pod logs
kubectl logs -f <pod>Follow pod logs
kubectl logs <pod> -c <container>View logs for a specific container
kubectl logs --tail=100 <pod>View last 100 lines of logs
kubectl exec -it <pod> -- bashOpen a shell in a pod
kubectl exec <pod> -- <command>Run a command in a pod
kubectl port-forward <pod> 8080:80Forward local port to pod
kubectl port-forward svc/<service> 8080:80Forward local port to service

Scaling and Rollouts

CommandDescription
kubectl scale deployment <name> --replicas=3Scale a deployment
kubectl rollout status deployment <name>Check rollout status
kubectl rollout history deployment <name>View rollout history
kubectl rollout undo deployment <name>Rollback to previous revision
kubectl rollout restart deployment <name>Restart a deployment

Context and Config

CommandDescription
kubectl config get-contextsList all contexts
kubectl config current-contextShow current context
kubectl config use-context <name>Switch to a context
kubectl config set-context --current --namespace=<ns>Set default namespace for current context

Global Flags

FlagDescription
-n <namespace>Specify namespace
-o jsonOutput as JSON
-o yamlOutput as YAML
-o wideOutput with additional info
--dry-run=clientPreview without applying
-l <key>=<value>Filter by label
--all-namespaces or -AAcross all namespaces
Sponsors