DEV Community

Cover image for Deploying a To-Do Application on Kubernetes
Pavan Belagatti
Pavan Belagatti

Posted on • Originally published at harness.io

Deploying a To-Do Application on Kubernetes

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
  • Harness platform free account access
  • Kubernetes cluster access from any cloud provider. You can also use Minikube or Kind 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

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

todo testing

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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, 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.

project connectors

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

cicd pipeline
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

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

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

deployment
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

The deployment stage execution is shown below:

Harness cd module usage

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

Oldest comments (0)