From 4fa8ab3d16997e106428e4ff4e179cbd40e29ff4 Mon Sep 17 00:00:00 2001 From: charles Date: Mon, 27 Apr 2026 23:27:04 -0700 Subject: [PATCH] add: simple flux --- .obsidian/workspace.json | 19 ++--- Simple Flux.md | 152 +++++++++++++++++++++++++++++++++++++++ infra.md | 4 ++ 3 files changed, 166 insertions(+), 9 deletions(-) create mode 100644 Simple Flux.md diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 04361bf..e97e9c5 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -13,12 +13,12 @@ "state": { "type": "markdown", "state": { - "file": "README.md", + "file": "infra.md", "mode": "source", "source": false }, "icon": "lucide-file", - "title": "README" + "title": "infra" } }, { @@ -41,12 +41,12 @@ "state": { "type": "markdown", "state": { - "file": "Games.md", + "file": "Simple Flux.md", "mode": "source", "source": false }, "icon": "lucide-file", - "title": "Games" + "title": "Simple Flux" } } ], @@ -142,12 +142,12 @@ "state": { "type": "outgoing-link", "state": { - "file": "Games.md", + "file": "Simple Flux.md", "linksCollapsed": false, "unlinkedCollapsed": true }, "icon": "links-going-out", - "title": "Outgoing links from Games" + "title": "Outgoing links from Simple Flux" } }, { @@ -214,11 +214,12 @@ }, "active": "a0cc81e9a0ac6335", "lastOpenFiles": [ - "README.md", - "thoughts.md", - "Games.md", "infra.md", + "README.md", "learning ai.md", + "Simple Flux.md", + "Games.md", + "thoughts.md", "rikidown.md", "skubelb.md", "valheim.md", diff --git a/Simple Flux.md b/Simple Flux.md new file mode 100644 index 0000000..642b211 --- /dev/null +++ b/Simple Flux.md @@ -0,0 +1,152 @@ +The Flux tutorial makes things very complicated. In essence, all Flux is is a tool that pulls a git repo, and does `kubectl apply -k`; there should be a much easier way to set it up. +## Install Flux +Export your GITEA_TOKEN: +``` +export GITEA_TOKEN=THERE_IS_SOME_TOKEN_HERE +``` +Bootstrap the repo: +``` +❯ flux bootstrap gitea \ +--token-auth=true \ +--owner=charles \ +--repository=flux-5pi5 \ +--branch=main \ +--path=./ \ +--personal \ +--hostname=git.tipsy.codes +``` + +This will create the repo in Gitea for you, and define a basic structure: + +``` +❯ tree +. +└── cluster +   └── flux-system +       ├── gotk-components.yaml +       ├── gotk-sync.yaml +       └── kustomization.yaml +``` + +From here, in the simplest way, you can just start deploying applications. +## First deployment +In the most simple form, any kustomization in the path pointed to by '--path' will be picked up. Since we set it to '.', adding something should be as simple as dropping it into that folder. + +``` +❯ git clone ssh://git@git.tipsy.codes:2222/charles/flux-5pi5.git +❯ cd flux-5pi5 +❯ cat < nginx.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + namespace: default +spec: + selector: +   matchLabels: +     app: nginx + replicas: 2 # tells deployment to run 2 pods matching the template + template: +   metadata: +     labels: +       app: nginx +   spec: +     containers: +       - name: nginx +         image: nginx:1.14.2 +         ports: +           - containerPort: 80 +EOF +``` + +Then commit, push, and reconcile: +``` +❯ git add . +❯ git commit -am 'add: nginx deployment' +[main e1e40fb] add: nginx deployment +1 file changed, 19 insertions(+) +create mode 100644 nginx.yaml +❯ git push +** WARNING: connection is not using a post-quantum key exchange algorithm. +** This session may be vulnerable to "store now, decrypt later" attacks. +** The server may need to be upgraded. See https://openssh.com/pq.html +Enumerating objects: 4, done. +Counting objects: 100% (4/4), done. +Delta compression using up to 20 threads +Compressing objects: 100% (3/3), done. +Writing objects: 100% (3/3), 478 bytes | 478.00 KiB/s, done. +Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) +remote: . Processing 1 references +remote: Processed 1 references in total +To ssh://git.tipsy.codes:2222/charles/flux-5pi5.git +  43161d8..e1e40fb  main -> main +``` + +If you are impatient, you can trigger a reconciliation with: +``` +flux reconcile source git flux-system +``` +Watch it rollout with: +``` +watch flux get all -A +``` +Then you should be good to go! +``` +❯ kubectl get pods +NAME                                READY   STATUS    RESTARTS   AGE +nginx-deployment-647677fc66-cltgn   1/1     Running   0          6m31s +nginx-deployment-647677fc66-r6lxj   1/1     Running   0          6m31s +``` +## Some simple things to make it better +### Use kustomizations +If we use kustomizations, we can track the reconciliation of sets of things. + +Here is a simple example: +``` +❯ head -n 99999 nginx.yaml nginx/* +==> nginx.yaml <== +apiVersion: kustomize.toolkit.fluxcd.io/v1 +kind: Kustomization +metadata: + name: nginx-kustomization + namespace: flux-system +spec: + interval: 10m + path: "./nginx" + prune: true + sourceRef: +   kind: GitRepository +   name: flux-system + targetNamespace: default + wait: true + +==> nginx/deployment.yaml <== +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + namespace: default +spec: + selector: +   matchLabels: +     app: nginx + replicas: 2 # tells deployment to run 2 pods matching the template + template: +   metadata: +     labels: +       app: nginx +   spec: +     containers: +       - name: nginx +         image: nginx:1.14.2 +         ports: +           - containerPort: 80 + +==> nginx/kustomization.yaml <== +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: default +resources: + - deployment.yaml +``` +The first file (`nginx.yaml`) tells Flux to look into a specific folder, with an update interval and some other settings. The other files are the kustomization; check the Kubernetes docs for that. \ No newline at end of file diff --git a/infra.md b/infra.md index 0773398..3ab471f 100644 --- a/infra.md +++ b/infra.md @@ -4,6 +4,10 @@ If you are interested in hosting anything, please reach out :). If I you don't k I also have 5pi5, a Raspberry Pi 5 (16 GiB) that I use to host smaller applications. +Learnings: + +- [[Simple Flux]] + ## Configuration The very strong ARM machine (aka, machop) runs k3s. This allows me to store my configurations in FluxCD, kept in a Git repo. Very helpful in terms of my ability to work on one project a time, when tipsy.