← Back to tools

kubectl

Official Kubernetes command-line tool for cluster management

Cloud & Services System & Monitoring linuxmacoswindows Go Apache-2.0

Description

kubectl is the official command-line tool for interacting with Kubernetes clusters. It allows you to deploy applications, inspect and manage cluster resources, view logs, and perform all operations against the Kubernetes API. It is the essential tool for anyone working with Kubernetes.

Install

homebrewbrew install kubectl

AI Summary

Official Kubernetes CLI for deploying applications, managing cluster resources, viewing logs, and performing all operations against the Kubernetes API.

Capabilities

  • + Create, update, and delete Kubernetes resources
  • + View pod logs and exec into running containers
  • + Apply manifests declaratively from YAML/JSON files
  • + Port-forward to services and pods for local access
  • + Manage contexts and switch between clusters and namespaces
  • + Scale deployments and manage rollouts
  • + Output resource details in JSON, YAML, or custom formats

Use When

  • Managing Kubernetes clusters and workloads from the terminal
  • Deploying applications defined in YAML manifests
  • Debugging pods by viewing logs or exec-ing into containers
  • Scripting Kubernetes operations in CI/CD pipelines
  • Inspecting cluster state and resource details

Avoid When

  • x Not using Kubernetes
  • x Want a visual/interactive experience for cluster management (use K9s or Lens)
  • x Managing Kubernetes packages with many resources (use Helm)

Usage Patterns

Apply a manifest file

kubectl apply -f deployment.yaml

Creates or updates resources defined in the YAML file

View pod logs

kubectl logs -f deployment/my-app

Streams logs from a deployment's pods

Exec into a running pod

kubectl exec -it my-pod -- /bin/sh

Opens an interactive shell inside the running container

Get resources with custom output

kubectl get pods -o wide --all-namespaces

Lists all pods across namespaces with extended info

Input / Output

stdin: Accepts manifests via stdin (e.g., kubectl apply -f -)
stdout: Resource listings, logs, and command output
stderr: Error messages and warnings
Exit codes:
0 Success
1 General error or resource not found

Typical Pipelines

kubectl get pods -o json | jq '.items[].metadata.name' to extract pod names
kubectl get secret my-secret -o jsonpath='{.data.password}' | base64 -d to decode a secret
helm template release chart/ | kubectl apply -f - to apply Helm-rendered manifests

Related Tools

View AGENTS.md for kubectl