Scaling NGINX in Kubernetes: From a Standalone Pod to a Deployment

Roshni Wakodikar
3 min readJan 2, 2025

--

If you’re diving into Kubernetes, you’ve likely encountered Pods — the smallest deployable unit in Kubernetes. They’re simple to use but managing them at scale? That’s a whole different story. Enter Deployments, the powerhouse abstraction that simplifies scaling, rolling updates, and self-healing for your Pods.

In this blog, we’ll walk through a common scenario: starting with a standalone NGINX Pod and transitioning to a Deployment to scale it effortlessly. By the end, you’ll have a solid grasp of managing Kubernetes resources like a pro.

Pods vs. Deployments: A Quick Primer

What is a Pod?

A Pod is the foundational building block in Kubernetes. Think of it as a wrapper for your container(s) along with networking and storage resources. A Pod represents a single instance of your application, making it ideal for simple use cases like running a single NGINX server.

What is a Deployment?

Now, if Pods are the bricks, Deployments are the bricklayers. A Deployment ensures your application is running the right number of replicas, updates them seamlessly, and keeps everything in sync. It’s like hiring a manager to handle the day-to-day tasks so you can focus on the bigger picture.

The Scenario

You start with an NGINX Pod — a straightforward setup for running a web server. But as traffic grows, you need more instances to handle the load. Instead of manually creating and managing multiple Pods, you decide to scale with a Deployment.

Here’s how we make that transition.

Step 1: Create a Standalone NGINX Pod

Let’s start by creating a simple Pod configuration in nginx-pod.yaml:

apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx-container
image: nginx:latest
ports:
- containerPort: 80

This YAML defines:

  • A Pod named nginx-pod.
  • A container running the official NGINX image.
  • A label app: nginx for identification.

Apply this configuration using kubectl:

kubectl apply -f nginx-pod.yaml

Verify it’s running:

kubectl get pods

At this point, you have a single NGINX Pod up and running. But what if you need more?

Step 2: Define a Deployment

To scale NGINX, we need a Deployment. Here’s the configuration for nginx-deployment.yaml:

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-container
image: nginx:latest
ports:
- containerPort: 80

Key features here:

  • Replicas: Specifies we want 3 Pods.
  • Selector: Ensures only Pods with the label app: nginx are managed.
  • Template: Defines how new Pods should be created.

Apply this Deployment:

kubectl apply -f nginx-deployment.yaml

Step 3: What Happens Next?

Run this command to check the Pods:

kubectl get pods

You’ll see something like this:

NAME                                 READY   STATUS    RESTARTS   AGE
nginx-deployment-5ccdc5f64c-5lbhb 1/1 Running 0 20s
nginx-deployment-5ccdc5f64c-kjf8v 1/1 Running 0 20s
nginx-deployment-5ccdc5f64c-t9z79 1/1 Running 0 20s
nginx-pod 1/1 Running 0 60s

Wait… four Pods? Why?

The Deployment created three new Pods, but it doesn’t manage the standalone nginx-pod. That Pod was created independently and remains unmanaged.

Step 4: Clean Up the Standalone Pod

To let the Deployment fully manage the application, we need to remove the standalone Pod:

kubectl delete pod nginx-pod

This leaves only the three Pods created by the Deployment. Kubernetes now maintains the desired state of three replicas, ensuring they’re always up and running.

Key Takeaways

1. Kubernetes Does What You Tell It

Deployments only manage Pods created by their template. Existing standalone Pods, even with matching labels, remain unmanaged.

2. Labels and Selectors Are Crucial

Labels help Kubernetes identify and group resources. Aligning labels between Deployments and Pods is essential for resource management.

3. Use Deployments for Scalability

While standalone Pods are fine for quick testing, Deployments are indispensable for scaling and maintaining high availability in production environments.

Final Thoughts

Kubernetes is a powerful system, but it requires understanding its nuances. Transitioning from a standalone Pod to a Deployment is a common step that highlights how Kubernetes abstracts complexity for scalability and reliability.

Next time you’re managing containers, skip the standalone Pods and go straight for a Deployment. It’s like upgrading from a manual car to an automatic — smoother, more efficient, and way less hassle.

Happy orchestrating! 🚀

Sign up to discover human stories that deepen your understanding of the world.

--

--

No responses yet

Write a response