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:

  1. How to list, describe, and debug core Kubernetes resources (Pods, Deployments, Services)
  2. The right way to deploy, update, and rollback applications
  3. Tricks for real-time log inspection and Pod access
  4. Secure handling of ConfigMaps and Secrets on the command line
  5. How to monitor cluster health and resource usage
  6. 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.

💡Best Practice: Learn these commands until muscle memory. You’ll debug faster, and deploy with more confidence.

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>
Sanity Check: Always check resource status before deploying or debugging.

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>
⚠️Common Mistake: Forgetting the namespace (use -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'
💡Tip: Use events to check for scheduling errors, failed volumes, or image pull issues.

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
Quick Win: Use --dry-run=client -o yaml to scaffold any resource config before applying.
📚Kubernetes StatefulSet vs Deployment: Practical Differences, Use Cases, and Hands-On Guide – Compare when you should use Deployments vs StatefulSets.

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
📌Note: Multi-container Pods require the -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
🚨Critical: Only use port forwarding for debug or short-term work. Never use as a replacement for proper Ingress/load balancing.

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
📚Managing Secrets in DevOps: Cloud Native Approaches to Security – Deep dive into secrets management best practices.
⚠️Warning: Never commit raw Secret YAMLs to source control. Use proper Secret management tools and restrict RBAC.

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
💡Best Practice: Always monitor rollout status before declaring a deploy as “done”.

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
🚨Do Not Skip: If a new build causes outages, promptly roll back while you troubleshoot.

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>
📌Prerequisite: Deleting a namespace will remove all resources inside – double check!

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
📌Prerequisite: Requires metrics-server to be deployed.

Stream Cluster Events

Watch events cluster-wide (live):

kubectl get events --watch
💡Tip: Use --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.

📚How to Optimize Docker Image Builds for Faster Builds and Deployments – Streamline your container build process for shorter CI pipelines.

Generate a Template Manifest from Existing Deployment

Export deployment as YAML (without managed fields):

kubectl get deployment myapp -o yaml --export
💡Best Practice: Save this YAML as a baseline for future changes or disaster recovery.

Best Practices for Using Essential Kubernetes Commands for Developers

  1. Always work in the right namespace: Set your default namespace to avoid mistakes.
    bash
    kubectl config set-context --current --namespace=my-namespace
  2. Use label selectors to filter resources:
    bash
    kubectl get pods -l app=myapp
  3. Automate repetitious commands with aliases and scripts.
  4. Favor kubectl apply for declarative resource management over imperative commands.
  5. Never commit raw Secret values to git – use encrypted stores or external secrets managers.
  6. Review resource limits and requests in YAMLs to avoid noisy neighbor issues.
  7. Regularly clean up unused resources to keep your cluster tidy and cost-effective.
  8. Monitor rollouts and always be ready to rollback when new deploys go wrong.
  9. 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.

🚀Try it now: Fire up your sandbox cluster and run through these commands today. Even 30 minutes of hands-on practice will make these commands second-nature.
🚀Next step: Start managing your cluster with these essential kubernetes commands for developers, and check out the related guides above to deepen your DevOps skills even further. Happy coding!