K3s Cluster einrichten
# Server Node (Control Plane)
curl -sfL https://get.k3s.io | sh -s - server --disable traefik --disable servicelb --cluster-init
# Token abrufen
cat /var/lib/rancher/k3s/server/node-token
# Agent Node (Worker)
curl -sfL https://get.k3s.io | K3S_URL=https://SERVER_IP:6443 K3S_TOKEN=<TOKEN> sh -
# kubectl konfigurieren
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
kubectl get nodes
Flux CD installieren
# Flux CLI installieren
curl -s https://fluxcd.io/install.sh | sudo bash
# Flux Bootstrap mit GitHub
flux bootstrap github --owner=meine-firma --repository=k3s-gitops --branch=main --path=./clusters/homelab --personal --token-auth
GitOps Repository Struktur
clusters/
homelab/
flux-system/ # Flux selbst (automatisch erstellt)
namespaces.yaml
apps/
nginx/
deployment.yaml
service.yaml
kustomization.yaml
Applikation deployen (via Git)
# clusters/homelab/apps/nginx/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:stable-alpine
ports:
- containerPort: 80
---
# clusters/homelab/apps/nginx/kustomization.yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: nginx
namespace: flux-system
spec:
interval: 10m
path: ./clusters/homelab/apps/nginx
prune: true
sourceRef:
kind: GitRepository
name: flux-system
# Git Push = automatisches Deployment!
git add clusters/homelab/apps/nginx/
git commit -m "Add nginx deployment"
git push
# Flux Sync Status
flux get kustomizations --watch
flux logs --follow
Image Automation (automatische Updates)
# Image Repository überwachen
apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImageRepository
metadata:
name: nginx
namespace: flux-system
spec:
image: nginx
interval: 1h
# Automatisch auf neueste stable Version updaten
apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImagePolicy
metadata:
name: nginx
namespace: flux-system
spec:
imageRepositoryRef:
name: nginx
policy:
semver:
range: ">=1.24.0 <2.0.0"
FAQ
Was ist der Unterschied zwischen Flux CD und ArgoCD?
Beide GitOps-Tools. Flux: Git-nativ, CLI-first, mehr Kubernetes-konform. ArgoCD: schicke Web-UI, einfacher für Teams die visuelle Übersicht brauchen.
Fazit
K3s + Flux CD ist die produktionsreife GitOps-Plattform für Homelab und KMU: jede Infrastrukturänderung wird per Git-Commit dokumentiert und automatisch deployed.
Kubernetes und GitOps für KMU in Heidelberg, Mannheim und der Rhein-Neckar-Region. Beratung anfragen.