# Install Zeabur Identity on an existing cluster

> Install Zeabur Identity on an existing Kubernetes cluster, configure kube-apiserver authentication, and sign in as the first admin.

Use a cluster admin's kubeconfig to install Zeabur Identity, then configure kube-apiserver authentication. After setup, you sign in from the browser and `kubectl` obtains short-lived tokens.

## Before you begin

- Prepare a kubeconfig with `cluster-admin` permissions.
- Install [cert-manager](https://cert-manager.io/docs/installation/kubectl/). `kube-config` uses it to issue the internal certificate that kube-apiserver uses to reach Zeabur Identity. Without cert-manager, pass `--discovery public`, or the command fails.
- Prepare a reachable HTTPS Issuer URL. Your browser must trust the URL's HTTPS certificate to create a passkey.
- Confirm that you retain [access without Zeabur Identity](https://oss.zeabur.com/docs/identity/operations/emergency-access): an admin kubeconfig that uses client certificates, and SSH or console access to every control plane node.
- Record how kube-apiserver currently starts and its authentication settings, and back up the configuration files. When using `generic`, also confirm how to restore the configuration without access to the Kubernetes API.

> Keep the admin kubeconfig and store an encrypted copy outside the cluster. Even after you confirm that sign-in works, don't delete your only emergency access path.

### Download and verify the release

Follow [Releases and verification](https://oss.zeabur.com/docs/identity/reference/releases) to download and verify Zeabur Identity, prepare `zeabur-identityctl`, and set `ZEABUR_IDENTITY_IMAGE` as described on that page.

### Install the CRDs and manifests

Run these commands with a kubeconfig that has `cluster-admin` permissions:

```sh
export ZEABUR_IDENTITY_ISSUER=https://login.example.com
zeabur-identityctl crds | kubectl apply --server-side -f -
zeabur-identityctl manifests --image "$ZEABUR_IDENTITY_IMAGE" --serve-arg=--invitations | kubectl apply --server-side -f -
kubectl -n zeabur-identity rollout status deploy/zeabur-identity --timeout=180s
```

The last command prints `deployment "zeabur-identity" successfully rolled out`. Replace `https://login.example.com` with your HTTPS Issuer URL and confirm that the URL is reachable.

`--serve-arg=--invitations` enables invitations. Without it, users can't redeem invitation links generated by `invite`.

### Configure kube-apiserver authentication

Choose `--distro k3s` or `--distro generic` for your cluster.

#### k3s and RKE2

Generate the configuration file:

```sh
zeabur-identityctl kube-config --distro k3s > authn.yaml
```

The command prints installation steps. Follow the output to install the configuration, then restart `k3s` or `rke2-server` once. When you make valid changes to `authn.yaml` afterward, kube-apiserver reloads the file within about a minute.

On RKE2, create `/etc/rancher/rke2/zeabur-identity/` and save `authn.yaml` there on every server before you restart `rke2-server`. RKE2 mounts only files that exist.

#### Other clusters

Generate the configuration file:

```sh
zeabur-identityctl kube-config --distro generic > authn.yaml
```

`generic` outputs only the authentication configuration file. Pass the file to `--authentication-config` according to how your cluster starts kube-apiserver. For managed Kubernetes clusters, use an authentication configuration method that your provider supports.

#### Checks before applying

- If the cluster already has authentication settings for other Issuers, merge Zeabur Identity's `jwt` entry into the existing file. Don't overwrite the entire configuration.
- You can't use `--authentication-config` and `--oidc-*` flags together.
- If the authentication configuration file contains an `anonymous` section, kube-apiserver can't also use the `--anonymous-auth` flag. The `k3s` output sets `anonymous.enabled: false`; you must configure anonymous access yourself for `generic`.
- `--discovery internal` is the default. If you switch to `--discovery public`, control plane nodes must be able to reach the public Issuer and trust its HTTPS certificate.
- `--audience` defaults to `kubernetes`, and `--max-token-lifetime` defaults to `1h`.

### Create the first admin

Generate a one-time setup link:

```sh
zeabur-identityctl setup-link --username admin
```

Open the link in a browser and select **Create passkey**, or **Use a password** to set a password and an authenticator app. Then check that the admin has a sign-in method. The output lists one `Credential` with `admin` in the `USER` column:

```sh
kubectl -n zeabur-identity get credentials
```

`--username` defaults to `admin`, and `--valid-for` defaults to `60m`.

> `--reset` deletes the user's passkeys, password, linked accounts and sessions. Don't use it to troubleshoot Pod, Ingress, or kube-apiserver failures.

### Register the kubectl client and configure kubeconfig

Follow steps 6 through 8 in [Install and sign in on k3s](https://oss.zeabur.com/docs/identity/get-started/quickstart) to register the `kubectl` client, configure kubeconfig on your computer, and sign in with the admin account you created.

## Verify the results

Run these commands with the kubeconfig you configured:

```sh
kubectl auth whoami
kubectl auth can-i '*' '*' --all-namespaces
```

The username should be `zeabur:admin`, and the permission check should return `yes`.

## Troubleshooting

| Symptom or result | Next action |
| - | - |
| The browser can't create a passkey | Confirm that the Issuer URL is reachable and that your browser trusts its HTTPS certificate. |
| Sign-in returns `oidc: authenticator not initialized` just after kube-apiserver restarts | Wait a few minutes for kube-apiserver to retrieve Zeabur Identity's keys. If the failure persists, check the kube-apiserver logs, the `zeabur-identity` Service's endpoints, and the internal certificate. Don't disable certificate verification. |
| kube-apiserver won't start | Use [access without Zeabur Identity](https://oss.zeabur.com/docs/identity/operations/emergency-access) to restore the previous authentication and anonymous access settings on the control plane node. |
| Users can't redeem invitation links | Confirm that the server starts with `--invitations`. |
