Skip to main content
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 installed.
  • Outbound HTTPS access from the cluster to the required domains.
  • A VCS connection and a fork of env0/templates.
This tutorial stores deployment state with env zero-hosted encrypted state, so you do not need a StorageClass or a persistent volume. To keep state on a persistent volume instead, see Persistent Volume/Storage Class.

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

2

Install the chart

Replace <YOUR_AGENT_ACCESS_TOKEN> with the secret token and <YOUR_PASSPHRASE> with a passphrase you choose.
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

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

Run the chart tests

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 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.

Create a template that needs no cloud credentials

Follow Create your first template with these values: The misc/null-resource folder contains one null_resource and no provider credentials. Skip the cloud account step.
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.

Run the deployment on your cluster

1

Watch the pods

In a terminal, run:
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 and the deployment troubleshooting notes.

Clean up

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

Next steps