kubectl
Manage Kubernetes clusters
TLDR
List information about a resource with more details
Update specified pod with the label unhealthy and the value true
List all resources with different types
Display resource (CPU/Memory/Storage) usage of nodes or pods
Print the address of the master and cluster services
Display an explanation of a specific field
Print the logs for a container in a pod or specified resource
Run command in an existing pod
SYNOPSIS
kubectl [flags] COMMAND [args]
PARAMETERS
-n, --namespace string
Namespace scope for the request
--context string
Kubeconfig context to use
--kubeconfig string
Path to kubeconfig file
-o, --output string
Output format (json|yaml|wide|name|jsonpath|...)
--dry-run string
"none|server|client" to simulate without applying
-v, --v level
Logging verbosity (0-9)
--help
Display help
--as string
Username to impersonate
-f, --filename file
Filename, directory, or URL for config
-R, --recursive
Process directory recursively
-l, --selector string
Selector (label query) to filter
-A, --all-namespaces
All namespaces
DESCRIPTION
Kubectl is the official command-line tool for Kubernetes, enabling users to interact with clusters via the Kubernetes API. It supports deploying applications, inspecting resources, scaling workloads, and troubleshooting.
Key uses include applying YAML manifests (kubectl apply -f file.yaml), listing pods (kubectl get pods), viewing logs (kubectl logs pod-name), port-forwarding (kubectl port-forward), and executing shells in containers (kubectl exec -it pod -- /bin/sh). Kubectl authenticates using kubeconfig files storing clusters, users, and contexts.
Output formats include YAML, JSON, tables; dry-run simulates changes. Global flags control namespace, verbosity, and config. Subcommands like create, delete, describe, edit cover most operations. Essential for developers, operators, and CI/CD in containerized environments.
Requires kubectl binary installed, kubeconfig (~/.kube/config), and cluster access. Supports aliases like k for quick use.
CAVEATS
Requires kubeconfig and cluster access; some flags subcommand-specific; high verbosity floods output; dry-run=client doesn't validate server-side.
COMMON SUBCOMMANDS
apply - Apply config
create - Create resource
delete - Delete resource
describe - Show details
exec - Exec in pod
get - List resources
logs - Pod logs
port-forward - Port forward
CONFIG SOURCES
Kubeconfig from kubectl config; clusters via kubeadm, minikube, kind; auth via tokens, certs, OIDC.
HISTORY
Introduced in Kubernetes v0.1 (2014) by Google; matured with Kubernetes 1.0 (2015). Now CNCF project, versioned with Kubernetes (e.g., v1.28). Widely adopted for container orchestration.


