# Deploy from git with Flux

The flux add-on keeps a cluster in step with a branch of your {{product}} git repository, over a deploy key {{product}} manages.

Replace _my-cluster_ with your cluster's name or id and _platform-config_ with one of your git
repositories.

The `flux` add-on runs Flux's source, kustomize and helm controllers. Each repository in its
options becomes a GitRepository (the branch, fetched over SSH) and a Kustomization of one path in
it: Flux applies what is there every interval, and with `prune` it deletes what you remove from
the repository. A path holds plain manifests or a `kustomization.yaml`; HelmReleases work too.

- **No key to manage.** When you install the add-on, Deutsche Cloud registers a read-only deploy key
  `eks-flux-<cluster id>` on each listed repository and gives the cluster its private half. It is
  deleted when you remove the repository from the options, remove the add-on or delete the
  cluster.
- **Who controls the cluster.** Flux applies the branch with cluster-admin rights: whoever can
  push to it controls the cluster. Protect the branch (pull requests, reviews) as you would the
  cluster's admin access.

## Prerequisites

- Permission for `eks:CreateAddon` on the cluster and `git:CreateDeployKey` on each repository. In
  the console, also `eks:DescribeCluster` to open the cluster.

## Install the add-on

**Console**
1. Open **Kubernetes**, open the cluster, then choose **Add-ons**.
2. Choose **Add an add-on**, then **GitOps (Flux)**.
3. Choose the repository, and the branch and path if they are not `main` and the root.
4. Choose **Install**.

**CLI**
```sh
dcloud eks addons create my-cluster --name flux --config 'repositories=[{"repository":"platform-config","path":"./clusters/prod"}]'
```

**API**
```http
POST /eks/api/clusters/my-cluster/addons
{ "name": "flux", "config": { "repositories": [{ "repository": "platform-config", "path": "./clusters/prod" }] } }
```

**Terraform**
```hcl
resource "dcloud_eks_addon" "flux" {
  cluster_id = dcloud_eks_cluster.main.id
  name       = "flux"
  config = jsonencode({
    repositories = [{ repository = "platform-config", path = "./clusters/prod" }]
  })
}
```

## See what it applied

```sh
kubectl -n flux-system get gitrepositories,kustomizations
```

`READY True` with the commit it applied; a failing apply names the object and the error. The
deploy key is listed under the repository's **Settings › Deploy keys**.
