Deploying a To-Do Application to Kubernetes with Harness

This tutorial shows how we can easily deploy a Kubernetes to-do application using Harness CI/CD.

Published on
12/1/22

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 to-do application that is simple and easily understood by developers, I’ll show you how to deploy it to Kubernetes using Harness. To-do 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 in your browser to see the application working. To run the test, you can simply use the command npm test. 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, make sure 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.

To Do Example: project connectors

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

Enter the deployment stage

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 set-up

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:

Delivery module details and configuration

After all the configuration, you can save and run the pipeline to see the successful execution of the pipeline steps. First, you will see Test and Build stage completing and then you see the deployment stage.

Console logs

The deployment stage execution is shown below:

Deployment stage execution

Learn More

Now you can test, build and deploy your application on Kubernetes using the Harness platform. If you're interested learning more about using Harness and intelligent software delivery, check out our Developer Hub for more step-by-step tutorials, videos, and reference docs.

The Modern Software Delivery Platform™

Loved by Developers, Trusted by Businesses
Get Started

Need more info? Contact Sales