chore: change how flux is bootstrapped and configured in the cluster, use go-task for utility

This commit is contained in:
SeanOMik 2024-05-03 21:26:26 -04:00
parent 8999d90e00
commit 42b9f3c530
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
10 changed files with 268 additions and 9701 deletions

View File

@ -0,0 +1,22 @@
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
vars:
CLUSTER_SECRET_SOPS_FILE: "{{.CLUSTER_DIR}}/bootstrap/flux/sops-key.sops.yaml"
GITHUB_DEPLOY_KEY_FILE: "{{.CLUSTER_DIR}}/bootstrap/flux/forgejo-deploy-key.sops.yaml"
tasks:
bootstrap:
desc: Bootstrap Flux into a Kubernetes cluster
cmds:
- kubectl apply --server-side --kustomize {{.CLUSTER_DIR}}/bootstrap/flux
- sops --decrypt {{.CLUSTER_SECRET_SOPS_FILE}} | kubectl apply --server-side --filename -z
- sops --decrypt {{.GITHUB_DEPLOY_KEY_FILE}} | kubectl apply --server-side --filename -
- kubectl apply --server-side --kustomize {{.CLUSTER_DIR}}/flux/config
preconditions:
- { msg: "Missing cluster sops key", sh: "gpg -K 687802D4DFD8AA82EA55666CF7DADAC782D7663D" }
reconcile:
desc: Force update Flux to pull in changes from your Git repository
cmd: flux reconcile --namespace flux-system kustomization cluster --with-source

9
Taskfile.yaml Normal file
View File

@ -0,0 +1,9 @@
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
vars:
CLUSTER_DIR: "{{.ROOT_DIR}}/cluster"
includes:
flux: .taskfiles/Flux/Taskfile.yaml

View File

@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/kustomize.toolkit.fluxcd.io/kustomization_v1.json
apiVersion: kustomize.toolkit.fluxcd.io/v1 apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization kind: Kustomization
metadata: metadata:
@ -10,12 +11,13 @@ spec:
prune: true prune: true
sourceRef: sourceRef:
kind: GitRepository kind: GitRepository
name: flux-system name: home-cluster
decryption: decryption:
provider: sops provider: sops
secretRef: secretRef:
name: sops-gpg name: sops-gpg
--- ---
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/kustomize.toolkit.fluxcd.io/kustomization_v1.json
apiVersion: kustomize.toolkit.fluxcd.io/v1 apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization kind: Kustomization
metadata: metadata:
@ -28,8 +30,9 @@ spec:
prune: true prune: true
sourceRef: sourceRef:
kind: GitRepository kind: GitRepository
name: flux-system name: home-cluster
--- ---
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/kustomize.toolkit.fluxcd.io/kustomization_v1.json
apiVersion: kustomize.toolkit.fluxcd.io/v1 apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization kind: Kustomization
metadata: metadata:
@ -45,7 +48,7 @@ spec:
prune: true prune: true
sourceRef: sourceRef:
kind: GitRepository kind: GitRepository
name: flux-system name: home-cluster
decryption: decryption:
provider: sops provider: sops
secretRef: secretRef:
@ -58,6 +61,7 @@ spec:
- kind: Secret - kind: Secret
name: cluster-secrets name: cluster-secrets
--- ---
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/kustomize.toolkit.fluxcd.io/kustomization_v1.json
apiVersion: kustomize.toolkit.fluxcd.io/v1 apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization kind: Kustomization
metadata: metadata:
@ -73,7 +77,7 @@ spec:
prune: true prune: true
sourceRef: sourceRef:
kind: GitRepository kind: GitRepository
name: flux-system name: home-cluster
decryption: decryption:
provider: sops provider: sops
secretRef: secretRef:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,76 @@
apiVersion: v1
kind: Secret
metadata:
name: forgejo-deploy-key
namespace: flux-system
type: Opaque
stringData:
identity: ENC[AES256_GCM,data:vqTgMRcQehWBwW/PCA3eyMLrloMbEQgV4gDcNNGoumvVoAA7v7sSJvRhfajNx2hLhmIF+82TkeJBIJGuFQp+Kw9tvNAWXXu3pDmWN0ZlaOcIXnd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A==,type:str]
password: ENC[AES256_GCM,data:YNLtVulYnGMU9BlvvcX0hOt4jFItG3c1mWLh6q/57eRu3OWf7qdLFQ==,iv:hBIDKXVgJ68rA15+8MfeTasFTU6NSS//A10oh5SdO94=,tag:KgxbhN62bRVmmdM8XnvuEg==,type:str]
username: ENC[AES256_GCM,data:xmPA,iv:hrlDr7O4sDwc5GMgkxvbPyNzAEpElLQlaATbHL7wST8=,tag:1xEgwqaiJXe/lxO59Q6vDg==,type:str]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age: []
lastmodified: "2024-05-04T01:22:43Z"
mac: ENC[AES256_GCM,data:S4+5EPXeqFFBEXoF9Y7doWRe+JBBhDeFMX6KrVnQNAxfpZBr4IQvAgrpOMRtWqbOHBrUoZZjq7E8ZFpGuklnqmI2q1jUdkO+xSlE2sP3dC6E+lEPTdBM5yi9lITv3edAQTdgaNckb092QcmTmHH0ENxTrO/a8YHNH4wJUeOXHx4=,iv:Uea9NRXFe31o+AySqHKuzMJgDt0roM/Ult1kipvzw3c=,tag:iQA+5q/CZirZOblntQ+AmA==,type:str]
pgp:
- created_at: "2024-05-04T01:22:43Z"
enc: |-
-----BEGIN PGP MESSAGE-----
hQIMAyqlIeyoxYovARAA1BJyf5s6fto5y6EcsQ1G/ZicV4bbLZxhGDC5oRCP2xXC
541Zdp6kqEhLKyh8vZ8r8CF0C/sB4jY52aHR/FEwqu5VUERWOPO6kk5dvD7eUzgv
lVqaCvuoNkAb0FjQg6cSAMau+cHDYp3EqE1fW1HbfY/2AoqE4hs9az6yhne6b30y
SJ6H8k6fWGZ3K/inEQ/rcew6FTjxHcKx+dmbx6wY6y6lvoet38Zd2Mki4OqPI/57
tQj+YqFud/UsuGm3PhuTlkJQI+hO+Re+3O+UEUQ7itO7tPOEgEZ3w1Y8ll6Tuauj
QslcToqGeTEfswATeEX8CR/oaU9Jaoh2JZSSQg84I/et7H72Banegy5qdg0R+zdb
HH3BRWt96fqV1sH46LTl4f6cfgucZpf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-----END PGP MESSAGE-----
fp: 687802D4DFD8AA82EA55666CF7DADAC782D7663D
encrypted_regex: ^(data|stringData)$
version: 3.8.1

View File

@ -0,0 +1,52 @@
# IMPORTANT: This file is not tracked by flux and should never be. Its
# purpose is to only install the Flux components & CRDs into your cluster.
---
# yaml-language-server: $schema=https://json.schemastore.org/kustomization
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- github.com/fluxcd/flux2/manifests/install?ref=v2.2.3
patches:
# Resources renamed to match those installed by oci://ghcr.io/fluxcd/flux-manifests
- target:
kind: ResourceQuota
name: critical-pods
patch: |
- op: replace
path: /metadata/name
value: critical-pods-flux-system
- target:
kind: ClusterRoleBinding
name: cluster-reconciler
patch: |
- op: replace
path: /metadata/name
value: cluster-reconciler-flux-system
- target:
kind: ClusterRoleBinding
name: crd-controller
patch: |
- op: replace
path: /metadata/name
value: crd-controller-flux-system
- target:
kind: ClusterRole
name: crd-controller
patch: |
- op: replace
path: /metadata/name
value: crd-controller-flux-system
- target:
kind: ClusterRole
name: flux-edit
patch: |
- op: replace
path: /metadata/name
value: flux-edit-flux-system
- target:
kind: ClusterRole
name: flux-view
patch: |
- op: replace
path: /metadata/name
value: flux-view-flux-system

File diff suppressed because one or more lines are too long

View File

@ -1,30 +1,31 @@
# This manifest was generated by flux. DO NOT EDIT.
--- ---
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/source.toolkit.fluxcd.io/gitrepository_v1.json
apiVersion: source.toolkit.fluxcd.io/v1 apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository kind: GitRepository
metadata: metadata:
name: flux-system name: home-cluster
namespace: flux-system namespace: flux-system
spec: spec:
interval: 1m0s interval: 1m0s
ref: ref:
branch: main branch: main
secretRef: secretRef:
name: flux-system name: forgejo-deploy-key
url: ssh://git@git.seanomik.net/seanomik/k3s-cluster url: ssh://git@git.seanomik.net/seanomik/k3s-cluster
--- ---
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/kustomize.toolkit.fluxcd.io/kustomization_v1.json
apiVersion: kustomize.toolkit.fluxcd.io/v1 apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization kind: Kustomization
metadata: metadata:
name: flux-system name: cluster
namespace: flux-system namespace: flux-system
spec: spec:
interval: 10m0s interval: 10m0s
path: ./cluster/base path: ./cluster/base.yaml
prune: true prune: true
sourceRef: sourceRef:
kind: GitRepository kind: GitRepository
name: flux-system name: home-cluster
# Support decryption # Support decryption
decryption: decryption:
provider: sops provider: sops

View File

@ -1,5 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1 apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
resources: resources:
- ./gotk-components.yaml - ./cluster.yaml
- ./gotk-sync.yaml

View File

@ -1,15 +1,28 @@
# Cluster Setup # Cluster Setup
This document goes over the process of installing the GitOps files into a cluster This document goes over the process of installing the GitOps files into a cluster
1. Install [cilium](https://docs.cilium.io/en/stable/gettingstarted/k8s-install-default/#install-the-cilium-cli) in the cluster
2. Install the [Flux CLI](https://fluxcd.io/flux/installation/#install-the-flux-cli)
3. Install [go-task](https://taskfile.dev/installation/)
4. Ensure you have a kubeconfig at `$HOME/.kube/config` and that you have the cluster sops GPG key imported.
5. Bootstrap flux
```sh
task flux:bootstrap
# namespace/flux-system configured
# customresourcedefinition.apiextensions.k8s.io/alerts.notification.toolkit.fluxcd.io created
# ...
```
6. Verify Flux components are running in the cluster
Install [cilium](https://docs.cilium.io/en/stable/gettingstarted/k8s-install-default/#install-the-cilium-cli) ```sh
kubectl -n flux-system get pods -o wide
Now install the FluxCD stuff:\ # NAME READY STATUS RESTARTS AGE
https://github.com/larivierec/home-cluster#installation # helm-controller-5bbd94c75-89sb4 1/1 Running 0 1h
# kustomize-controller-7b67b6b77d-nqc67 1/1 Running 0 1h
1. Bootstrap FluxCD, this will likely fail # notification-controller-7c46575844-k4bvr 1/1 Running 0 1h
2. After it fails, create the sops secret in the `flux-system` namespace # source-controller-7d6875bcb4-zqw9f 1/1 Running 0 1h
3. Now trigger a reconcilation, or resume the fluxcd bootstrap ```
7. After a while all the services should start to come up
# Uninstalling and removing all k3s data in NixOS # Uninstalling and removing all k3s data in NixOS
```shell ```shell