Experience the Power of Microservices: A Step-by-Step Guide to Deploying the Demo Voting App

Nwokolo Emmanuel
4 min readMay 11, 2023

Welcome to another exciting edition of our series.

In this edition, you will be learning how to deploy a Microservice: The voting app,

and we are going to be using a hand full of tools

prerequisite:

- A cluster running

- An Ubuntu machine

- Terraform installed

- Kubectl installed

- AWS CLI installed

To make things easier, follow this link HERE to get the script I wrote that helps you install all these tools on your machine.

I have also added a link HERE, to help you spin up a Virtual Machine on DigitalOcean or any other cloud provider.

And If you have gotten all these setups, let’s dive into our main topic!

1. PROVIDERS

First, we need to configure our provider’s file. This file will hold the namespace creation and authentication to our cluster.

In the file above, just like the ones we had in the Prometheus and Nginx section, where ever you see ClusterName, replace it with your cluster name.

We are also creating a new namespace called the “voting app” for our project.

2. POSTGRES DEPLOYMENT

In this section, we will deploy Postgres with Terraform on a Kubernetes cluster.

In the file above, we ran the deployment in the namespace we had created, and we also set up one replica of this using the postgres:9.4 docker image and a service for listening on port 5432

3. REDIS

The second service up for deployment is Redis which will be deployed in the “voting app” namespace.

The configurations found in the file above are the same as the Postgres file in step two.

However, the service here is listening on port 6379, while the image’s name is Redis.

4. RESULT APP

The Result app is where we can see the result of the vote we have cast, and in this section, we will be looking at how to deploy it.

And just like all the files we have been creating, the result file is no different, only that it runs on port 80 , and the name of the docker image is dockersamples/examplevotingapp_result.

5. VOTING APP

The voting app just like the result app is where we can cast a vote.

the voting app is also listening on port 80 and the image name is “kodekloud/examplevotingapp_vote:v1”.

6. WORKER APP

The last app we will be deploying here will be the worker app, and the image name is dockersamples/examplevotingapp_worker.

This app will not have any ports because it’s not supposed to be accessible from outside. And we are creating three replicas of it.

When you have created all the files, your file structure should look like this:

Now you can run this command to initialize Terraform in the present working directory:

$ terraform init

Then you should run this command to apply every file and create the deployment:

$ terraform apply --auto-approve

And when this runs successfully. Use this command to confirm the deployment:

$ kubectl get svc -n voting-app

You should see a list of all the services we deployed above!

Congratulations!! You just deployed the voting app with Terraform and Kubernetes!!!

Resources

NOTICE

There is a platform called THE CLOUD TOP G MASTERMIND where you can learn more about becoming a Cloud Engineer, the tools you need to build your projects, and getting your dream job.

You can get more details by clicking this LINK.

see you soon!

NOTE: If you have any questions or want to add to this blog, you can send me an E-mail. And I reply faster to people that subscribe to my newsletter!!

Conclusion

If you loved this blog post, please, give it a like, comment, and don’t forget to click the follow button.

And if you would love to get an update on the two exciting blogs I will be posting this week, then you should sign up for my newsletter right here!!

--

--

Nwokolo Emmanuel

I am a Cloud Engineer, I love sharing easy solutions to problems that I found difficult. Interested in Open Source | twitter: twitter.com/CloudTopG