Kubectl
Kubectl is the standard command-line tool for interacting with Kubernetes clusters across all major cloud providers (AKS, EKS, GKE) and on-premises environments. It enables you to deploy, manage, and troubleshoot Kubernetes resources efficiently.
Installation
Linux/WSL
NixOS
Add to your configuration.nix
:
Then run:
Connecting to Managed Clusters
AKS:
az aks get-credentials --resource-group <rg> --name <cluster>
EKS:
aws eks update-kubeconfig --region <region> --name <cluster>
GKE:
gcloud container clusters get-credentials <cluster> --region <region>
Common Usage Examples
Create a deployment:
View deployment status:
Scale a deployment:
Update deployment image:
Create a service:
View pod logs:
Create a secret:
Create a ConfigMap:
Real-Life DevOps Scenarios
Use
kubectl
in CI/CD pipelines (GitHub Actions, Azure Pipelines, GitLab CI) for automated deployments and rollbacks.Integrate with GitOps tools (ArgoCD, Flux) for declarative cluster management.
Use LLMs (Copilot, Claude) to generate manifests and troubleshoot errors.
Automate cluster context switching for multi-cloud workflows.
Best Practices (2025)
Always use the latest stable version of kubectl
Use
kubectl --context
to manage multiple clustersValidate YAML with
kubectl apply --dry-run=client -f <file>
Use
kubectl explain <resource>
for quick documentationPrefer declarative (
apply
) over imperative (create
,edit
) workflowsUse RBAC and namespaces for security and isolation
Common Pitfalls
Not matching kubectl version to cluster version (can cause errors)
Forgetting to set the correct context before running commands
Applying unvalidated YAML (syntax or schema errors)
References
Last updated