-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayground.yaml
More file actions
206 lines (206 loc) · 6.72 KB
/
Copy pathplayground.yaml
File metadata and controls
206 lines (206 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
kind: playground
name: flux-workshop
base: k3s
title: "Flux GitOps Workshop"
description: |
A Kubernetes cluster for the Flux GitOps workshop. Gitea, Flux CLI,
and the workshop repo are set up automatically. No GitHub account needed.
cover: __static__/flux-cover.png
categories:
- kubernetes
- ci-cd
playground:
networks:
- name: local
subnet: 172.16.0.0/24
machines:
- name: dev-machine
users:
- name: root
- name: laborant
default: true
drives:
- source: k3s-dev-machine
mount: /
size: 30GiB
network:
interfaces:
- address: 172.16.0.5/24
network: local
resources:
cpuCount: 2
ramSize: 4GiB
- name: cplane-01
users:
- name: root
- name: laborant
default: true
drives:
- source: k3s-cplane
mount: /
size: 30GiB
network:
interfaces:
- address: 172.16.0.2/24
network: local
resources:
cpuCount: 2
ramSize: 4GiB
- name: node-01
users:
- name: root
- name: laborant
default: true
drives:
- source: k3s-node
mount: /
size: 30GiB
network:
interfaces:
- address: 172.16.0.3/24
network: local
resources:
cpuCount: 2
ramSize: 2GiB
- name: node-02
users:
- name: root
- name: laborant
default: true
drives:
- source: k3s-node
mount: /
size: 30GiB
network:
interfaces:
- address: 172.16.0.4/24
network: local
resources:
cpuCount: 2
ramSize: 4GiB
tabs:
- id: terminal
kind: terminal
name: Terminal
machine: dev-machine
- id: ide
kind: ide
name: IDE
machine: dev-machine
- id: kexp
kind: kexp
name: Explorer
machine: dev-machine
- id: port-3000
kind: port
name: Gitea
machine: dev-machine
port: 3000
initTasks:
init_setup:
name: init_setup
machine: dev-machine
init: true
user: root
run: |
while ! kubectl get nodes 2>/dev/null | grep -q " Ready"; do sleep 2; done
git config --global user.email "workshop@devoxx.gr"
git config --global user.name "Workshop Participant"
cat > /usr/local/bin/workshop-setup << 'SCRIPT'
#!/bin/bash
set -eu
echo "=== Setting up Flux GitOps Workshop ==="
echo ""
echo "Step 1/4: Installing Flux CLI..."
FLUX_VERSION=$(curl -sf https://api.github.com/repos/fluxcd/flux2/releases/latest | grep tag_name | cut -d'"' -f4)
curl -sL https://github.com/fluxcd/flux2/releases/download/${FLUX_VERSION}/flux_${FLUX_VERSION#v}_linux_amd64.tar.gz | sudo tar xz -C /usr/local/bin
echo ""
echo "Step 2/4: Installing Gitea (in-cluster git server)..."
helm repo add gitea-charts https://dl.gitea.com/charts/ 2>/dev/null
helm repo update
helm install gitea gitea-charts/gitea \
--namespace gitea --create-namespace \
--set gitea.admin.username=workshop \
--set gitea.admin.password=workshop \
--set service.http.type=NodePort \
--set service.http.nodePort=30080 \
--set persistence.size=1Gi \
--set redis-cluster.enabled=false \
--set postgresql-ha.enabled=false \
--set postgresql.enabled=true \
--set postgresql.global.postgresql.auth.password=gitea
echo " Waiting for Gitea to be ready..."
kubectl wait --for=condition=Ready -n gitea pod -l app.kubernetes.io/name=gitea --timeout=300s
NODE_IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')
GITEA_HOST="http://${NODE_IP}:30080"
for i in $(seq 1 30); do
curl -sf ${GITEA_HOST}/api/v1/version >/dev/null 2>&1 && break
sleep 2
done
echo " Gitea ready at ${GITEA_HOST}"
echo ""
echo "Step 3/4: Creating workshop repository..."
curl -sf -X POST ${GITEA_HOST}/api/v1/user/repos \
-H "Content-Type: application/json" \
-u "workshop:workshop" \
-d '{"name":"flux-workshop","default_branch":"main","auto_init":true}' > /dev/null
git config --global credential.helper store
echo "http://workshop:workshop@${NODE_IP}:30080" > ~/.git-credentials
mkdir -p ~/workshop && cd ~/workshop
git clone ${GITEA_HOST}/workshop/flux-workshop.git
cd flux-workshop
mkdir -p clusters/staging apps/base apps/staging infra/base infra/staging tenants/base tenants/team-a
git add . && git commit -m "Initial directory structure" --allow-empty && git push
echo ""
echo "Step 4/4: Bootstrapping Flux..."
GITEA_CLUSTER_URL="http://gitea-http.gitea.svc.cluster.local:3000"
flux install --components-extra=image-reflector-controller,image-automation-controller
kubectl wait --for=condition=Ready -n flux-system pods --all --timeout=180s
kubectl create secret generic flux-system --namespace=flux-system \
--from-literal=username=workshop --from-literal=password=workshop
echo "apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: flux-system
namespace: flux-system
spec:
interval: 1m
url: ${GITEA_CLUSTER_URL}/workshop/flux-workshop.git
ref:
branch: main
secretRef:
name: flux-system" | sed 's/^ //' | kubectl apply -f -
echo "apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: flux-system
namespace: flux-system
spec:
interval: 5m
sourceRef:
kind: GitRepository
name: flux-system
path: ./clusters/staging
prune: true" | sed 's/^ //' | kubectl apply -f -
flux reconcile source git flux-system
echo ""
echo "========================================="
echo " Workshop environment ready!"
echo ""
echo " Repo: ~/workshop/flux-workshop"
echo " Gitea: ${GITEA_HOST}"
echo " Login: workshop / workshop"
echo ""
echo " Start with Lab 2!"
echo "========================================="
SCRIPT
sed -i 's/^ //' /usr/local/bin/workshop-setup
chmod +x /usr/local/bin/workshop-setup
echo "Run 'workshop-setup' to initialize the workshop environment."
accessControl:
canList:
- anyone
canRead:
- anyone
canStart:
- anyone