kubectl flags & options

get

List resources of a given type.

kubectl get pods
kubectl get services -n production
kubectl get nodes -o wide

describe

Show detailed information about a specific resource.

kubectl describe pod my-app-7b4f6c8d-x2k9p
kubectl describe node worker-01

apply -f

Create or update resources from a YAML or JSON file.

kubectl apply -f deployment.yaml
kubectl apply -f ./k8s/

delete

Delete resources by name, file, or label.

kubectl delete pod my-app-7b4f6c8d-x2k9p
kubectl delete -f deployment.yaml

logs

Print the logs from a container in a pod.

kubectl logs my-app-7b4f6c8d-x2k9p
kubectl logs -f my-app-7b4f6c8d-x2k9p
kubectl logs my-app-7b4f6c8d-x2k9p -c sidecar

exec -it

Run a command inside a running container.

kubectl exec -it my-app-7b4f6c8d-x2k9p -- /bin/sh
kubectl exec my-app-7b4f6c8d-x2k9p -- env

-n, --namespace

Target a specific Kubernetes namespace.

kubectl get pods -n kube-system
kubectl logs -n staging my-app-abc123

-o, --output

Set the output format (json, yaml, wide, name, jsonpath).

kubectl get pods -o yaml
kubectl get pods -o jsonpath='{.items[*].metadata.name}'

--context

Use a specific kubeconfig context to target a different cluster.

kubectl --context=production get pods

scale

Change the number of replicas for a deployment.

kubectl scale deployment my-app --replicas=5

rollout

Manage rollouts for deployments.

kubectl rollout status deployment/my-app
kubectl rollout restart deployment/my-app
kubectl rollout undo deployment/my-app