How to Manage Kube Pods

How to Manage Kube Pods Kubernetes, often abbreviated as K8s, has become the de facto standard for container orchestration in modern cloud-native environments. At the heart of Kubernetes lies the pod — the smallest deployable unit in the system. A pod encapsulates one or more containers that share storage, network, and specifications for how to run. While pods are designed to be ephemeral and stat

Nov 6, 2025 - 10:27
Nov 6, 2025 - 10:27
 1

How to Manage Kube Pods

Kubernetes, often abbreviated as K8s, has become the de facto standard for container orchestration in modern cloud-native environments. At the heart of Kubernetes lies the pod the smallest deployable unit in the system. A pod encapsulates one or more containers that share storage, network, and specifications for how to run. While pods are designed to be ephemeral and stateless by nature, managing them effectively is critical to ensuring application reliability, scalability, and performance. This guide provides a comprehensive, step-by-step tutorial on how to manage Kube pods, covering everything from basic operations to advanced best practices and real-world scenarios.

Managing Kube pods isnt just about starting and stopping containers. It involves monitoring health, scaling dynamically, troubleshooting failures, applying updates without downtime, and ensuring compliance with resource policies. Whether youre a DevOps engineer, a site reliability engineer (SRE), or a developer working in a Kubernetes environment, mastering pod management is essential to delivering resilient, high-performing applications.

This tutorial will walk you through the core concepts, practical commands, industry-standard practices, and tools you need to confidently manage pods in production environments. By the end, youll understand not only how to perform common tasks, but also how to anticipate issues, optimize resource usage, and automate operations for long-term efficiency.

Step-by-Step Guide

Understanding the Pod Lifecycle

Before diving into commands and tools, its crucial to understand how pods behave throughout their lifecycle. A pod goes through several phases: Pending, Running, Succeeded, Failed, and Unknown. Each phase reflects the current state of the pods containers and the Kubernetes control planes ability to manage them.

Pending means the pod has been accepted by the Kubernetes cluster but one or more containers have not yet been created. This is often due to image pulling, resource scheduling, or network configuration delays.

Running indicates that all containers in the pod have been created and at least one is running or in the process of starting. This is the desired state for most workloads.

Succeeded applies to pods that ran to completion (e.g., batch jobs) and exited successfully without restarting.

Failed means all containers have terminated, and at least one container exited with a non-zero status indicating an error.

Unknown is a state where the pods status cannot be determined, often due to communication issues between the node and the control plane.

Understanding these states helps you diagnose issues quickly. For example, a pod stuck in Pending may indicate insufficient CPU or memory resources, while a pod cycling between Running and CrashLoopBackOff suggests a misconfigured application or missing dependency.

Creating a Pod

Pods are typically created using YAML manifests, which define their specifications declaratively. While you can create pods using imperative commands like kubectl run, using YAML is the recommended approach for production environments because it ensures reproducibility and version control.

Heres a basic pod manifest:

apiVersion: v1

kind: Pod

metadata:

name: nginx-pod

labels:

app: nginx

spec:

containers:

- name: nginx-container

image: nginx:1.21

ports:

- containerPort: 80

resources:

requests:

memory: "64Mi"

cpu: "250m"

limits:

memory: "128Mi"

cpu: "500m"

To create this pod, save the manifest as nginx-pod.yaml and run:

kubectl apply -f nginx-pod.yaml

You can verify creation with:

kubectl get pods

This will show the pods name, status, restart count, and age. The apply command is idempotent running it again will not recreate the pod unless the manifest has changed.

Inspecting Pod Details

Once a pod is running, youll often need to inspect its configuration and runtime state. Use the following commands:

  • kubectl describe pod <pod-name> Provides detailed information about the pods events, conditions, resource usage, and container statuses. This is invaluable for debugging.
  • kubectl get pod <pod-name> -o yaml Outputs the full YAML definition of the pod as known to the API server. Useful for comparing desired vs. actual state.
  • kubectl logs <pod-name> Retrieves logs from the primary container in the pod. For multi-container pods, specify the container name with -c <container-name>.
  • kubectl exec -it <pod-name> -- /bin/sh Opens an interactive shell inside the container. This is useful for inspecting filesystems, checking running processes, or testing connectivity.

For example, if you suspect an application is failing to connect to a database, you can exec into the pod and run curl or telnet to test network reachability.

Scaling Pods Manually

While pods are managed by higher-level controllers like Deployments or StatefulSets in production, you can manually scale individual pods for testing or temporary workloads.

To scale a pod to multiple replicas, you must use a Deployment or ReplicaSet. However, if youre working directly with pods (not recommended for production), you can create multiple pod manifests with unique names and apply them:

for i in {1..3}; do

cp nginx-pod.yaml nginx-pod-$i.yaml

sed -i "s/nginx-pod/nginx-pod-$i/g" nginx-pod-$i.yaml

kubectl apply -f nginx-pod-$i.yaml

done

A better approach is to use a Deployment:

apiVersion: apps/v1

kind: Deployment

metadata:

name: nginx-deployment

spec:

replicas: 3

selector:

matchLabels:

app: nginx

template:

metadata:

labels:

app: nginx

spec:

containers:

- name: nginx

image: nginx:1.21

ports:

- containerPort: 80

Apply and scale:

kubectl apply -f nginx-deployment.yaml

kubectl scale deployment/nginx-deployment --replicas=5

Deployments automatically manage underlying ReplicaSets and ensure the desired number of pods are running, replacing failed ones automatically.

Updating and Rolling Out Pod Changes

Updating a pods configuration requires replacing the pod, since pods are immutable. The correct way to update is by modifying the Deployments pod template and applying the change.

For example, to upgrade the nginx image from 1.21 to 1.23:

kubectl set image deployment/nginx-deployment nginx=nginx:1.23

Kubernetes performs a rolling update by default: it creates new pods with the updated image and terminates old ones one at a time, ensuring zero downtime. You can monitor the rollout with:

kubectl rollout status deployment/nginx-deployment

To view the rollout history:

kubectl rollout history deployment/nginx-deployment

If the new version has issues, you can roll back:

kubectl rollout undo deployment/nginx-deployment

Always test image changes in a staging environment before deploying to production. Use image tags like latest sparingly prefer versioned tags to ensure reproducibility.

Deleting Pods

Deleting a pod is straightforward but requires caution. Use:

kubectl delete pod <pod-name>

If the pod is managed by a Deployment, ReplicaSet, or StatefulSet, Kubernetes will automatically recreate it to maintain the desired replica count. To prevent recreation, delete the controller:

kubectl delete deployment <deployment-name>

For pods not managed by controllers (e.g., standalone pods), deletion is permanent. Use the --force and --grace-period=0 flags only if a pod is stuck in Terminating state due to node failure:

kubectl delete pod <pod-name> --force --grace-period=0

Be aware that forcing deletion may result in data loss if the pod was writing to persistent storage.

Managing Pod Resources and Limits

Resource requests and limits are critical for cluster stability and performance. Requests define the minimum resources a pod needs to be scheduled. Limits define the maximum resources it can consume.

Under-provisioning can cause pods to be evicted or starved for CPU/memory. Over-provisioning leads to wasted resources and poor cluster utilization.

Example with resource constraints:

resources:

requests:

memory: "128Mi"

cpu: "500m"

limits:

memory: "256Mi"

cpu: "1000m"

Use kubectl top pods to see real-time resource usage. Combine this with monitoring tools like Prometheus to identify trends and right-size your allocations.

Always set limits for memory to prevent OutOfMemory (OOM) kills. For CPU, limits are soft the container can burst beyond them if resources are available, but will be throttled if demand exceeds the limit.

Working with Multi-Container Pods

Pods can host multiple containers that share the same network namespace and storage volumes. This is useful for sidecar patterns (e.g., logging agents, service meshes) or adapter containers that transform data.

Example: A web server pod with a logging sidecar:

apiVersion: v1

kind: Pod

metadata:

name: web-with-logger

spec:

containers:

- name: web-server

image: nginx:1.21

ports:

- containerPort: 80

volumeMounts:

- name: log-volume

mountPath: /var/log/nginx

- name: log-aggregator

image: busybox

command: ['sh', '-c', 'tail -f /var/log/nginx/access.log']

volumeMounts:

- name: log-volume

mountPath: /var/log/nginx

volumes:

- name: log-volume

emptyDir: {}

In this example, both containers share the emptyDir volume. The web server writes logs, and the sidecar reads and streams them. This pattern avoids the need for external log collection agents on the host.

Handling Pod Evictions and Node Failures

Pods can be evicted due to resource pressure, node maintenance, or taints. To handle this gracefully:

  • Use PodDisruptionBudget (PDB) to ensure a minimum number of pods remain available during voluntary disruptions (e.g., upgrades).
  • Set appropriate terminationGracePeriodSeconds to allow containers to shut down cleanly.
  • Use livenessProbe and readinessProbe to detect and recover from unhealthy states.

Example PDB:

apiVersion: policy/v1

kind: PodDisruptionBudget

metadata:

name: nginx-pdb

spec:

minAvailable: 2

selector:

matchLabels:

app: nginx

This ensures at least two nginx pods remain available during disruptions, even if the cluster is scaled down or nodes are drained.

Best Practices

Always Use Controllers, Not Standalone Pods

Standalone pods are not self-healing. If the node they run on fails, the pod is gone forever. Always use Deployments for stateless applications, StatefulSets for stateful workloads (e.g., databases), and DaemonSets for node-level services (e.g., log collectors).

Define Resource Requests and Limits

Never leave resource requests and limits unset. This can lead to unpredictable scheduling, resource contention, and cluster instability. Use tools like the Kubernetes Vertical Pod Autoscaler (VPA) to analyze historical usage and suggest optimal values.

Use Readiness and Liveness Probes

Liveness probes tell Kubernetes when to restart a container. Readiness probes tell it when the container is ready to serve traffic. Use HTTP probes for web apps, TCP probes for services that dont expose HTTP, and exec probes for custom health checks.

Example:

livenessProbe:

httpGet:

path: /health

port: 80

initialDelaySeconds: 30

periodSeconds: 10

readinessProbe:

httpGet:

path: /ready

port: 80

initialDelaySeconds: 5

periodSeconds: 5

These prevent traffic from being routed to pods that arent fully initialized and restart unresponsive containers automatically.

Implement Image Pull Policies Correctly

Use imagePullPolicy: IfNotPresent for development and Always for production. This ensures youre always running the latest tagged image in production and avoids caching stale versions.

Label and Annotate Pods Strategically

Labels (e.g., app: web, env: prod) are used for selection and grouping. Annotations (e.g., deployment-hash: abc123) store non-identifying metadata like build timestamps or CI/CD pipeline IDs.

Use consistent labeling across your organization to enable automation, monitoring, and cost allocation.

Secure Pod Security Contexts

Run containers as non-root users whenever possible. Use security contexts to enforce least privilege:

securityContext:

runAsUser: 1000

runAsGroup: 3000

fsGroup: 2000

Also, disable privilege escalation, set read-only root filesystems, and use network policies to restrict pod-to-pod communication.

Monitor and Alert on Pod Health

Integrate with observability tools like Prometheus, Grafana, and Loki. Set alerts for:

  • Pod restarts exceeding thresholds
  • Pods in CrashLoopBackOff
  • Resource usage nearing limits
  • Pods stuck in Pending for more than 5 minutes

These proactive alerts help you resolve issues before users are impacted.

Use Namespaces for Isolation

Organize pods into namespaces (e.g., production, staging, dev) to separate environments, teams, and resource quotas. Use NetworkPolicies and ResourceQuotas to enforce boundaries.

Automate with CI/CD Pipelines

Never manually apply pod manifests. Use GitOps workflows with tools like Argo CD or Flux to sync your cluster state with a Git repository. Every change to the manifest triggers an automated rollout, ensuring auditability and consistency.

Tools and Resources

Core Kubernetes Tools

  • kubectl The primary command-line interface for interacting with Kubernetes clusters. Essential for all pod management tasks.
  • kubectx and kubens Tools to switch between clusters and namespaces quickly. Saves time when managing multiple environments.
  • k9s A terminal-based UI for navigating and managing Kubernetes resources. Offers real-time logs, resource graphs, and quick deletion without typing full commands.
  • kube-score A static analysis tool that checks your manifests for security, performance, and best practice violations.
  • Conftest Validates YAML against Rego policies (Open Policy Agent). Useful for enforcing organizational standards across teams.

Monitoring and Observability

  • Prometheus Collects metrics from pods (CPU, memory, network) via kube-state-metrics and cAdvisor.
  • Grafana Visualizes metrics with customizable dashboards for pod health, resource usage, and rollout trends.
  • Loki Log aggregation system designed for Kubernetes. Efficiently stores and queries logs from pods across the cluster.
  • OpenTelemetry Provides distributed tracing to understand latency and dependencies between microservices running in pods.

Automation and GitOps

  • Argo CD Declarative GitOps continuous delivery tool that syncs Kubernetes manifests from Git repositories.
  • Flux Another GitOps operator that automates updates based on image registry changes or Git commits.
  • GitHub Actions or GitLab CI Automate testing, building, and deploying pod manifests as part of your CI/CD pipeline.

Learning Resources

  • Kubernetes Official Pod Documentation The authoritative source for pod concepts and specifications.
  • Kubernetes Tasks Step-by-step guides for common operations, including pod management.
  • Kubernetes in Action by Marko Luksa A comprehensive book covering Kubernetes internals and practical deployment strategies.
  • Learnk8s.io Free tutorials and real-world examples for managing pods and workloads.
  • Kubernetes Slack Community Active community for asking questions and sharing experiences.

Real Examples

Example 1: Deploying a Multi-Tier Application

Consider a simple web application with a frontend (React), backend (Node.js), and Redis cache.

Each component runs in its own Deployment:

  • Frontend: Serves static files via nginx. Uses a PodDisruptionBudget to ensure at least 2 replicas are always available.
  • Backend: Node.js API with liveness and readiness probes. Resource limits set to 500m CPU and 1Gi memory.
  • Redis: Runs as a StatefulSet with persistent storage. Uses a custom init container to set permissions.

Each Deployment is versioned using Git tags. CI/CD pipelines build Docker images, push them to a private registry, and trigger Argo CD to update the cluster.

Monitoring shows that during peak traffic, the backend pod CPU usage spikes to 85%. The team uses VPA to increase the request from 250m to 500m, reducing throttling and improving response times.

Example 2: Debugging a CrashLoopBackOff

A pod named api-gateway-7d5b9c8f4d-2xq7k is stuck in CrashLoopBackOff. The team runs:

kubectl logs api-gateway-7d5b9c8f4d-2xq7k

The output shows: error: could not connect to database: dial tcp 10.96.0.10:5432: i/o timeout.

They exec into the pod and test connectivity:

kubectl exec -it api-gateway-7d5b9c8f4d-2xq7k -- sh

ping 10.96.0.10

telnet 10.96.0.10 5432

The ping succeeds, but telnet times out. This indicates the database service exists but is not accepting connections.

Investigating the database Deployment, they find it was scaled down to 0 replicas during a maintenance window and forgotten. They scale it back up:

kubectl scale deployment/postgres --replicas=1

The API pod restarts successfully and transitions to Running. The team adds a monitoring alert for zero-replica StatefulSets to prevent recurrence.

Example 3: Optimizing Resource Usage with VPA

A team notices their 100 microservices are over-provisioned. CPU requests average 500m, but actual usage is under 100m.

They deploy the Vertical Pod Autoscaler and enable it for a test Deployment:

kubectl apply -f https://github.com/kubernetes/autoscaler/raw/master/vertical-pod-autoscaler/deploy/recommended.yaml

After 24 hours of data collection, VPA recommends reducing the CPU request from 500m to 150m and memory from 512Mi to 128Mi.

They apply the changes and observe no performance degradation. The cluster now runs 30% more workloads on the same hardware, reducing cloud costs by 22%.

FAQs

Can I modify a running pod directly?

No. Pods are immutable. To change a pods configuration such as its image, environment variables, or resource limits you must delete it and recreate it with the new specification. This is why controllers like Deployments are used: they automate this process.

Why is my pod stuck in Pending?

Common reasons include:

  • Insufficient CPU or memory resources in the cluster.
  • Node taints that prevent scheduling (e.g., dedicated nodes for specific workloads).
  • Image pull failures due to incorrect registry credentials or network policies.
  • Storage class not available or persistent volume claims not bound.

Use kubectl describe pod <pod-name> to see events that explain the cause.

Whats the difference between a Deployment and a Pod?

A Pod is a single instance of a running application. A Deployment is a controller that manages multiple identical pods. Deployments ensure the desired number of pods are always running, handle updates, and provide rollback capabilities. Pods alone are not self-healing.

How do I check which node a pod is running on?

Run kubectl get pods -o wide. The output includes a NODE column showing the node name where each pod is scheduled.

Can pods communicate across namespaces?

Yes, by default. However, its recommended to use NetworkPolicies to restrict communication to only trusted services. Cross-namespace communication increases attack surface and complicates troubleshooting.

What happens when a node fails?

Kubernetes detects the failure and reschedules the pods from that node onto healthy nodes, provided there are sufficient resources. If the pods are managed by a Deployment or StatefulSet, they are recreated automatically. If they are standalone, they are lost unless manually recreated.

How do I prevent pods from being scheduled on specific nodes?

Use node selectors, node affinity, or taints and tolerations. For example, to prevent pods from running on master nodes, apply a taint:

kubectl taint nodes control-plane node-role.kubernetes.io/control-plane:NoSchedule

Then ensure your pods have a corresponding toleration or avoid matching the tainted node.

Is it safe to use the :latest tag for production pods?

No. Using :latest makes deployments non-reproducible and increases risk. Always use immutable tags like v1.2.3 or git commit hashes. This ensures you can roll back to a known-good version.

Conclusion

Managing Kube pods is a foundational skill for anyone working with Kubernetes. While pods are simple in concept, their effective management requires a deep understanding of Kubernetes architecture, resource constraints, health checks, and automation principles. This guide has walked you through the full lifecycle of pod management from creation and scaling to monitoring, troubleshooting, and optimization.

Remember: pods are ephemeral by design. Your applications must be built to handle restarts, scaling, and failures gracefully. Rely on controllers like Deployments, enforce resource limits, implement proactive monitoring, and automate deployments through GitOps to ensure reliability at scale.

As you continue working with Kubernetes, invest time in learning its ecosystem tools like Prometheus, Argo CD, and k9s will become indispensable. Stay curious, test changes in non-production environments, and always prioritize observability and security.

Mastering pod management isnt just about executing commands its about cultivating a mindset of resilience, automation, and continuous improvement. With the practices outlined here, youre now equipped to manage Kube pods confidently, whether youre deploying a simple web app or orchestrating thousands of microservices in a global production environment.