
8 min read
When working with Kubernetes, mastering the essential kubernetes commands for developers can dramatically simplify your workflow, troubleshooting, and deployment processes. Whether you’re debugging a stuck Pod, rolling out a new microservice, or quickly patching a secret, these commands provide the power you need right at your fingertips.
In this blog, you will learn how to use the most essential kubernetes commands for developers, with step-by-step examples, tips for managing configurations, YAML samples for everyday resource management, and troubleshooting tricks that save hours of guesswork.
By the end of this blog, you will learn:
- How to list, describe, and debug core Kubernetes resources (Pods, Deployments, Services)
- The right way to deploy, update, and rollback applications
- Tricks for real-time log inspection and Pod access
- Secure handling of ConfigMaps and Secrets on the command line
- How to monitor cluster health and resource usage
- Common pitfalls and best practices for effortless Kubernetes development
Let’s dive right into the must-have commands that every cloud-native developer should use.
Why Developers Need Essential Kubernetes Commands
Kubernetes isn’t just for platform engineers or SREs. As a developer, having a toolkit of essential kubernetes commands means you can investigate, deploy, and validate your apps without waiting on Ops.
1. Getting Around: Inspecting the Cluster
Before you touch a line of code, get familiar with your cluster state. This is your developer map to Kubernetes.
List all namespaces:
kubectl get namespaces
List all resources (Pods, Deployments, SVCS) in a namespace:
kubectl get all -n my-namespace
Get all nodes and their status:
kubectl get nodes
Describe specific node for troubleshooting:
kubectl describe node <node-name>
2. The Core: Pods and Deployments
Viewing Pods and Their Details
List all Pods in the default namespace:
kubectl get pods
See all Pods in a custom namespace:
kubectl get pods -n staging
Describe a Pod for full status and events:
kubectl describe pod <pod-name>
-n). Many people look for Pods in the wrong namespace and get tripped up.Troubleshooting CrashLoopBackOff and Pending Pods
Show real-time events for a Pod:
kubectl get events --sort-by='.metadata.creationTimestamp'
Viewing and Rolling Out Deployments
List all Deployments:
kubectl get deployments
See deployment details:
kubectl describe deployment <deployment-name>
Scale a deployment (e.g., from 2 to 5 replicas):
kubectl scale deployment <deployment-name> --replicas=5
3. Applying YAMLs: The Developer’s Launchpad
YAML manifests are ground zero for Kubernetes changes. Apply wisely.
Apply a manifest:
kubectl apply -f my-deployment.yaml
Delete resources with a manifest:
kubectl delete -f my-deployment.yaml
Get resource templates:
kubectl create deployment nginx --image=nginx --dry-run=client -o yaml > nginx-deployment.yaml
--dry-run=client -o yaml to scaffold any resource config before applying.4. Real-Time Development: exec, Logs, and Port Forwarding
Accessing Pod Shell for Debugging
Open a shell in a running Pod:
kubectl exec -it <pod-name> -- /bin/sh
View pod logs (for troubleshooting):
kubectl logs <pod-name>
Tail logs for a specific container:
kubectl logs <pod-name> -c <container-name> -f
-c flag to specify the right container.Port Forward a Pod or Service to Your Local Machine
Forward Pod port to local port 8080 (handy for testing microservices):
kubectl port-forward pod/<pod-name> 8080:80
Forward a Service:
kubectl port-forward svc/<service-name> 8080:80
5. Essential Kubernetes Commands for Developers: ConfigMaps and Secrets
Your apps need config data, and often, credentials or API tokens. Kubernetes manages these with ConfigMaps and Secrets. Managing them safely is crucial.
Creating a ConfigMap from a File
Create ConfigMap from a properties file:
kubectl create configmap my-config --from-file=app.properties
Display ConfigMap Contents
Show ConfigMap as YAML:
kubectl get configmap my-config -o yaml
Creating and Reading Secrets
Create a Secret from literal key-value pairs:
kubectl create secret generic my-secret --from-literal=db_user=demo --from-literal=db_pass=UrStr0ngPass!
Get Secret value (Base64-encoded):
kubectl get secret my-secret -o yaml
Decode a Secret value:
kubectl get secret my-secret -o jsonpath="{.data.db_pass}" | base64 --decode
6. Application Updates: Rolling, Pausing, and Rolling Back
Being able to roll out changes – and recover from mistakes – is vital. These essential kubernetes commands for developers enable zero-downtime updates and fast rollbacks.
Rolling Out a New Version
Update Deployment with a new image:
kubectl set image deployment/myapp myapp-container=repo/myapp:v2
Monitor Deployment Rollout
Watch rollout status to ensure new Pods are up:
kubectl rollout status deployment/myapp
Pause and Resume Rollouts
Pause an in-progress rollout:
kubectl rollout pause deployment/myapp
Resume rollout:
kubectl rollout resume deployment/myapp
Rollback to Previous Deployment
Undo the last deployment:
kubectl rollout undo deployment/myapp
7. Clean-Up and Resource Management
Orphaned resources eat up cluster budget. Regularly clean up!
Delete a Pod:
kubectl delete pod <pod-name>
Delete a deployment:
kubectl delete deployment <deployment-name>
Delete a namespace and everything within:
kubectl delete namespace <namespace-name>
8. Monitoring, Metrics, and Logs
Observability is critical for both development and production.
Get Resource Usage with Metrics Server
Show CPU and memory usage for Pods:
kubectl top pod
Show node metrics:
kubectl top node
Stream Cluster Events
Watch events cluster-wide (live):
kubectl get events --watch
--watch on any resource for a live feed of changes.9. Bonus: Speed Up Local Dev & Build Pipelines
For developers, quick feedback cycles are critical. Use build-optimization and local testing alongside essential kubernetes commands for developers.
Generate a Template Manifest from Existing Deployment
Export deployment as YAML (without managed fields):
kubectl get deployment myapp -o yaml --export
Best Practices for Using Essential Kubernetes Commands for Developers
- Always work in the right namespace: Set your default namespace to avoid mistakes.
bash
kubectl config set-context --current --namespace=my-namespace - Use label selectors to filter resources:
bash
kubectl get pods -l app=myapp - Automate repetitious commands with aliases and scripts.
- Favor
kubectl applyfor declarative resource management over imperative commands. - Never commit raw Secret values to git – use encrypted stores or external secrets managers.
- Review resource limits and requests in YAMLs to avoid noisy neighbor issues.
- Regularly clean up unused resources to keep your cluster tidy and cost-effective.
- Monitor rollouts and always be ready to rollback when new deploys go wrong.
- Stay updated on the latest Kubernetes features and deprecations.
Conclusion
Mastering the essential kubernetes commands for developers isn’t just about memorizing syntax – it’s about empowering yourself to build, debug, and deploy cloud-native apps faster and safer. From real-time Pod shell access and deployment rollbacks, to secure handling of ConfigMaps and Secrets, each of these commands makes your workflow smoother and lets you focus on what matters: shipping better code.
Remember to follow best practices, use YAML for reproducibility, automate what you can, and never treat security as an afterthought. The more confident you become with these essential kubernetes commands for developers, the more productive and independent you’ll be in your daily work.