# Install on Kubernetes

> Install Corfedo on a Kubernetes cluster with the Helm chart, from the Secrets and the values file to the setup Job and the setup page.

Source: https://docs.corfedo.ai/operate/kubernetes/

Install Corfedo on a Kubernetes cluster with its Helm chart. To run Corfedo on one machine, [install on a single host](https://docs.corfedo.ai/operate/single-host/).

## Before you begin

- A cluster [prepared for Corfedo](https://docs.corfedo.ai/operate/kubernetes/prepare-the-cluster/).
- `kubectl` and Helm on your machine.
- A host name for Corfedo, such as `corfedo.example.com`.
- Your organization's identity provider. The setup page shows the callback address to register there.

## Create the Secrets

Create these Secrets in the release's namespace before you install. Their names start with the release name, here `corfedo`.

| Secret | Holds | Comes from |
| --- | --- | --- |
| `corfedo-database` | The passwords of the six database logins, one key per login | The passwords you set in PostgreSQL |
| `corfedo-storage`, `corfedo-search-storage`, `corfedo-indexer-storage` | The bucket's access key for the platform roles, the search nodes and the indexers, as `credentials.json` | Your object storage |

The trust bundle is a ConfigMap with the workload issuer's CA certificate, as `ca.crt`.

Run the commands in a new directory that only you can read. Each file has the name of its key.

```sh
kubectl create namespace corfedo

# One file per login with the password you set in PostgreSQL:
# migrator, runtime, authentication, issuer, validation, webhooks
kubectl create secret generic corfedo-database --namespace corfedo \
  --from-file=migrator --from-file=runtime --from-file=authentication \
  --from-file=issuer --from-file=validation --from-file=webhooks

# credentials.json: {"access_key": "...", "secret_key": "..."}
for name in corfedo-storage corfedo-search-storage corfedo-indexer-storage; do
  kubectl create secret generic "$name" --namespace corfedo --from-file=credentials.json
done

kubectl create configmap corfedo-workload-trust --namespace corfedo --from-file=ca.crt
```

Then remove the directory.

### Keys and the setup secret

The install creates three more Secrets with random values unless they exist: `corfedo-keys` encrypts the credentials saved in **Settings**, `corfedo-oauth` signs the clients' access tokens and `corfedo-setup` holds the setup secret. `helm uninstall` keeps them. [Back them up](https://docs.corfedo.ai/operate/kubernetes/backup-and-recovery/) with the database.

To use your own Secrets, name them in the values file, both OAuth values together. Corfedo never changes them. A rendering without hooks, such as `helm template --no-hooks` or `helm template | kubectl apply`, names all three.

```yaml
secrets:
  keyDirectory: {name: acme-keys}
  oauth:
    keySet: {name: acme-oauth}
    verificationKeySet: {name: acme-oauth}
  setup: {name: acme-setup}
```

**Create your own keys and setup secret**

With Docker, the platform image creates them as files. Run the commands in a new directory that only you can read, then remove it.

```sh
image=ghcr.io/corfedo/corfedo-platform:PLATFORM_VERSION
docker run --rm --network none --user "$(id -u):$(id -g)" --volume "$PWD:/out" "$image" \
  installation-secrets generate --output /out
kubectl create secret generic acme-keys --namespace corfedo --from-file=keys/
kubectl create secret generic acme-oauth --namespace corfedo --from-file=oauth/
kubectl create secret generic acme-setup --namespace corfedo --from-file=setup-secret
```

## Write the values file

Save this as `values.yaml` and replace the example values. `helm show values` prints every value with its description.

```yaml
# The platform and engine images of the release you install.
image:
  platform:
    repository: ghcr.io/corfedo/corfedo-platform
    tag: PLATFORM_VERSION
  engine:
    repository: ghcr.io/corfedo/corfedo-search
    tag: ENGINE_VERSION

hosting:
  # One workspace at one address.
  mode: SingleTenant
  publicOrigin: https://corfedo.example.com/
  # The network the ingress controller's pods forward requests from.
  trustedProxies: [10.42.0.0/16]

database:
  host: postgres.example.com
  # The server's max_connections.
  maxConnections: 700

storage:
  s3:
    # An empty bucket that no other installation uses.
    # To share a bucket, set prefix to an empty prefix for this installation.
    bucket: corfedo-example
    region: eu-central-1
    # For an S3-compatible service other than AWS:
    # serviceUrl: https://objects.example.com
    # forcePathStyle: true
  # The GiB of the bucket that indexes may use, 16 or more.
  budgetGiB: 100

ingress:
  enabled: true
  className: nginx
  # The HTTPS certificate, see below.

networkPolicy:
  # The pods that may send public requests to Corfedo: your ingress controller's.
  ingressFrom:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: ingress-nginx
      podSelector:
        matchLabels:
          app.kubernetes.io/name: ingress-nginx

workload:
  # A name for the identities in this installation's workload certificates.
  trustDomain: corfedo.example.com
  # The issuer of the workload certificates and the ConfigMap with its CA certificate.
  issuerRef: {name: corfedo-workload, kind: ClusterIssuer}
  trustBundle: {name: corfedo-workload-trust}

# The volume of each search node and of each indexer.
search:
  volume:
    size: 8Gi
indexer:
  volume:
    size: 20Gi
```

Then add the values for the host name's certificate from [HTTPS certificate](https://docs.corfedo.ai/operate/kubernetes/routing/#https-certificate).

## Install

```sh
helm install corfedo oci://ghcr.io/corfedo/charts/corfedo --version CHART_VERSION \
  --namespace corfedo --values values.yaml
```

`helm install` stops with a message when a required value is missing or `database.maxConnections` is too low for the replicas, see [PostgreSQL](https://docs.corfedo.ai/operate/kubernetes/prepare-the-cluster/#postgresql).

## Check the result

The setup Job prepares the database and the bucket. The other pods restart until it has completed. The installation is complete when every workload is ready too.

```sh
kubectl wait job --namespace corfedo \
  --selector app.kubernetes.io/instance=corfedo,corfedo.ai/job=setup \
  --for=condition=complete --timeout=15m
kubectl rollout status deployment,statefulset --namespace corfedo \
  --selector app.kubernetes.io/instance=corfedo --timeout=15m
kubectl get pods --namespace corfedo
```

Every pod is `Running` and ready, and the setup pod is `Completed`. For a pod that stays in `ContainerCreating`, the events at the end of `kubectl describe pod` name what it waits for. For its workload certificate, `kubectl get certificaterequest --namespace corfedo` shows whether the request was denied.

When the setup pod fails at the storage step, these logs say why, with `--previous` after a restart.

```sh
kubectl logs --namespace corfedo -c artifact-storage-configure \
  --selector app.kubernetes.io/instance=corfedo,app.kubernetes.io/component=setup
```

| What you see | Why | What to do |
| --- | --- | --- |
| `… is not empty and has no marker` | The bucket or prefix holds other objects | Use an empty one |
| `The storage holds the marker of another installation` | It is another installation's storage | Use an unused bucket or prefix |
| `… lies inside the storage at …` | The prefix is inside another installation's storage | Use a prefix outside it |
| `Shared storage refused the request (403 …)` | The platform's key lacks a right, often the bucket listing | Grant the rights of [Object storage](https://docs.corfedo.ai/operate/kubernetes/prepare-the-cluster/#object-storage) |

## Evaluate without your own database and identity provider

`postgresql.enabled` and `keycloak.enabled` add a PostgreSQL server and Keycloak as the account service to the release, each one instance without replication or backup, for evaluation only. `helm show values` describes their Secrets and values. With `postgresql.enabled`, remove `database.host`.

## Next step

Follow [Set up your workspace](https://docs.corfedo.ai/get-started/workspace/) at `https://corfedo.example.com/setup`. Under **Sign-in connection**, enter your identity provider's application as [Sign-in](https://docs.corfedo.ai/workspace/members/sign-in/#add-a-connection) describes. This command prints the setup secret. With your own setup Secret, use its name and key:

```sh
kubectl get secret corfedo-setup --namespace corfedo -o jsonpath='{.data.setup-secret}' | base64 -d
```
