kubectl config current-contextPrint the active kubeconfig context name.
Use before running any command to avoid targeting the wrong cluster.
Kubernetes Reference
Use this command reference for day-to-day Kubernetes operations across context/namespace management, pods, deployments, services, config/secrets, autoscaling, and CRDs.
Last updated: 2026-03-10
Practical command snippets by resource type, including context switching, namespaces, pods, deployments, services, secrets, CRDs, and GCP cluster setup workflows.
Get current context, switch clusters, and set default namespace scope safely.
kubectl config current-contextPrint the active kubeconfig context name.
Use before running any command to avoid targeting the wrong cluster.
kubectl config get-contextsList available contexts with cluster/user bindings.
Use to discover configured environments and identify the context name to switch to.
kubectl config use-context <context-name>Switch active context in kubeconfig.
Use when changing from one environment to another (for example dev to prod).
kubectl --context=<context-name> get pods -ARun a one-off command against a specific context without switching globally.
Use when you need a quick check in another cluster while keeping your current default context.
kubectl config set-context --current --namespace=<namespace>Set default namespace for the current context.
Use to reduce repeated -n flags and prevent namespace mistakes.
kubectl config view --minify --output 'jsonpath={..namespace}'Show the namespace currently attached to active context.
Use to verify namespace scope before mutating workloads.
Inspect running containers, logs, and shell access for rapid triage.
kubectl get pods -AList all pods in every namespace.
Use this first to verify pod status cluster-wide.
kubectl describe pod <pod-name> -n <namespace>Show pod events, scheduling details, and container state.
Use when a pod is Pending, CrashLoopBackOff, or restarting.
kubectl logs <pod-name> -n <namespace> --tail=200Fetch the latest pod logs.
Use for quick application error context.
kubectl logs <pod-name> -n <namespace> -c <container-name> --followStream logs for a specific container in a multi-container pod.
Use for real-time incident troubleshooting.
kubectl exec -it <pod-name> -n <namespace> -- shOpen an interactive shell in a running container.
Use to inspect runtime config, files, or DNS/network behavior.
kubectl delete pod <pod-name> -n <namespace>Delete a pod and let its controller recreate it.
Use for stateless restart recovery under a Deployment.
Authenticate with Google Cloud and pull GKE credentials into your local kubeconfig.
gcloud auth loginAuthenticate the gcloud CLI with your Google account.
Use when onboarding a new machine or switching Google identities.
gcloud auth application-default loginCreate local Application Default Credentials for SDK-based tooling.
Use when tools or scripts require ADC instead of gcloud user credentials.
gcloud auth listList authenticated Google accounts and show the active account.
Use to confirm you are authenticated as the intended identity.
gcloud config set project <project-id>Set the active Google Cloud project in local gcloud config.
Use before listing clusters or fetching credentials for a specific project.
gcloud container clusters list --project <project-id>List GKE clusters for the selected project.
Use to discover cluster names and region/zone values.
gcloud container clusters get-credentials <cluster-name> --region <region> --project <project-id>Fetch credentials for a regional GKE cluster and merge into kubeconfig.
Use when connecting to regional clusters (recommended default for production).
gcloud container clusters get-credentials <cluster-name> --zone <zone> --project <project-id>Fetch credentials for a zonal GKE cluster and merge into kubeconfig.
Use when the target GKE cluster is zonal instead of regional.
kubectl config current-contextVerify the active kubectl context after pulling GKE credentials.
Use immediately after get-credentials to confirm the selected cluster context.
Operate rollout lifecycle for stateless workloads.
kubectl get deployments -AList deployments and replica readiness across namespaces.
Use for rollout health and replica drift checks.
kubectl rollout status deployment/<name> -n <namespace>Watch rollout progress until complete.
Use during release verification.
kubectl rollout history deployment/<name> -n <namespace>View deployment revision history.
Use before rollback decisions.
kubectl rollout undo deployment/<name> -n <namespace>Rollback deployment to previous revision.
Use when current rollout introduces regressions.
kubectl scale deployment/<name> --replicas=3 -n <namespace>Set desired replica count manually.
Use for temporary capacity adjustments.
kubectl set image deployment/<name> <container>=<image>:<tag> -n <namespace>Patch image tag for a deployment container.
Use for hotfix rollouts or controlled image bumps.
Validate network routing from cluster service to public entrypoint.
kubectl get svc -AList all Service resources.
Use to confirm service exposure type and cluster IPs.
kubectl describe svc <service-name> -n <namespace>Inspect service ports, selector, and endpoints.
Use when traffic is not reaching backend pods.
kubectl get endpoints <service-name> -n <namespace>Check endpoint addresses selected by the service.
Use to verify selector-to-pod binding.
kubectl get ingress -AList ingress resources and exposed hosts.
Use for external routing diagnostics.
kubectl describe ingress <ingress-name> -n <namespace>Show ingress rules, TLS config, and backend mappings.
Use when host/path routes fail unexpectedly.
Inspect and validate runtime configuration and secret payloads.
kubectl get configmap -AList ConfigMaps across namespaces.
Use to find environment-specific config references.
kubectl get configmap <name> -n <namespace> -o yamlView ConfigMap content in YAML form.
Use when debugging missing or malformed config values.
kubectl get secret -AList Secret resources across namespaces.
Use to verify secret presence before pod startup.
kubectl get secret <name> -n <namespace> -o jsonFetch raw secret JSON with base64-encoded data fields.
Use to inspect expected secret keys.
kubectl get secret <name> -n <namespace> -o jsonpath='{.data.<key>}' | base64 --decodeDecode one secret key value for verification.
Use when checking credential or config mismatch issues.
Track batch execution and scheduled workloads.
kubectl get jobs -AList all Job resources.
Use to monitor one-off batch runs.
kubectl describe job <job-name> -n <namespace>Inspect job execution state and pod references.
Use for failed job diagnostics.
kubectl get cronjob -AList all CronJob schedules.
Use for scheduled workload inventory.
kubectl describe cronjob <cronjob-name> -n <namespace>Inspect schedule, concurrency policy, and job history.
Use when scheduled jobs run late or overlap.
kubectl create job --from=cronjob/<cronjob-name> <manual-job-name> -n <namespace>Trigger an immediate ad-hoc run from a CronJob template.
Use for manual execution during incident response.
Operate stateful workloads, node agents, and autoscaling behavior.
kubectl get statefulset -AList StatefulSets and ready replicas.
Use for persistent workload status checks.
kubectl rollout status statefulset/<name> -n <namespace>Watch StatefulSet rollout progression.
Use after config or image updates.
kubectl get daemonset -AList DaemonSets running on cluster nodes.
Use to verify node-level agent coverage.
kubectl describe daemonset <name> -n <namespace>Inspect desired/current node scheduling and events.
Use when node-level components are missing on some nodes.
kubectl get hpa -AList horizontal pod autoscalers and target metrics.
Use to validate autoscaling rules and current behavior.
Discover CRDs and inspect controller-managed custom resource instances.
kubectl get crdList all CustomResourceDefinition objects.
Use to inventory installed CRDs in the cluster.
kubectl api-resources --api-group=<group-name>List available resources for a specific API group.
Use to identify CRD plural names and short names.
kubectl get <crd-plural> -AList all custom resources for a CRD kind.
Use for controller state overview.
kubectl describe <crd-plural> <resource-name> -n <namespace>Inspect one custom resource and related events.
Use when CRD reconciliation is failing.
kubectl get <crd-plural> <resource-name> -n <namespace> -o yamlView full CRD object spec and status.
Use for debugging status conditions and observed generation.
kubectl explain <crd-plural>.specShow field documentation for CRD spec schema.
Use while authoring or reviewing CR manifests.
kubectl get certificates -AExample: list cert-manager Certificate resources.
Use when TLS issuance is managed by cert-manager.
kubectl get rollouts -AExample: list Argo Rollouts resources.
Use when progressive delivery is managed by Argo Rollouts.