Set Up a Kubernetes Cluster Build Infrastructure
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
- Step 1: Create a Kubernetes Cluster
- Step 2: Add Kubernetes Cluster Connector and Delegate in Harness
- Step 3: Define the Build Farm Infrastructure in Harness
- Configure As Code
- See Also
Before You Begin
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
- In your Project, click Project Setup.
- Click Connectors.
- Click New Connector and then click Kubernetes Cluster.
- Enter a name for the new Kubernetes Cluster Connector.
- Click Continue.
- In Details, you can select Master URL and Credentials or Use the credentials of a specific Harness Delegate.
- In this example, click Use the credentials of a specific Harness Delegate and click Continue.
- In Set Up Delegates, click Install new Delegate. The Delegate setting appears.
- Click Kubernetes, and then click Continue.
- Enter a name for the Delegate, like
quickstart, click the Small size.
- 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.
- Click Continue.
- Click Download Script. The YAML file for the Kubernetes Delegate will download to your computer as an archive.
- 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.
- In the same terminal, log into your Kubernetes cluster. In most platforms, you select the cluster, click Connect, and copy the access command.
- Next, install the Harness Delegate using the
harness-delegate.yamlfile 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
- 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.
- Select the Connect using Delegates with the following Tags option.
- Enter the tag of the new Delegate and click Save and Continue.
- When you are done, the Connector is tested.
- Click Finish.
Step 3: Define the Build Farm Infrastructure in Harness
- 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.
- In the CI stage Infrastructure, select the Kubernetes Cluster Connector you created in the previous step.
- 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:
Once the build farm is set up, you can now add CI stages to execute your Run steps to build, deploy your code.