> Markdown version of https://tuna.am/en/docs/guides/install/install-k8s-operator/. Documentation index: [llms.txt](https://tuna.am/en/llms.txt), full text in one file: [llms-full.txt](https://tuna.am/en/llms-full.txt). Any page is available as Markdown: append `.md` to its URL without the trailing slash.

# Installing the Kubernetes operator

The operator publishes cluster Services through Tuna tunnels: tunnels, domains and TCP ports are described as Kubernetes resources. No client is needed on your machines, the operator runs in the cluster itself. This page covers installing and configuring it. Publishing applications is described in [Kubernetes operator](https://tuna.am/en/docs/tunnels/guides/kubernetes-operator.md).

## What you need

* Kubernetes 1.32 or newer;
* [Nelm](https://github.com/werf/nelm) (recommended) or Helm 4;
* an API key with write access to "Endpoints and domains" — see below for how to create it.

## API key for the operator

The operator uses the key to reserve domains and TCP ports and to issue temporary tokens for tunnels. All of this belongs to the "Endpoints and domains" product, so write access to it (the `tunnels:write` scope) is all the key needs.

1. Open [API keys](https://my.tuna.am/api_keys?lang=en) in the dashboard and create a new key.
2. Under "What is the key for", choose "For API".
3. In "Description", name the cluster, for example `k8s-operator prod`. Create a separate key for each cluster: then you can revoke one cluster's access without affecting the others.
4. In "Expiration", choose "Unlimited". The "For API" preset sets 30 days by default, and once the key expires, the operator loses access to the API. If your security policy requires a limited lifetime, keep it, but plan to rotate the key.
5. Under "API access", choose "Selective" and set "Endpoints and domains" to "Write". Leave the other products at "None".
6. Create the key and copy it.

You don't need to turn on "Run tunnels". The operator doesn't connect tunnels with its own key: it issues a separate temporary token for each tunnel.

A key with full API access works too, but it gives the operator access to monitors, secrets and team settings it doesn't need.

## Installation

The [`tuna-k8s-operator`](https://code.tuna.am/tuna/-/packages/helm/tuna-k8s-operator) chart is in the `code.tuna.am` package registry. The examples install the operator into the `tuna-system` namespace and pass the key in the `credentials.apiKey` parameter. Other ways to pass the key are in [Where to keep the key](#api-key-storage).

**Nelm**

Nelm shows the change plan first and then applies it:

```shell
export NELM_FEAT_REMOTE_CHARTS=true
nelm repo add tuna https://code.tuna.am/api/packages/tuna/helm
nelm release plan install -n tuna-system -r tuna-operator tuna/tuna-k8s-operator \
  --set credentials.apiKey=<API key>
nelm release install -n tuna-system -r tuna-operator tuna/tuna-k8s-operator \
  --set credentials.apiKey=<API key>

```

**Helm**

```shell
helm repo add tuna https://code.tuna.am/api/packages/tuna/helm
helm repo update
helm install tuna-operator tuna/tuna-k8s-operator \
  --namespace tuna-system --create-namespace \
  --set credentials.apiKey=<API key>

```

Check that the operator is running:

```shell
kubectl get pods -n tuna-system

```

The namespace runs two pods: `…-agent-manager` handles Tunnel and Ingress, `…-api-manager` handles Domain and TCPEndpoint.

### Where to keep the key

| Parameter                    | How it works                                         | When to choose it                                                                         |
| ---------------------------- | ---------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| `credentials.apiKey`         | the chart creates a Secret with the key              | a trial run, a test cluster                                                               |
| `credentials.existingSecret` | the name of your own Secret with the `api-key` field | the key comes from External Secrets Operator or Sealed Secrets, or you created it by hand |
| `extraEnv`                   | the `TUNA_API_KEY` variable from a secret injector   | no Secret in Kubernetes: the key comes straight from the vault                            |

An `extraEnv` example for [Bank-Vaults](https://bank-vaults.dev):

```yaml
podAnnotations:
  vault.security.banzaicloud.io/vault-addr: https://vault.vault.svc:8200
  vault.security.banzaicloud.io/vault-role: tuna-operator
extraEnv:
  - name: TUNA_API_KEY
    value: vault:secret/data/tuna#TUNA_API_KEY

```

### Chart parameters

`helm show values tuna/tuna-k8s-operator` lists all parameters with descriptions. These are the ones you'll need most often:

| Parameter                             | What it sets                                                                                                                                        |
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `watchNamespace`                      | watch a single namespace; by default the operator watches all of them                                                                               |
| `ingressClass.default`                | make `tuna` the default class for Ingresses without `ingressClassName`                                                                              |
| `agentManager.allowExternalUpstreams` | allow publishing addresses outside the resource's namespace, see [Security](https://tuna.am/en/docs/tunnels/guides/kubernetes-operator.md#security) |
| `apiManager.replicas`                 | the number of api-manager replicas; one is active, the rest are on standby                                                                          |

## Upgrading

**Nelm**

Run the same `nelm release plan install` and `nelm release install` with a new `--chart-version`: CRDs are updated together with the release.

**Helm**

Helm doesn't upgrade CRDs, so apply them before upgrading the chart:

```shell
helm pull tuna/tuna-k8s-operator --untar --version <version>
kubectl apply -f tuna-k8s-operator/crds/
helm upgrade tuna-operator tuna/tuna-k8s-operator --namespace tuna-system --reuse-values --version <version>

```

## Uninstalling

Delete the resources first: Domain and TCPEndpoint have finalizers, and they need a running operator.

```shell
kubectl delete tunnels,domains,tcpendpoints --all --all-namespaces
nelm release uninstall -n tuna-system -r tuna-operator   # or: helm uninstall tuna-operator -n tuna-system
kubectl delete crd tunnels.k8s.tuna.am domains.k8s.tuna.am tcpendpoints.k8s.tuna.am

```
