Skip to main content
In this lesson, we enhance the initial demo—which deployed Pods and Services directly—by leveraging Kubernetes Deployments. This improved approach addresses the challenges of scaling and updating applications without downtime. By using Deployments, you can automate the management of ReplicaSets, making it simple to scale, roll out updates, and perform rollbacks while retaining a history of revisions.
The image illustrates a Kubernetes deployment architecture for a voting app, featuring multiple pods for voting, results, Redis, database, and worker services.
Deploying individual Pods limits your ability to easily increase the number of service instances or update the container image without downtime. Using Deployments streamlines these processes.
In the upgraded setup, each application component—including the front-end apps (voting and results), databases, and worker applications—is encapsulated within its own Deployment. The project directory now hosts both the original Pod and Service definition files, along with new files for the Deployments.

Voting App Deployment

We begin by defining a basic Pod for the voting app:
Then, create a Deployment file (votingapp-deployment.yaml) based on this pod template. Adjust the API version to apps/v1, change the kind to Deployment, and add the selector and replicas fields:
This configuration allows you to start with a single replica on your cluster for resource efficiency, with the option to scale up as needed.

Redis Deployment

Begin with the original Redis Pod definition:
Then, create the Redis Deployment (redis-deploy.yaml) using the same template as the voting app deployment. Update the component names, labels, and container details accordingly:

PostgreSQL Deployment

Transform the PostgreSQL Pod into a Deployment. First, consider the original PostgreSQL Pod definition with environment variables:
Now, create the PostgreSQL Deployment (postgres-deploy.yaml). Ensure that the selector matches the Pod template labels:

Worker App Deployment

For the worker application, start with its Pod definition:
Then, create a corresponding Deployment (worker-app-deploy.yaml). Update the names, labels, and selectors as required:

Result App Deployment

Similarly, convert the result application from a Pod to a Deployment. Create the file result-app-deploy.yaml, update the names and labels from the original Pod definition, and ensure that the template matches the selector criteria. Your project directory should now include files similar to the following:

Deploying on Kubernetes

Before creating the new Deployments and Services, ensure that any previously created resources are removed. Verify by running:
Once the cluster is clean, proceed with the deployments.

Creating the Voting App Deployment

Deploy the voting app using the command below:
Verify the deployment:
Expected output:

Deploying Redis, PostgreSQL, and Their Services

First, deploy Redis and its service:
Then, deploy PostgreSQL and its service:
Confirm that all Pods are running:
Sample output:

Deploying Worker and Result Applications

Deploy the worker application (which does not have an associated Service):
Next, deploy the result application and its service:
Finally, check that all Deployments and Services are active:
Example output:

Accessing the Front-End Applications

Use Minikube to retrieve the URLs for the voting and result services:
Open these URLs in your web browser to interact with the voting app. Load balancing within the Deployment ensures that different pods serve your requests.

Scaling the Voting App Deployment

Scaling the voting application is straightforward with Deployments. For example, to increase the number of voting app replicas from one to three, run:
After scaling, verify the status:
Refresh the voting service URL in your browser several times to observe that requests are being handled by multiple pods, confirming that the scaling is effective.
This lesson demonstrates how Kubernetes Deployments simplify application management by enabling effortless scaling, rolling updates, and high availability. Happy deploying, and see you in the next lesson!

Watch Video