In basic terms, a deployment is a Kubernetes object that manages the creation of pods via ReplicaSets. The deployment creates pods by way of a specification from a template. With a deployment, it is possible to quickly scale up or down a set of identical pods.

Say, for instance, you want to deploy a set of identical NGINX pods to your cluster. By using a deployment, you can very quickly scale those pods to meet demand.

I want to show you how to create an NGINX deployment, and then scale it up.

That line tells Kubernetes we're going to create three identical Pods, named nginx.

Save and close the file.

To create the deployment, issue the command:

kubectl apply -f nginx-deploy.yaml

If you issue the command:

kubectl get deployments

You should see that nginx-deployment is listed with 3/3 Pods ready (Figure A).

Figure A

Our Kubernetes NGINX deployment was a success.

How to scale the deployment

With our deployment created, we can now scale it up. Let's say you have a need to scale the number of NGINX pods from three to five. There are two ways to do this. First, you could edit the YAML file and change the line:

replicas: 3

to:

replicas: 5

Once you've changed that value, save and close the file, and rerun the command:

kubectl apply -f nginx-deploy.yaml

After running the above command, you should see nginx-deployment listed as 5/5 (Figure B).

Figure B

Our NGINX pods have been scaled to 5.

Another way of doing this is via the command line (without editing the YAML file). Say we want to take the NGINX pods up to 11. For that, we use the kubectl scale command like so:

kubectl scale deployments/nginx-deployment --replicas=11

At this point, our NGINX pods should be listed as 11/11 (Figure C).

Figure C

We've scaled the NGINX pods to 11.

How to scale down your pods

You can also scale those pods down in the same way you scaled them up. Within the YAML file, you could change the:

replicas: 5

line to:

replicas: 3

And with the kubectl command you could scale them from 11 to 3 like so:

kubectl scale deployments/nginx-deployment --replicas=3

You could even scale them down to 0 if you need.

And that's the basics of scaling Kubernetes deployments up and down. Although this is a very simple example, you can apply that to far more complicated deployments and get them scaled to meet your growing container demands.

Comment and share: How to scale a deployment within a Kubernetes cluster

By Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.