Add Flux GitOps bootstrap for minikube
Set up a complete GitOps pipeline using Flux CD to manage a minikube cluster. Includes bootstrap script, Traefik ingress controller via HelmRelease, and a hello-world nginx deployment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
4
apps/kustomization.yaml
Normal file
4
apps/kustomization.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- nginx-hello
|
||||
30
apps/nginx-hello/deployment.yaml
Normal file
30
apps/nginx-hello/deployment.yaml
Normal file
@@ -0,0 +1,30 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx-hello
|
||||
namespace: nginx-hello
|
||||
labels:
|
||||
app: nginx-hello
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx-hello
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx-hello
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.27-alpine
|
||||
ports:
|
||||
- containerPort: 80
|
||||
name: http
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
6
apps/nginx-hello/kustomization.yaml
Normal file
6
apps/nginx-hello/kustomization.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- namespace.yaml
|
||||
- deployment.yaml
|
||||
- service.yaml
|
||||
4
apps/nginx-hello/namespace.yaml
Normal file
4
apps/nginx-hello/namespace.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: nginx-hello
|
||||
16
apps/nginx-hello/service.yaml
Normal file
16
apps/nginx-hello/service.yaml
Normal file
@@ -0,0 +1,16 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx-hello
|
||||
namespace: nginx-hello
|
||||
labels:
|
||||
app: nginx-hello
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: nginx-hello
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: http
|
||||
protocol: TCP
|
||||
name: http
|
||||
57
bootstrap.sh
Executable file
57
bootstrap.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
echo "=== Step 1: Ensuring minikube is running ==="
|
||||
if minikube status --format='{{.Host}}' 2>/dev/null | grep -q "Running"; then
|
||||
echo "minikube is already running."
|
||||
else
|
||||
echo "Starting minikube..."
|
||||
minikube start --driver=docker
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== Step 2: Checking Flux prerequisites ==="
|
||||
flux check --pre
|
||||
|
||||
echo ""
|
||||
echo "=== Step 3: Installing Flux controllers ==="
|
||||
flux install
|
||||
|
||||
echo ""
|
||||
echo "=== Step 4: Applying GitRepository and root Kustomization ==="
|
||||
kubectl apply -f "${SCRIPT_DIR}/clusters/minikube/flux-system/gotk-sync.yaml"
|
||||
|
||||
echo ""
|
||||
echo "=== Step 5: Triggering reconciliation and waiting ==="
|
||||
sleep 5
|
||||
flux reconcile source git flux-system
|
||||
sleep 5
|
||||
flux reconcile kustomization flux-system
|
||||
|
||||
echo "Waiting for infrastructure kustomization to become ready..."
|
||||
kubectl wait --for=condition=Ready kustomization/infrastructure \
|
||||
-n flux-system --timeout=300s || true
|
||||
|
||||
echo "Waiting for apps kustomization to become ready..."
|
||||
kubectl wait --for=condition=Ready kustomization/apps \
|
||||
-n flux-system --timeout=300s || true
|
||||
|
||||
echo ""
|
||||
echo "=== Step 6: Final status ==="
|
||||
echo "--- Flux resources ---"
|
||||
flux get all
|
||||
|
||||
echo ""
|
||||
echo "--- All pods ---"
|
||||
kubectl get pods -A
|
||||
|
||||
echo ""
|
||||
echo "--- Services ---"
|
||||
kubectl get svc -A
|
||||
|
||||
echo ""
|
||||
echo "Bootstrap complete."
|
||||
echo "To access nginx-hello: kubectl port-forward -n nginx-hello svc/nginx-hello 8080:80"
|
||||
echo "To access Traefik dashboard: minikube service traefik-dashboard -n traefik --url (if enabled)"
|
||||
17
clusters/minikube/apps.yaml
Normal file
17
clusters/minikube/apps.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||
kind: Kustomization
|
||||
metadata:
|
||||
name: apps
|
||||
namespace: flux-system
|
||||
spec:
|
||||
interval: 10m0s
|
||||
path: ./apps
|
||||
prune: true
|
||||
sourceRef:
|
||||
kind: GitRepository
|
||||
name: flux-system
|
||||
dependsOn:
|
||||
- name: infrastructure
|
||||
wait: true
|
||||
timeout: 5m0s
|
||||
24
clusters/minikube/flux-system/gotk-sync.yaml
Normal file
24
clusters/minikube/flux-system/gotk-sync.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
kind: GitRepository
|
||||
metadata:
|
||||
name: flux-system
|
||||
namespace: flux-system
|
||||
spec:
|
||||
interval: 1m0s
|
||||
ref:
|
||||
branch: main
|
||||
url: https://gitea-1.rustation.com/richards/iaac-new-dev.git
|
||||
---
|
||||
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||
kind: Kustomization
|
||||
metadata:
|
||||
name: flux-system
|
||||
namespace: flux-system
|
||||
spec:
|
||||
interval: 10m0s
|
||||
path: ./clusters/minikube
|
||||
prune: true
|
||||
sourceRef:
|
||||
kind: GitRepository
|
||||
name: flux-system
|
||||
4
clusters/minikube/flux-system/kustomization.yaml
Normal file
4
clusters/minikube/flux-system/kustomization.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- gotk-sync.yaml
|
||||
15
clusters/minikube/infrastructure.yaml
Normal file
15
clusters/minikube/infrastructure.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||
kind: Kustomization
|
||||
metadata:
|
||||
name: infrastructure
|
||||
namespace: flux-system
|
||||
spec:
|
||||
interval: 10m0s
|
||||
path: ./infrastructure
|
||||
prune: true
|
||||
sourceRef:
|
||||
kind: GitRepository
|
||||
name: flux-system
|
||||
wait: true
|
||||
timeout: 5m0s
|
||||
4
infrastructure/kustomization.yaml
Normal file
4
infrastructure/kustomization.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- traefik
|
||||
33
infrastructure/traefik/helmrelease.yaml
Normal file
33
infrastructure/traefik/helmrelease.yaml
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2
|
||||
kind: HelmRelease
|
||||
metadata:
|
||||
name: traefik
|
||||
namespace: flux-system
|
||||
spec:
|
||||
interval: 10m0s
|
||||
targetNamespace: traefik
|
||||
storageNamespace: traefik
|
||||
chart:
|
||||
spec:
|
||||
chart: traefik
|
||||
version: ">=34.0.0 <35.0.0"
|
||||
sourceRef:
|
||||
kind: HelmRepository
|
||||
name: traefik
|
||||
reconcileStrategy: ChartVersion
|
||||
install:
|
||||
createNamespace: true
|
||||
remediation:
|
||||
retries: 3
|
||||
upgrade:
|
||||
remediation:
|
||||
retries: 3
|
||||
values:
|
||||
service:
|
||||
type: NodePort
|
||||
ports:
|
||||
web:
|
||||
nodePort: 30080
|
||||
websecure:
|
||||
nodePort: 30443
|
||||
9
infrastructure/traefik/helmrepository.yaml
Normal file
9
infrastructure/traefik/helmrepository.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
kind: HelmRepository
|
||||
metadata:
|
||||
name: traefik
|
||||
namespace: flux-system
|
||||
spec:
|
||||
interval: 1h0m0s
|
||||
url: https://traefik.github.io/charts
|
||||
6
infrastructure/traefik/kustomization.yaml
Normal file
6
infrastructure/traefik/kustomization.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- namespace.yaml
|
||||
- helmrepository.yaml
|
||||
- helmrelease.yaml
|
||||
4
infrastructure/traefik/namespace.yaml
Normal file
4
infrastructure/traefik/namespace.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: traefik
|
||||
Reference in New Issue
Block a user