# Install and upgrade

> Get access to the Kavach Enterprise image and manifests, pin a version, install the operator, check it works, and upgrade or roll back safely.

## Get access

Kavach Enterprise is not open source. With access, you get:

- pull access to the image `ghcr.io/kavachlabs/kavach-daemon`, private on the GitHub Container Registry;
- the Kubernetes manifests for that release: `crds.yaml`, `operator-deployment.yaml` and the reference sidecar `shadow-healer-sidecar.yaml`.

To get access, write to hello@thekavachlabs.com.

## Choose a version

Each release publishes one multi-arch image (`linux/amd64`, `linux/arm64`) under several tags:

| Tag | Example | Use |
| --- | --- | --- |
| `X.Y.Z` | `0.1.1` | **Production.** Never changes. |
| `X.Y` | `0.1` | Takes patch releases within a minor version. |
| `sha-<commit>` | `sha-43c3884` | One exact build. |
| `latest` | | The newest release. Moves with every release, so use it for trials only. |

Pin `X.Y.Z` in production, or better, the image digest (`kavach-daemon@sha256:…`). The reference manifests use `latest`, and `ProtectedService.spec.daemonImage` defaults to it; set both before you go to production. The image includes the open-source `kavach` CLI at a fixed commit, so a pinned image also pins the CLI the daemon replays with.

Before 1.0, a minor version may change custom resource fields and flags. Read the release notes before moving from one minor version to the next.

## Let the cluster pull the image

Create a pull secret in each namespace that runs the daemon or the operator, using the registry credentials you were given:

```bash
kubectl create secret docker-registry kavach-registry \
  --namespace payments \
  --docker-server=ghcr.io \
  --docker-username=<username> \
  --docker-password="$(cat registry-token.txt)"
```

Then attach it to the service account the pods run as. This covers the sidecars the operator creates, which run as the `ProtectedService`'s `serviceAccountName`:

```bash
kubectl patch serviceaccount payments -n payments \
  -p '{"imagePullSecrets": [{"name": "kavach-registry"}]}'
```

For pods you write yourself, you can instead list it under `spec.imagePullSecrets`.

## Install the operator

The operator is namespaced: it manages `ProtectedService`, `HealingPolicy` and `QuarantineDrain` resources in the namespace it runs in, with a `Role` limited to that namespace. Install one per namespace you want protected.

1. Install the custom resource definitions, once per cluster:

   ```bash
   kubectl apply -f crds.yaml
   kubectl get crd | grep kavach.dev
   ```

   You should see `protectedservices.kavach.dev`, `healingpolicies.kavach.dev` and `quarantinedrains.kavach.dev`.

2. Set the image tag in `operator-deployment.yaml`, add the pull secret, then apply it to the namespace:

   ```bash
   kubectl apply -n payments -f operator-deployment.yaml
   kubectl rollout status -n payments deployment/kavach-operator
   ```

   This creates the operator's service account, its `Role` and `RoleBinding`, two network policies (deny everything, then allow egress on DNS and on ports 443 and 6443 only), and the deployment.

3. Check the storage the services will use, from inside the cluster:

   ```bash
   kubectl run kavach-probe -n payments --rm -it --restart=Never \
     --image=ghcr.io/kavachlabs/kavach-daemon:<version> \
     --overrides='{"spec":{"imagePullSecrets":[{"name":"kavach-registry"}]}}' \
     -- --diagnose-storage s3://acme-kavach/payments --region us-east-1
   ```

4. Create a `HealingPolicy` and a `ProtectedService`, as in [Deploy](https://www.thekavachlabs.com/docs/enterprise/deployment#operator), and check the operator accepted them:

   ```bash
   kubectl get protectedservices -n payments
   kubectl describe protectedservice payments -n payments
   ```

To see what the operator would create without changing anything, run it once with `--reconcile-operator --dry-run --once`: it prints the manifests.

## Without the operator

Use the reference `shadow-healer-sidecar.yaml` as a starting point: set the image tag, the bucket, the service's two builds and the pull secret, and add the containers to your own deployment. See [Sidecar](https://www.thekavachlabs.com/docs/enterprise/deployment#sidecar).

## Upgrade

1. Read the release notes for every version between yours and the target.
2. If the release changes the custom resource definitions, apply its `crds.yaml` first. CRDs are cluster-wide, so this affects every namespace.
3. Change the image tag (or digest) in the operator deployment, in `spec.daemonImage` of each `ProtectedService`, and in sidecars you manage yourself. The operator rolls out the sidecars it manages when `daemonImage` changes.
4. Watch the rollout: `kubectl rollout status`, then `/readyz` on the new pods. A daemon that cannot verify its storage never becomes ready, so a bad upgrade stops at the first pod.

The daemon finishes its current pass on `SIGTERM` and exits, so a normal rolling update is safe. Keep the default `terminationGracePeriodSeconds` (30 seconds) or longer.

The release notes say if a version changes the format of anything in your bucket. Run `kavach-daemon --verify-audit` after the upgrade to confirm the audit trail still verifies.

## Roll back

Set the image back to the previous tag or digest and roll out again:

```bash
kubectl rollout undo -n payments deployment/kavach-operator
```

If the upgrade also applied a newer `crds.yaml`, roll back the image first, then reapply the old `crds.yaml` only if the release notes say the new one is not backwards compatible. Run `kavach-daemon --verify-audit` after a rollback to confirm the audit trail is intact.

## Uninstall

```bash
kubectl delete -n payments protectedservices --all
kubectl delete -n payments -f operator-deployment.yaml
kubectl delete -f crds.yaml   # last namespace only: deletes every Kavach resource in the cluster
```

Your bucket is not touched. Delete it, or the Kavach prefixes in it, separately if you no longer need the incident history and audit trail.

Source: https://www.thekavachlabs.com/docs/enterprise/install
