> ## Documentation Index
> Fetch the complete documentation index at: https://docs.envzero.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Run a deployment on your own agent

> Install the env zero self-hosted Kubernetes agent on your cluster with Helm, assign it to a project, and run a first deployment on your own infrastructure.

In this tutorial you install a self-hosted Kubernetes agent, assign it to a project, and run a deployment that executes in a pod on your own cluster. The deployment uses a template that creates no cloud resources, so you need no cloud credentials.

## Prerequisites

* Self-hosted agents enabled for your organization. They are available to Enterprise customers only. If your organization does not have them, the **Agents** page tells you to contact your account manager.
* Admin role or **Edit Organization Settings** permission.
* A Kubernetes cluster at version 1.24 or later, with nodes of at least 2 CPU and 8 GiB memory. Your `kubectl` context must point to it.
* [Helm](https://helm.sh/docs/intro/install/) installed.
* Outbound HTTPS access from the cluster to the [required domains](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/self-hosted-kubernetes-agent.md#required-outbound-domains).
* A [VCS connection](https://docs.envzero.com/guides/getting-started/connect-your-vcs.md) and a fork of [env0/templates](https://github.com/env0/templates).

> [!NOTE]
>
> This tutorial stores deployment state with [env zero-hosted encrypted state](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/env-zero-hosted-encrypted-state.md), so you do not need a `StorageClass` or a persistent volume. To keep state on a persistent volume instead, see [Persistent Volume/Storage Class](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/self-hosted-kubernetes-agent.md#persistent-volumestorage-class-optional).

## Create an agent pool

**1. Open the Agents page**

Go to **Organization Settings** > **Agents**.

**2. Create the agent**

Click **Create Agent**, enter a name in **Agent Name**, and click **Create**. The name must be unique in your organization.

The secrets dialog for the new agent opens. It shows **No secrets yet**.

## Create an agent secret

**1. Add a secret**

In the secrets dialog, click **Add Secret**, enter a **Description** such as `tutorial`, and click **Create Secret**.

**2. Copy the token**

Copy the value under **Secret Token** and keep it. env zero shows it once.

The dialog also shows install commands under **Helm Installation** and **Docker Installation**. This tutorial uses a variant of the Helm command, so click **Done**.

## Install the agent

**1. Add the env zero Helm repository**

```shell theme={null}
helm repo add env0 https://env0.github.io/self-hosted
helm repo update
```

**2. Install the chart**

Replace `<YOUR_AGENT_ACCESS_TOKEN>` with the secret token and `<YOUR_PASSPHRASE>` with a passphrase you choose.

```shell theme={null}
helm install --create-namespace env0-agent env0/env0-agent \
  --namespace env0-agent \
  --set-string agentAccessToken='<YOUR_AGENT_ACCESS_TOKEN>' \
  --set-string env0StateEncryptionKey="$(printf '%s' '<YOUR_PASSPHRASE>' | base64)"
```

The agent encrypts and decrypts your deployment state with the passphrase, and env zero never has access to it. Keep it in your own secret store.

The chart requires `env0StateEncryptionKey` to be base64 of text, which is why the command encodes the passphrase. If you pass a value that is not base64, `helm install` fails with an error that names the value.

## Verify the installation

**1. Check the agent deployment**

```shell theme={null}
kubectl get deployments --namespace env0-agent
```

The list includes `env0-agent-agent-trigger-deployment`. The agent trigger polls env zero for deployment tasks.

**2. Run the chart tests**

```shell theme={null}
helm test env0-agent --namespace env0-agent --logs --timeout 2m
```

The chart tests check that the agent image provides the agent entry points, and that a deployment pod can reach the agent trigger. The persistent volume test is skipped when you set `env0StateEncryptionKey`. If a test fails, its log shows which check failed.

**3. Check the agent status in env zero**

Return to **Organization Settings** > **Agents** and click the refresh icon in the **Agent Pools** header. **Agent Status** shows **Active** when the agent is ready to run deployments. If it shows **Inactive**, wait and refresh again. See [Monitoring self-hosted agents](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/self-hosted-agents-monitoring.md) for what each state means.

## Assign the agent to a project

**1. Find the assignments**

On the **Agents** page, scroll to **Agent Assignments**. It lists your projects.

**2. Select your agent**

In the row of the project you will deploy in, such as **Default Organization Project**, open the dropdown and select your agent.

Projects with no assignment use the organization's default agent. See [Assigning agents to projects](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/overview.md#assigning-agents-to-projects).

## Create a template that needs no cloud credentials

Follow [Create your first template](https://docs.envzero.com/guides/getting-started/create-your-first-template.md) with these values:

| Field | Value |
| - | - |
| Template type | **Terraform** |
| Repository | Your fork of `env0/templates` |
| Terraform folder | `misc/null-resource` |
| Project | The project you assigned your agent to |

The `misc/null-resource` folder contains one `null_resource` and no provider credentials. Skip the cloud account step.

> [!WARNING]
>
> Self-hosted agents do not accept secrets stored on the env zero platform. A template that deploys cloud resources needs credentials and sensitive variables stored as references to your own secret store. See [Sensitive secrets](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/self-hosted-kubernetes-agent.md#sensitive-secrets).

## Run the deployment on your cluster

**1. Watch the pods**

In a terminal, run:

```shell theme={null}
kubectl get pods --namespace env0-agent --watch
```

**2. Run the template**

In env zero, open your project, find the template under **Project Templates**, click **Run Now**, and click **Run**.

The agent creates a pod for the deployment. The pod appears in the `kubectl` output and stays as `Completed` after the deployment finishes, until the agent trigger cleans up old jobs (10 successful jobs are kept by default). In env zero, the environment status changes to **Active**, and the deployment log lists the `null_resource` that Terraform created.

If the deployment stays queued or fails, see [Troubleshooting](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/troubleshooting.md) and the [deployment troubleshooting notes](https://docs.envzero.com/guides/getting-started/running-your-first-environment.md#troubleshooting).

## Clean up

Open the environment and click **Destroy**. The `null_resource` holds no cloud cost, but destroying it keeps your project clean.

## Next steps

* [Self-hosted agents overview](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/overview.md) - Manage pools, rotate secrets, and delete agents.
* [Custom/optional configuration](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/custom-optional-configuration.md) - Set resource limits and other Helm values.
* [Authenticating the agent on AWS EKS](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/authenticating-the-agent-on-aws-eks.md) - Give the agent an IAM role for cloud deployments.
* [HA/DR strategy for self-hosted agents](https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/hadr-strategy-for-self-hosted-agents.md) - Plan for agent failure.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.