Harness Nginx Workflow Setup

Harness

This guide provides the exact details on how you can set up the Nginx Workflow on which our HawkScan Harness Integration Guide is based.

Create a Kubernetes Application Deployment in Harness

Before we begin to deploy HawkScan, we need an application deployed to Kubernetes for it to scan. That’s what we will work on in this guide.

We begin by creating our own Kubernetes cluster. Then we add it to Harness as a Kubernetes Cluster Cloud Provider. And finally we create a Harness Workflow to deploy Nginx as a Kubernetes Deployment. In a bit more detail, here’s the plan:

  1. Stand up a Kubernetes cluster using Docker Desktop.
  2. Add a Harness Delegate to our cluster, so Harness can communicate with it.
  3. Create a Kubernetes Cluster Cloud Provider, inheriting all settings from the Delegate above.
  4. Create a Harness Application named “Nginx.”
  5. Create an Environment for Nginx called “Development,” with its Kubernetes Namespace set to “develop.”
  6. Create an Infrastructure Definition in the Nginx Development Environment for our Kubernetes Cluster Cloud Deployment.
  7. Create an Nginx Service to define how to run our Nginx test app in our Kubernetes cluster.
  8. Create a Workflow called “Nginx Workflow” to deploy our Nginx Service in the Development Environment.

Create a Kubernetes Cluster

We used the latest version of Docker Desktop for Mac, and enabled Kubernetes within it. The process is similar for Docker Desktop for Windows. Once you have installed Docker Desktop:

  • Configure Docker Desktop to use 8GB of RAM (Preferences → Resources → Advanced → Memory).
  • Enable Kubernetes (Preferences → Kubernetes → Enable Kubernetes).

If you have a Linux host, you can follow this guide using K3s. When you install it, you should disable the Traefik ingress controller so it does not prevent your Nginx test app from coming up and listening on port 80.

Create a Harness delegate for your Kubernetes cluster

In Harness, go to Setup → Harness Delegates → Install Delegate. For Download Type, select Kubernetes YAML, and name your delegate “kubicle.”

/assets/images/cicd/harness-kube/1-harness-delegate-kubicle.png

Download the Delegate Kubernetes YAML. It comes with a memory setting which requires 8 GB to be free on the cluster. This is a good setting for production clusters, but since our test cluster is resource-constrained, we need to reduce that limit to 4 GB. So edit the Delegate YAML and replace the string memory: "8Gi" with memory: "4Gi". Finally, apply the Delegate YAML to your cluster using kubectl.

kubectl apply -f ./harness-delegate.yaml

From the Setup → Harness Delegates page, check the status of your delegate. If it’s working, it should show up and report “Status: ✅ Connected.”

/assets/images/cicd/harness-kube/2-harness-delegate-status.png

Add your Kubernetes Cluster to Harness as a Cloud Provider

In Harness, go to Setup → Cloud Providers → Add Cloud Provider, and select Kubernetes Cluster. Give your Cloud Provider the display name, “Kubicle”. Under Cluster Details, select “Inherit from selected Delegate,” and select the “kubicle” delegate. Hit the Test button to make sure it works, and then hit Submit to create the Cloud Provider.

/assets/images/cicd/harness-kube/3-harness-cloud-provider-kubicle.png

Create a Harness Application named Nginx

In Harness, go to Setup and click on Add Application. Name your Application “Nginx.”

/assets/images/cicd/harness-kube/4-harness-add-app-nginx.png

Create a Harness Environment in Nginx named Development

In Harness, go to Setup → Nginx → Environments, and click Add Environment. Name the environment “Development.” Set the environment type to Non-Production.

/assets/images/cicd/harness-kube/5-harness-development-environment.png

Hit Submit to create the environment.

Add Kubicle as an Infrastructure Definition in the Nginx Development Environment

In Harness, go to Setup → Nginx → Environments → Development, and click Add Infrastructure Definition.

  • Name the cluster Kubicle Cluster.
  • Set the Cloud Provider Type to Kubernetes Cluster.
  • Set the Deployment Type to Kubernetes.
  • Select “Use Already Provisioned Infrastructure.”
  • Set the Cloud Provider to “Kubernetes Cluster: Kubicle.”
  • Set the namespace to “develop.”

    /assets/images/cicd/harness-kube/6-harness-infrastructure-kubicle-cluster.png

Hit Submit to create the Infrastructure Definition.

Create a Service in Nginx named Nginx Service

In Harness, go to Setup → Nginx → Services, and click Add Service. Name the service “Nginx Service.” Set the Deployment Type to Kubernetes, and hit Submit.

/assets/images/cicd/harness-kube/7-harness-service-nginx.png

In the Service Overview, click Add Artifact Source → Docker Registry

/assets/images/cicd/harness-kube/8-harness-nginx-service-overview.png

In the Service Overview, under Manifests, edit the values.yaml file to change the name from harness-example to nginx.

/assets/images/cicd/harness-kube/9b-harness-nginx-manifests.png

Create a Workflow in the Nginx App to deploy Nginx Service

In Harness, go to Setup → Nginx → Workflows, and click Add Workflow

  • Name the workflow “Nginx Workflow.”
  • Set Workflow Type to Rolling Deployment.
  • Set Environment to Development.
  • Set Service to Nginx Service.
  • Set Infrastructure Definition to Kubicle Cluster.
  • Hit Submit to create the Workflow.

    /assets/images/cicd/harness-kube/10-harness-nginx-workflow.png

Deploy the Nginx Workflow

In Harness, go to Setup → Nginx → Workflows → Nginx Workflow, and click Deploy. Select the “stable” tag to deploy the latest stable version of the Nginx container.

/assets/images/cicd/harness-kube/11-deploy-nginx-workflow.png

Hit Submit. When the workflow runs, we can see that our Nginx deployment is applied to our Kubernetes cluster. This automatically creates our Development environment namespace, “develop,” and starts an Nginx pod and an Nginx service in that namespace.

/assets/images/cicd/harness-kube/12-harness-nginx-deployment.png

Check your Kubernetes cluster with kubectl to confirm that the service and pod came up as indicated in the deployment detail screen above.

% kubectl get pods,services -n develop 
NAME                                   READY   STATUS    RESTARTS   AGE
pod/nginx-deployment-96b6f4bcf-xkg8l   1/1     Running   0          3m

NAME                TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/nginx-svc   LoadBalancer   10.43.152.230   10.0.0.220    80:30939/TCP   3m

Next Steps

Now that you have Harness deploying Nginx to your Kubernetes cluster as a test app, head back to the HawkScan Harness Integration Guide to learn how to scan that app!