Deploying a To-Do Application on Kubernetes
Tags: kubernetes, devops, cicd
Published: 2022-12-02 05:46:24

Continuous integration and delivery (CI/CD) is a very important part of any successful DevOps methodology. DevOps ensures the use of microservices, containerizing the applications, using CI/CD, deploying applications using cloud-native technologies such as Kubernetes, and more. All these things speed up and streamline the process of software development and help developers collaborate.

Harness is a modern software delivery platform helping thousands of developers adopt CI/CD. We would love to show how easy it is to set up CI/CD with Harness and streamline your software delivery process. Taking an example of a todo application that is simple and easily understood by developers, I’ll show you how to deploy it to Kubernetes using Harness. Todo application is something that every developer is familiar with and involves simple operations of creating tasks. Follow the tutorial to learn how we can easily deploy this application using Harness CI/CD. 

## Pre-Requisites:
- Download and install [Node.js](https://nodejs.org/en/download/) 
- [Harness platform](https://app.harness.io/auth/#/signup/?utm_source=internal&utm_medium=social&utm_campaign=community&utm_content=kubernetes-toto-article&utm_term=get-started) free account access
- Kubernetes cluster access from any cloud provider. You can also use [Minikube](https://minikube.sigs.k8s.io/docs/start/) or [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/) to create a single node cluster. 

### Tutorial:
Use the command `git clone https://github.com/pavanbelagatti/todo-app-example.git` to clone the repo to your local machine.

Then, get into the main folder with the command.

`cd todo-list-app`

Then use the command `npm install` to install all the dependencies needed for the project.

Run the application with the command `node app.js` and visit http://localhost:8080/todo in your browser to see the application working. 

![todo application running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4b6wxtgr60yvejzt1b1h.png)

To run the test, you can simply use the command `npm test`.

![todo testing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/82t22dbluu9o0i6i82d7.png)

We have both _deployment.yaml_ and _service.yaml_ files set to deploy and expose the application through Kubernetes. 

Below is the _deployment.yaml_ file

```
apiVersion: apps/v1
kind: Deployment
metadata:
 labels:
   app: todo-app
 name: todo-app
spec:
 replicas: 2
 selector:
   matchLabels:
     app: todo-app
 template:
   metadata:
     labels:
       app: todo-app
   spec:
     containers:
     - image: dockerhub image name
       name: todo-app
       ports:
       - containerPort: 8080
```

Below is the _service.yaml_ file

```
apiVersion: v1
# Indicates this as a service
kind: Service
metadata:
 # Service name
 name: todo-app
spec:
 selector:
   # Selector for Pods
   app: todo-app
 ports:
   # Port Map
 - port: 80
   targetPort: 8080
   protocol: TCP
 type: LoadBalancer
```
### CI/CD: Using Harness 
Harness has a pretty sleek UI and can easily help developers do CI/CD effortlessly. Once you [sign-up at Harness](https://app.harness.io/auth/#/signup/), ensure you have access to the Kubernetes cluster to deploy your application. Login to the Harness platform and ensure the basic connectors are ready. Also, make sure you have the Delegate installed on your target Kubernetes cluster. 

The Harness Delegate is a service/software you need to install/run on the target cluster (Kubernetes in our case) to connect your artifacts, infrastructure, collaboration, verification and other providers with the Harness Manager. When you set up Harness for the first time, you install a Harness Delegate.

If you want to know more about Delegate, you can read [here](https://docs.harness.io/article/2k7lnc7lvl-delegates-overview).

![project connectors](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kangahdq0p70o2tgvy1j.png)

Create a project on Harness to set up CI/CD pipeline. First, select the continuous integration module and then the delivery module.

![cicd pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2uoijpdga236rm7yyy4y.png)
As you can see above, we will first test and build, and then we will deploy the application to the Kubernetes cluster.

Test and Build set-up is shown below:

![test and build](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncnj3ucualr9wqbttadx.png)

Basically, we are configuring the infrastructure (Kubernetes, in our case), specifying to carry out the tests, and finally pushing the build image to Docker Hub after the successful test cases. 

When you click on the test step, you will see our configuration:

![configure run step](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pygofsp5ry8ahwanggqq.png)

Similarly, the delivery module details and configuration will look like this:

![deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z9x54filaf1fo9ycezgw.png)
After all the configuration, you can save and run the pipeline to see the successful execution of the pipeline steps. First, you will see the Test and Build stage completing and then you see the deployment stage.

![Harness deploying](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3p7v2qa7s4geqnh0l87z.png)

The deployment stage execution is shown below:

![Harness cd module usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/akgvdn7o61ss9ma9aeov.png)

This is how you can test, build and deploy your application on Kubernetes using the Harness platform.