Skip to content

Instantly share code, notes, and snippets.

@richardcase
Last active April 30, 2023 17:58
Show Gist options
  • Save richardcase/8ea3c2a72675c9301673b784b1f3f087 to your computer and use it in GitHub Desktop.
Save richardcase/8ea3c2a72675c9301673b784b1f3f087 to your computer and use it in GitHub Desktop.
You will need the kubeconfig for the management cluster
and either export KUBECONFIG=mgmt.kubeconfig or add --kubeconfig mgmt.kubeconfig to the commands below
1. Clone the Flux2 state repo
2. Run the following to get the Flux2 install manifest
```bash
flux install --export > flux-components.yaml
```
3. And apply to your management cluster:
```bash
kubectl apply -f flux-components.yaml
```
4. Get the public and private deploy key files for the state repo (keys called fluxdeploy below)
5. Set the SSH key for GitHub:
```bash
export GH_SSH=$(ssh-keyscan github.com)
```
6. Create the secret in the management cluster for syncing flux:
```bash
kubectl create secret generic flux-system --from-file=identity=./fluxdeploy --from-file=identity.pub=./fluxdeploy.pub --from-literal=known_hosts=$GH_SSH --namespace flux-system
```
7. Create a Git repo source for Flux2 and apply to management cluster:
```bash
flux create source git flux-system --url=ssh://[email protected]/wkp-capi-demo/platform-cluster-management.git --branch main --secret-ref flux-system --export > flux-source.yaml
kubectl apply -f flux-source.yaml
```
8. Create a kustomization to sync the management cluster definitions (including flux-system) and apply:
``bash
flux create kustomization flux-system --source=flux-system --prune=true --interval=10m --path="./clusters/mgmt01" --validation=client --export > flux-kustomization.yaml
kubectl apply -f flux-kustomization.yaml
9. Create a folder called **flux-system** in clusters/mgmt01 and add the following files to it:
- flux-components.yaml
- flux-source.yaml
- flux-kustomization.yaml
10. In the same **flux-system** folder create a file called **kustomization.yaml** and add the following contents:
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- flux-components.yaml
- flux-source.yaml
- flux-kustomization.yaml
```
11. Commit these 4 files to the state repo and push the changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment