> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/harness-ai/use-harness-platform/connectors/cloud-providers/add-a-kubernetes-cluster-connector.md).

# Add a Kubernetes cluster connector

Connect Harness to your Kubernetes clusters on any platform.

Use a Harness Kubernetes cluster connector to connect Harness to a Kubernetes cluster on any platform. Use the connector to provision infrastructure, run a Continuous Integration (CI) build farm, and deploy microservices and other workloads to the cluster. This topic assumes you have some familiarity with [Harness' key concepts](/harness-ai/new-to-harness-platform/overview.md).

To connect to a platform-specific Kubernetes cluster, such as Google Kubernetes Engine (GKE) or Amazon Elastic Kubernetes Service (EKS), you can use this platform-agnostic connector or a platform-specific connector, such as the [GCP connector](/harness-ai/use-harness-platform/connectors/cloud-providers/connect-to-google-cloud-platform-gcp.md) or the [AWS connector](/harness-ai/use-harness-platform/connectors/cloud-providers/add-aws-connector.md).

***

## What you will learn from this topic <a href="#what-you-will-learn-from-this-topic" id="what-you-will-learn-from-this-topic"></a>

* How to [add a Kubernetes cluster connector](#create-a-kubernetes-cluster-connector) at the account, org, or project scope.
* How to [select a connectivity method](#details) for the connector.
* How to configure the [roles and policies](/harness-ai/use-harness-platform/connectors/cloud-providers/add-a-kubernetes-cluster-connector/kubernetes-cluster-connector-settings-reference.md#roles-and-policies-for-the-connector) required for deployments and builds.
* How to use the connector with [Amazon EKS](#connect-to-amazon-eks) and [Azure Kubernetes Service (AKS)](#aks-clusters-must-have-local-accounts-enabled) clusters.
* How to define a Kubernetes cluster connector using a [YAML example](#yaml-examples).

***

## Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

* **Kubernetes roles and policies**: assign the Kubernetes service account or Harness Delegate that the connector will use the roles and policies required for how you use the connector in your Harness pipelines, such as deployments or Continuous Integration (CI) builds. Go to the [Kubernetes cluster connector settings reference](/harness-ai/use-harness-platform/connectors/cloud-providers/add-a-kubernetes-cluster-connector/kubernetes-cluster-connector-settings-reference.md#roles-and-policies-for-the-connector) for the full list of roles and policies.
* **Amazon EKS clusters**: for considerations specific to EKS, go to [Connect to Amazon EKS](#connect-to-amazon-eks).
* **Azure Kubernetes Service (AKS) clusters**: for considerations specific to AKS, go to [AKS clusters must have local accounts enabled](#aks-clusters-must-have-local-accounts-enabled).

***

## Platform-specific considerations <a href="#platform-specific-considerations" id="platform-specific-considerations"></a>

Review the following considerations if your target cluster runs on Amazon EKS or Azure Kubernetes Service (AKS).

### Connect to Amazon EKS <a href="#connect-to-amazon-eks" id="connect-to-amazon-eks"></a>

To connect Harness to Amazon EKS, you can use the platform-agnostic Kubernetes cluster connector or an [AWS connector configured for EKS](/harness-ai/use-harness-platform/connectors/cloud-providers/add-aws-connector/aws-connector-settings-reference.md#connect-to-elastic-kubernetes-service-eks).

To use an EKS cluster for Kubernetes cluster build infrastructure in Harness CI, you must create a platform-agnostic Kubernetes cluster connector for the stage's build infrastructure, and then you can use either type of connector in individual steps in the stage.

For individual steps in a build stage, if your EKS clusters use IAM roles for service accounts (IRSA) or Fargate nodes in EKS clusters, use an [AWS connector configured for EKS](/harness-ai/use-harness-platform/connectors/cloud-providers/add-aws-connector/aws-connector-settings-reference.md#connect-to-elastic-kubernetes-service-eks).

**Switching IAM policies**: if the IAM role used by your connector does not have the required policies, you can modify or switch the role assigned to the cluster or the Harness Delegate associated with your connector. It can take up to five minutes for IAM policy changes to take effect.

### AKS clusters must have local accounts enabled <a href="#aks-clusters-must-have-local-accounts-enabled" id="aks-clusters-must-have-local-accounts-enabled"></a>

To use an AKS cluster for deployments, the AKS cluster must have local accounts enabled (AKS property `disableLocalAccounts=false`).

***

## Create a Kubernetes cluster connector <a href="#create-a-kubernetes-cluster-connector" id="create-a-kubernetes-cluster-connector"></a>

Perform the following steps to create the Kubernetes cluster connector.

The connector wizard guides you through four steps: **Overview**, **Details**, **Delegates Setup**, and **Connection Test**.

### Overview <a href="#overview" id="overview"></a>

Perform the following steps:

1. Go to **Project Settings** (or **Account Settings** or **Organization Settings**) -> **Connectors**.
2. Select **New Connector** -> **Cloud Providers** -> **Kubernetes cluster**.
3. Enter a **Name**. Harness automatically creates an **Id** based on the name using the [Entity Identifier](/harness-ai/use-harness-platform/references/entity-identifier-reference.md) format. You can edit the ID before saving; once saved, the ID is immutable.
4. Optionally, add a **Description** and **Tags**.

![](https://173309742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3F2TpHXhur2QtQnORSM9%2Fuploads%2Fgit-blob-2bac712291afe15f75fa09a4828137664a654109%2Fadd-kubernetes-connector.png?alt=media)

5. Select **Continue** to proceed to **Details**.

### Details <a href="#details" id="details"></a>

On the **Details** page, select how you want Harness to reach your Kubernetes cluster.

![](https://173309742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3F2TpHXhur2QtQnORSM9%2Fuploads%2Fgit-blob-e29190a970fe0098814c348f461440f9e9bf8314%2Fadd-kubernetes-connectordetails.png?alt=media)

* **Specify master URL and credentials**: authenticate using the Kubernetes master node URL and one of the supported authentication methods. For more information, go to [Specify master URL and credentials](/harness-ai/use-harness-platform/connectors/cloud-providers/add-a-kubernetes-cluster-connector/kubernetes-cluster-connector-settings-reference.md#specify-master-url-and-credentials) in the Kubernetes cluster connector settings reference.
* **Use the credentials of a specific Harness Delegate (IAM role, service account, etc)**: allow the connector to inherit its authentication credentials from the Harness Delegate running in the target cluster. For more information, go to [Use the credentials of a specific Harness Delegate](/harness-ai/use-harness-platform/connectors/cloud-providers/add-a-kubernetes-cluster-connector/kubernetes-cluster-connector-settings-reference.md#use-the-credentials-of-a-specific-harness-delegate) in the Kubernetes cluster connector settings reference.

Select **Continue** to proceed to **Delegates Setup**.

### Delegates Setup <a href="#delegates-setup" id="delegates-setup"></a>

Harness uses Kubernetes cluster connectors at pipeline runtime to authenticate and perform operations with Kubernetes. Authentications and operations are performed by Harness Delegates. Regardless of the authentication method selected in **Details**, you must select the Delegates this connector will use.

![](https://173309742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3F2TpHXhur2QtQnORSM9%2Fuploads%2Fgit-blob-051edfdc3e72c04dc421a7be96ad2aa6b5976183%2Fkubernetes-connector-delegates.png?alt=media)

* **Use any available Delegate**: Harness selects an available delegate at runtime. To learn how Harness selects a delegate when none is specified, go to [Task assignment](/harness-ai/use-harness-platform/delegates/delegate/delegate-concepts/delegate-overview.md#task-assignment).
* **Only use Delegates with all of the following tags**: use **Tags** to match one or more suitable delegates. Harness displays the matching delegates and their tags in the **Test Delegate Connectivity** table. To learn more about delegate tags, go to [Use delegate selectors](/harness-ai/use-harness-platform/delegates/delegate/manage-delegates/select-delegates-with-selectors.md). You can select **Install new Delegate** to add a delegate without exiting connector configuration. For guidance on installing delegates, go to [Delegate installation overview](/harness-ai/use-harness-platform/delegates/delegate/install-delegates/overview.md).

{% hint style="info" %}
It is possible to create a connector with a non-existent delegate. This behavior is intended. This design allows customers to replace a delegate with a new one of the same name or tag.
{% endhint %}

Select **Save and Continue** to proceed to **Connection Test**.

### Connection Test <a href="#connection-test" id="connection-test"></a>

Harness tests the credentials you provided using the delegates you selected and shows the delegate that executed the check. If the test succeeds, select **Finish** to complete the connector setup.

![](https://173309742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3F2TpHXhur2QtQnORSM9%2Fuploads%2Fgit-blob-81a98ac8c8a0d077c772de4fbd5e16ebcbcc99ce%2Fkubernetes-connector-connectiontest.png?alt=media)

***

## YAML examples <a href="#yaml-examples" id="yaml-examples"></a>

The following YAML examples show how to configure a Kubernetes cluster connector for each credential type.

**Specify master URL and credentials**

The following YAML defines a Kubernetes cluster connector that uses the **Specify master URL and credentials** credential type with a service account token.

<details>

<summary>Kubernetes cluster connector YAML</summary>

```yaml
connector:
  name: K8s-qa-target # Connector display name shown in the Harness UI
  identifier: K8sqatarget # Unique connector identifier, cannot be changed after creation
  description: ""
  accountIdentifier: <YOUR_ACCOUNT_ID> # Harness account identifier that owns the connector
  type: K8sCluster # Connector type
  spec:
    credential:
      type: ManualConfig # Use the Specify master URL and credentials credential type
      spec:
        masterUrl: <KUBERNETES_MASTER_URL> # Kubernetes master node URL, for example https://<cluster-api-server>
        auth:
          type: ServiceAccount # Authentication method used with the master URL
          spec:
            serviceAccountTokenRef: account.<YOUR_SECRET_ID> # Identifier of the Harness secret storing the service account token
    ignoreTestConnection: false # Run the connection test when the connector is saved
```

</details>

**Use the credentials of a specific Harness Delegate (IAM role, service account, etc)**

The following YAML defines a Kubernetes cluster connector that uses the **Use the credentials of a specific Harness Delegate (IAM role, service account, etc)** credential type, and selects a delegate by tag.

<details>

<summary>Kubernetes cluster connector YAML</summary>

```yaml
connector:
  name: K8s-inherit-delegate # Connector display name shown in the Harness UI
  identifier: K8sinheritdelegate # Unique connector identifier, cannot be changed after creation
  description: ""
  accountIdentifier: <YOUR_ACCOUNT_ID> # Harness account identifier that owns the connector
  type: K8sCluster # Connector type
  spec:
    credential:
      type: InheritFromDelegate # Use the Use the credentials of a specific Harness Delegate credential type
    delegateSelectors:
      - <YOUR_DELEGATE_SELECTOR> # Delegate tag used to select a delegate for this connector
    ignoreTestConnection: false # Run the connection test when the connector is saved
```

</details>

***

## Next steps <a href="#next-steps" id="next-steps"></a>

* [Kubernetes cluster connector settings reference](/harness-ai/use-harness-platform/connectors/cloud-providers/add-a-kubernetes-cluster-connector/kubernetes-cluster-connector-settings-reference.md): review Kubernetes cluster connector settings, credential options, required roles and permissions, and Amazon EKS and OpenShift support.
* [GCP connector](/harness-ai/use-harness-platform/connectors/cloud-providers/connect-to-google-cloud-platform-gcp.md): connect Harness to Google Cloud Platform, including GKE clusters and other GCP resources.
* [AWS connector](/harness-ai/use-harness-platform/connectors/cloud-providers/add-aws-connector.md): connect Harness to AWS, including EKS clusters and other AWS resources.
