Set Up a Kubernetes Cluster Build Infrastructure

Updated 3 months ago by Manish Jaiswal

The following steps set up a Kubernetes cluster build infrastructure for a Harness CI stage.

The Kubernetes build infrastructure is used by your Harness Pipelines to repeatedly and automatedly build your software and run tests. 

Once you set up the Kubernetes cluster to use as your build infrastructure, you connect Harness to it using a Harness Kubernetes Cluster Connector and Harness Delegate.

In this topic:

Before You Begin

Visual Summary

Here's a short video that walks you through adding a Harness Kubernetes Cluster Connector and Harness Kubernetes Delegate. The Delegate is added to the target cluster and then the Kubernetes Cluster Connector uses the Delegate to connect to the cluster.

Step 1: Create a Kubernetes Cluster


  • Ensure your Kubernetes cluster meets the build infrastructure requirements in CI Cluster Requirement.
  • For Harness-specific permission requirements, see permission required for CI.
  • Typically, you install the Harness Kubernetes Delegate in the same cluster you use as your build infrastructure. Ensure that the cluster also has enough memory and CPU for the Delegate you install.

To create a new Kubernetes cluster, see:

Step 2: Add Kubernetes Cluster Connector and Delegate in Harness

  1. In your Project, click Project Setup.
  2. Click Connectors.
  3. Click New Connector and then click Kubernetes Cluster.
  4. Enter a name for the new Kubernetes Cluster Connector.
  5. Click Continue.
  6. In Details, you can select Master URL and Credentials or Use the credentials of a specific Harness Delegate. 
  7. In this example, click Use the credentials of a specific Harness Delegate and click Continue.
  8. In Set Up Delegates, click Install new Delegate. The Delegate setting appears.
  9. Click Kubernetes, and then click Continue.
  10. Enter a name for the Delegate, like quickstart, click the Small size.
  11. In Delegate Configurations, select Primary Configuration. This is simply a default. In the future, you can add Delegate Configuration to run scripts on your Delegates and scope them to different environments.
  12. Click Continue.
  13. Click Download Script. The YAML file for the Kubernetes Delegate will download to your computer as an archive.
  14. Open a terminal and navigate to where the Delegate file is located. You will connect to your cluster using the terminal so you can simply run the YAML file on the cluster.
  15. In the same terminal, log into your Kubernetes cluster. In most platforms, you select the cluster, click Connect, and copy the access command.
  16. Next, install the Harness Delegate using the harness-delegate.yaml file you just downloaded. In the terminal connected to your cluster, run this command:

    kubectl apply -f harness-delegate.yaml

    You can find this command in the Delegate wizard:
    The successful output is something like this:

    % kubectl apply -f harness-delegate.yaml
    namespace/harness-delegate unchanged unchanged
    secret/k8s-quickstart-proxy unchanged
    statefulset.apps/k8s-quickstart-sngxpn created
    service/delegate-service unchanged
  17. In Harness, click Verify. It will take a few minutes to verify the Delegate. Once it is verified, close the wizard. Back in Set Up Delegates, you can select the new Delegate. In the list of Delegates, you can see your new Delegate and its tags.
  18. Select the Connect using Delegates with the following Tags option.
  19. Enter the tag of the new Delegate and click Save and Continue.
  20. When you are done, the Connector is tested.
  21. Click Finish.

Step 3: Define the Build Farm Infrastructure in Harness

  1. In this step, we are using our Kubernetes Cluster Connector and Delegate we added in the previous step to set up our build farm infrastructure in the CI Stage.
  2. In the CI stage Infrastructure, select the Kubernetes Cluster Connector you created in the previous step.
  3. In Namespace, enter the Kubernetes namespace to use.

    You can use a Runtime Input (<+input>) or expression also. See Runtime Inputs.

Option: Add Annotations and Labels 

In some cases, you might need to control the output of the YAML generated when executing a CI stage/step. For example, annotations and labels can be used for cost reporting and node scheduling. You can use the annotations and labels option to attach metadata to your objects.

Annotations: key/value pairs. See syntax.

Labels: key/value pairs that are attached to objects, such as pods. See syntax.

Configure As Code

When configuring your Pipeline in YAML, you add the Kubernetes Cluster CI infrastructure using the infrastructure of type KubernetesDirect:

- stage:
type: KubernetesDirect
connectorRef: account.mydelegate
namespace: default

Once the build farm is set up, you can now add CI stages to execute your Run steps to build, deploy your code.

See Also

Please Provide Feedback