diff --git a/README.md b/README.md index f4ebfb2..ec1029c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,59 @@ # argocd +GitOps for the homelab k3s cluster (`k3s-design.md`). Argo CD watches this repo +on Forgejo and deploys whatever is on `main`. + +## Layout + +``` +bootstrap/root.yaml the only thing applied by hand: the "root" Application -> cluster/ +cluster/ cluster-level Argo objects (app-of-apps) + argocd.yaml Argo CD manages its own install from argocd/ + apps.yaml ApplicationSet: one Application per folder in apps/ +argocd/ Argo CD install (upstream install.yaml pinned + small patches) +apps// one app per folder, deployed to namespace +``` + +Argo reads the repo at `http://10.0.0.14:3000/un-oeil/argocd.git` (Forgejo's +internal address): pods can't reach `forgejo.un-oeil.fr` because the host has no +hairpin NAT. The repo is public, so no credentials are needed. + +## Bootstrap (once) + +Over WireGuard, with `KUBECONFIG=~/.kube/k3s-homelab.yaml`. Push this repo first: +Argo pulls from Forgejo, not from your laptop. + +```bash +kubectl apply --server-side -k argocd/ +kubectl -n argocd rollout status deploy/argocd-server +kubectl apply -f bootstrap/root.yaml +``` + +Admin password (user `admin`), then change it in the UI and delete the secret: + +```bash +kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath='{.data.password}' | base64 -d; echo +``` + +UI: either `kubectl -n argocd port-forward svc/argocd-server 8080:80` → +http://localhost:8080, or add `10.0.0.141 argocd.un-oeil.fr` to `/etc/hosts` → +http://argocd.un-oeil.fr. Argo CD is admin-only: **don't add it to Caddy**. + +## Launching an app + +1. Create `apps//` (copy `apps/whoami/`). Its contents can be: + - plain manifests, or + - a `kustomization.yaml` (Helm charts work too via `helmCharts:`), or + - a `Chart.yaml` (umbrella chart with the real chart as a dependency + `values.yaml`). +2. Commit and push. Argo picks it up within ~3 min (or hit *Refresh* in the UI) + and creates namespace ``. +3. To make it public: add an Ingress with host `.un-oeil.fr`, then a Caddy + vhost (LXC 100) pointing at Traefik on `10.0.0.141-143:80`. + +Removing a folder deletes the app **and its resources, PVCs included**. + +## Not there yet + +- Storage: only k3s `local-path` (data stuck on one node). Longhorn is the next app. +- Secrets: nothing yet. Don't commit plain Secrets; add Sealed Secrets or SOPS first. +- Forgejo webhook → Argo for instant syncs instead of 3 min polling. diff --git a/apps/whoami/deployment.yaml b/apps/whoami/deployment.yaml new file mode 100644 index 0000000..180a703 --- /dev/null +++ b/apps/whoami/deployment.yaml @@ -0,0 +1,26 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: whoami +spec: + replicas: 2 + selector: + matchLabels: + app: whoami + template: + metadata: + labels: + app: whoami + spec: + containers: + - name: whoami + image: traefik/whoami:v1.11.0 + ports: + - name: http + containerPort: 80 + resources: + requests: + cpu: 10m + memory: 16Mi + limits: + memory: 32Mi diff --git a/apps/whoami/ingress.yaml b/apps/whoami/ingress.yaml new file mode 100644 index 0000000..f32b90a --- /dev/null +++ b/apps/whoami/ingress.yaml @@ -0,0 +1,20 @@ +# Public only once a matching vhost exists in Caddy (LXC 100) pointing at +# Traefik on 10.0.0.141-143:80. Test before that, over WireGuard: +# curl -H 'Host: whoami.un-oeil.fr' http://10.0.0.141 +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: whoami +spec: + ingressClassName: traefik + rules: + - host: whoami.un-oeil.fr + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: whoami + port: + name: http diff --git a/apps/whoami/kustomization.yaml b/apps/whoami/kustomization.yaml new file mode 100644 index 0000000..098170e --- /dev/null +++ b/apps/whoami/kustomization.yaml @@ -0,0 +1,7 @@ +# Example app: copy this folder to start a new one. +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - deployment.yaml + - service.yaml + - ingress.yaml diff --git a/apps/whoami/service.yaml b/apps/whoami/service.yaml new file mode 100644 index 0000000..d916f79 --- /dev/null +++ b/apps/whoami/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: whoami +spec: + selector: + app: whoami + ports: + - name: http + port: 80 + targetPort: http diff --git a/argocd/argocd-cm.yaml b/argocd/argocd-cm.yaml new file mode 100644 index 0000000..d669d3a --- /dev/null +++ b/argocd/argocd-cm.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: argocd-cm +data: + url: http://argocd.un-oeil.fr + # Lets an app's kustomization.yaml pull Helm charts via `helmCharts:`. + kustomize.buildOptions: --enable-helm diff --git a/argocd/argocd-cmd-params-cm.yaml b/argocd/argocd-cmd-params-cm.yaml new file mode 100644 index 0000000..e640c5f --- /dev/null +++ b/argocd/argocd-cmd-params-cm.yaml @@ -0,0 +1,8 @@ +# TLS is terminated in front of Argo CD (Traefik over WireGuard, or port-forward), +# so the API server serves plain HTTP. +apiVersion: v1 +kind: ConfigMap +metadata: + name: argocd-cmd-params-cm +data: + server.insecure: "true" diff --git a/argocd/ingress.yaml b/argocd/ingress.yaml new file mode 100644 index 0000000..41c6554 --- /dev/null +++ b/argocd/ingress.yaml @@ -0,0 +1,19 @@ +# Admin-only: do NOT add this host to Caddy. Reach it over WireGuard with +# `10.0.0.141 argocd.un-oeil.fr` in the laptop's /etc/hosts. +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: argocd-server +spec: + ingressClassName: traefik + rules: + - host: argocd.un-oeil.fr + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: argocd-server + port: + name: http diff --git a/argocd/kustomization.yaml b/argocd/kustomization.yaml new file mode 100644 index 0000000..a5f37e2 --- /dev/null +++ b/argocd/kustomization.yaml @@ -0,0 +1,13 @@ +# Argo CD itself. Used once by hand for the bootstrap (see README), then +# Argo CD manages its own install from here (cluster/argocd.yaml). +# Upgrade: bump the version in the URL below and push. +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: argocd +resources: + - namespace.yaml + - https://raw.githubusercontent.com/argoproj/argo-cd/v3.5.4/manifests/install.yaml + - ingress.yaml +patches: + - path: argocd-cmd-params-cm.yaml + - path: argocd-cm.yaml diff --git a/argocd/namespace.yaml b/argocd/namespace.yaml new file mode 100644 index 0000000..a040f2b --- /dev/null +++ b/argocd/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: argocd diff --git a/bootstrap/root.yaml b/bootstrap/root.yaml new file mode 100644 index 0000000..5da669f --- /dev/null +++ b/bootstrap/root.yaml @@ -0,0 +1,19 @@ +# The only manifest applied by hand. Everything else is reached from cluster/. +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: root + namespace: argocd +spec: + project: default + source: + repoURL: http://10.0.0.14:3000/un-oeil/argocd.git + targetRevision: main + path: cluster + destination: + server: https://kubernetes.default.svc + namespace: argocd + syncPolicy: + automated: + prune: true + selfHeal: true diff --git a/cluster/apps.yaml b/cluster/apps.yaml new file mode 100644 index 0000000..0a0004a --- /dev/null +++ b/cluster/apps.yaml @@ -0,0 +1,35 @@ +# One Argo CD Application per folder in apps/, deployed to a namespace of the +# same name. Argo detects the folder type: Chart.yaml -> Helm, +# kustomization.yaml -> Kustomize, otherwise plain manifests. +apiVersion: argoproj.io/v1alpha1 +kind: ApplicationSet +metadata: + name: apps + namespace: argocd +spec: + goTemplate: true + goTemplateOptions: ["missingkey=error"] + generators: + - git: + repoURL: http://10.0.0.14:3000/un-oeil/argocd.git + revision: main + directories: + - path: apps/* + template: + metadata: + name: "{{.path.basename}}" + spec: + project: default + source: + repoURL: http://10.0.0.14:3000/un-oeil/argocd.git + targetRevision: main + path: "{{.path.path}}" + destination: + server: https://kubernetes.default.svc + namespace: "{{.path.basename}}" + syncPolicy: + automated: + prune: true + selfHeal: true + syncOptions: + - CreateNamespace=true diff --git a/cluster/argocd.yaml b/cluster/argocd.yaml new file mode 100644 index 0000000..eaa3cf9 --- /dev/null +++ b/cluster/argocd.yaml @@ -0,0 +1,23 @@ +# Argo CD manages its own install (argocd/). +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: argocd + namespace: argocd +spec: + project: default + source: + repoURL: http://10.0.0.14:3000/un-oeil/argocd.git + targetRevision: main + path: argocd + destination: + server: https://kubernetes.default.svc + namespace: argocd + syncPolicy: + automated: + # No prune: a bad commit here must not be able to delete Argo CD itself. + prune: false + selfHeal: true + syncOptions: + # The Argo CD CRDs are too big for client-side apply annotations. + - ServerSideApply=true