---
title: Connect Kubernetes
url: /docs/ai/agents/integrations/kubernetes/
---


Connect a Kubernetes cluster so an agent can run `kubectl` commands against it. [Pulumi ESC](/docs/esc/) supplies the kubeconfig whenever the agent runs `kubectl`.

## Choose the cluster identity

Use a Kubernetes identity with only the RBAC permissions the agent needs, such as read access to the namespaces it investigates. Before you connect a kubeconfig, check which identity it authenticates as and what that identity's RBAC roles allow. See [Connected credentials](/docs/ai/agents/permissions/#scope-credentials-for-connected-tools) for guidance on scoping credentials.

## Prepare an ESC environment

The [Kubernetes Cluster Access](/docs/esc/guides/integrate-with/kubernetes-cluster-access/) guide walks through both options:

- **Stack-output kubeconfig (recommended for Pulumi-managed clusters).** Use the [`pulumi-stacks`](/docs/esc/providers/iac/pulumi-stacks/) ESC provider to read the kubeconfig from an EKS, AKS, or GKE stack output, then write it to a temporary file through `files.KUBECONFIG`. The connection reads the kubeconfig from the stack output when the environment is opened.
- **Static kubeconfig.** Set the kubeconfig contents in `files.KUBECONFIG` for clusters not managed by a Pulumi program.

If the kubeconfig runs an authentication command, supply the credentials that command needs in the same ESC environment. For example, [Amazon EKS uses `aws eks get-token`](https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html), so an EKS connection also needs AWS credentials for an identity with access to the cluster.

The agent's Pulumi Cloud role needs [permission to open the environment](/docs/ai/agents/permissions/#esc-secrets-and-downstream-cloud-access) before ESC can supply the kubeconfig to `kubectl`. For a Neo task, the user who runs it needs that permission instead.

## Connect the environment

To connect the environment, you need permission to manage organization integrations (`org_integrations:update`):

1. Open your organization's **Agent settings** > **Integrations** > **CLI tools**.
1. Under **Available**, choose **Kubernetes** and select **Connect**.
1. Enter a **Name** and select the **ESC environment** that supplies the credentials.
1. In **Notes (optional)**, describe when the agent should use this connection.
1. Select **Connect**.

For example, name the connection `production-k8s-investigation` and include the cluster name in its notes, so the agent knows which cluster the connection reaches.

## Use the connection

Include the connection name, cluster, and target resources in the [assignment](/docs/ai/agents/configure/#save-and-assign-a-task).

