December 1, 2022

Deploying a To-Do Application to Kubernetes with Harness

Table of Contents

Deploying a to-do application to Kubernetes with Harness involves setting up a CI/CD pipeline, configuring Kubernetes clusters, and using deployment scripts. This guide demonstrates the ease of deploying applications using Harness’s intuitive platform, ensuring streamlined and efficient application management.

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 https://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.

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:

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:

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

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.

The deployment stage execution is shown below:

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.

Continuous Delivery & GitOps