Project

General

Profile

The ungleich kubernetes infrastructure » History » Version 136

Nico Schottelius, 09/03/2022 12:45 PM

1 22 Nico Schottelius
h1. The ungleich kubernetes infrastructure and ungleich kubernetes manual
2 1 Nico Schottelius
3 3 Nico Schottelius
{{toc}}
4
5 1 Nico Schottelius
h2. Status
6
7 28 Nico Schottelius
This document is **pre-production**.
8
This document is to become the ungleich kubernetes infrastructure overview as well as the ungleich kubernetes manual.
9 1 Nico Schottelius
10 10 Nico Schottelius
h2. k8s clusters
11
12 123 Nico Schottelius
| Cluster            | Purpose/Setup     | Maintainer | Master(s)                     | argo                                                   | v4 http proxy | last verified |
13
| c0.k8s.ooo         | Dev               | -          | UNUSED                        |                                                        |               |    2021-10-05 |
14
| c1.k8s.ooo         | retired           |            | -                             |                                                        |               |    2022-03-15 |
15
| c2.k8s.ooo         | Dev p7 HW         | Nico       | server47 server53 server54    | "argo":https://argocd-server.argocd.svc.c2.k8s.ooo     |               |    2021-10-05 |
16
| c3.k8s.ooo         | retired           | -          | -                             |                                                        |               |    2021-10-05 |
17
| c4.k8s.ooo         | Dev2 p7 HW        | Jin-Guk    | server52 server53 server54    |                                                        |               |             - |
18
| c5.k8s.ooo         | retired           |            | -                             |                                                        |               |    2022-03-15 |
19
| c6.k8s.ooo         | Dev p6 VM Jin-Guk | Jin-Guk    |                               |                                                        |               |               |
20
| [[p5.k8s.ooo]]     | production        |            | server34 server36 server38    | "argo":https://argocd-server.argocd.svc.p5.k8s.ooo     | -             |               |
21
| [[p5-cow.k8s.ooo]] | production        | Nico       | server47 server51 server55    | "argo":https://argocd-server.argocd.svc.p5-cow.k8s.ooo |               |    2022-08-27 |
22
| [[p6.k8s.ooo]]     | production        |            | server67 server69 server71    | "argo":https://argocd-server.argocd.svc.p6.k8s.ooo     | 147.78.194.13 |    2021-10-05 |
23
| [[p10.k8s.ooo]]    | production        |            | server63 server65 server83    | "argo":https://argocd-server.argocd.svc.p10.k8s.ooo    | 147.78.194.12 |    2021-10-05 |
24
| [[k8s.ge.nau.so]]  | development       |            | server107 server108 server109 | "argo":https://argocd-server.argocd.svc.k8s.ge.nau.so  |               |               |
25
| [[dev.k8s.ooo]]    | development       |            | server110 server111 server112 | "argo":https://argocd-server.argocd.svc.dev.k8s.ooo    | -             |    2022-07-08 |
26
27
28
29 21 Nico Schottelius
30 1 Nico Schottelius
h2. General architecture and components overview
31
32
* All k8s clusters are IPv6 only
33
* We use BGP peering to propagate podcidr and serviceCidr networks to our infrastructure
34
* The main public testing repository is "ungleich-k8s":https://code.ungleich.ch/ungleich-public/ungleich-k8s
35 18 Nico Schottelius
** Private configurations are found in the **k8s-config** repository
36 1 Nico Schottelius
37
h3. Cluster types
38
39 28 Nico Schottelius
| **Type/Feature**            | **Development**                | **Production**         |
40
| Min No. nodes               | 3 (1 master, 3 worker)         | 5 (3 master, 3 worker) |
41
| Recommended minimum         | 4 (dedicated master, 3 worker) | 8 (3 master, 5 worker) |
42
| Separation of control plane | optional                       | recommended            |
43
| Persistent storage          | required                       | required               |
44
| Number of storage monitors  | 3                              | 5                      |
45 1 Nico Schottelius
46 43 Nico Schottelius
h2. General k8s operations
47 1 Nico Schottelius
48 46 Nico Schottelius
h3. Cheat sheet / external great references
49
50
* "kubectl cheatsheet":https://kubernetes.io/docs/reference/kubectl/cheatsheet/
51
52 117 Nico Schottelius
h3. Allowing to schedule work on the control plane / removing node taints
53 69 Nico Schottelius
54
* Mostly for single node / test / development clusters
55
* Just remove the master taint as follows
56
57
<pre>
58
kubectl taint nodes --all node-role.kubernetes.io/master-
59 118 Nico Schottelius
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
60 69 Nico Schottelius
</pre>
61 1 Nico Schottelius
62 117 Nico Schottelius
You can check the node taints using @kubectl describe node ...@
63 69 Nico Schottelius
64 44 Nico Schottelius
h3. Get the cluster admin.conf
65
66
* On the masters of each cluster you can find the file @/etc/kubernetes/admin.conf@
67
* To be able to administrate the cluster you can copy the admin.conf to your local machine
68
* Multi cluster debugging can very easy if you name the config ~/cX-admin.conf (see example below)
69
70
<pre>
71
% scp root@server47.place7.ungleich.ch:/etc/kubernetes/admin.conf ~/c2-admin.conf
72
% export KUBECONFIG=~/c2-admin.conf    
73
% kubectl get nodes
74
NAME       STATUS                     ROLES                  AGE   VERSION
75
server47   Ready                      control-plane,master   82d   v1.22.0
76
server48   Ready                      control-plane,master   82d   v1.22.0
77
server49   Ready                      <none>                 82d   v1.22.0
78
server50   Ready                      <none>                 82d   v1.22.0
79
server59   Ready                      control-plane,master   82d   v1.22.0
80
server60   Ready,SchedulingDisabled   <none>                 82d   v1.22.0
81
server61   Ready                      <none>                 82d   v1.22.0
82
server62   Ready                      <none>                 82d   v1.22.0               
83
</pre>
84
85 18 Nico Schottelius
h3. Installing a new k8s cluster
86 8 Nico Schottelius
87 9 Nico Schottelius
* Decide on the cluster name (usually *cX.k8s.ooo*), X counting upwards
88 28 Nico Schottelius
** Using pXX.k8s.ooo for production clusters of placeXX
89 9 Nico Schottelius
* Use cdist to configure the nodes with requirements like crio
90
* Decide between single or multi node control plane setups (see below)
91 28 Nico Schottelius
** Single control plane suitable for development clusters
92 9 Nico Schottelius
93 28 Nico Schottelius
Typical init procedure:
94 9 Nico Schottelius
95 28 Nico Schottelius
* Single control plane: @kubeadm init --config bootstrap/XXX/kubeadm.yaml@
96
* Multi control plane (HA): @kubeadm init --config bootstrap/XXX/kubeadm.yaml --upload-certs@
97 10 Nico Schottelius
98 29 Nico Schottelius
h3. Deleting a pod that is hanging in terminating state
99
100
<pre>
101
kubectl delete pod <PODNAME> --grace-period=0 --force --namespace <NAMESPACE>
102
</pre>
103
104
(from https://stackoverflow.com/questions/35453792/pods-stuck-in-terminating-status)
105
106 42 Nico Schottelius
h3. Listing nodes of a cluster
107
108
<pre>
109
[15:05] bridge:~% kubectl get nodes
110
NAME       STATUS   ROLES                  AGE   VERSION
111
server22   Ready    <none>                 52d   v1.22.0
112
server23   Ready    <none>                 52d   v1.22.2
113
server24   Ready    <none>                 52d   v1.22.0
114
server25   Ready    <none>                 52d   v1.22.0
115
server26   Ready    <none>                 52d   v1.22.0
116
server27   Ready    <none>                 52d   v1.22.0
117
server63   Ready    control-plane,master   52d   v1.22.0
118
server64   Ready    <none>                 52d   v1.22.0
119
server65   Ready    control-plane,master   52d   v1.22.0
120
server66   Ready    <none>                 52d   v1.22.0
121
server83   Ready    control-plane,master   52d   v1.22.0
122
server84   Ready    <none>                 52d   v1.22.0
123
server85   Ready    <none>                 52d   v1.22.0
124
server86   Ready    <none>                 52d   v1.22.0
125
</pre>
126
127 41 Nico Schottelius
h3. Removing / draining a node
128
129
Usually @kubectl drain server@ should do the job, but sometimes we need to be more aggressive:
130
131 1 Nico Schottelius
<pre>
132 103 Nico Schottelius
kubectl drain --delete-emptydir-data --ignore-daemonsets serverXX
133 42 Nico Schottelius
</pre>
134
135
h3. Readding a node after draining
136
137
<pre>
138
kubectl uncordon serverXX
139 1 Nico Schottelius
</pre>
140 43 Nico Schottelius
141 50 Nico Schottelius
h3. (Re-)joining worker nodes after creating the cluster
142 49 Nico Schottelius
143
* We need to have an up-to-date token
144
* We use different join commands for the workers and control plane nodes
145
146
Generating the join command on an existing control plane node:
147
148
<pre>
149
kubeadm token create --print-join-command
150
</pre>
151
152 50 Nico Schottelius
h3. (Re-)joining control plane nodes after creating the cluster
153 1 Nico Schottelius
154 50 Nico Schottelius
* We generate the token again
155
* We upload the certificates
156
* We need to combine/create the join command for the control plane node
157
158
Example session:
159
160
<pre>
161
% kubeadm token create --print-join-command
162
kubeadm join p10-api.k8s.ooo:6443 --token xmff4i.ABC --discovery-token-ca-cert-hash sha256:longhash 
163
164
% kubeadm init phase upload-certs --upload-certs
165
[upload-certs] Storing the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace
166
[upload-certs] Using certificate key:
167
CERTKEY
168
169
# Then we use these two outputs on the joining node:
170
171
kubeadm join p10-api.k8s.ooo:6443 --token xmff4i.ABC --discovery-token-ca-cert-hash sha256:longhash --control-plane --certificate-key CERTKEY
172
</pre>
173
174
Commands to be used on a control plane node:
175
176
<pre>
177
kubeadm token create --print-join-command
178
kubeadm init phase upload-certs --upload-certs
179
</pre>
180
181
Commands to be used on the joining node:
182
183
<pre>
184
JOINCOMMAND --control-plane --certificate-key CERTKEY
185
</pre>
186 49 Nico Schottelius
187 51 Nico Schottelius
SEE ALSO
188
189
* https://stackoverflow.com/questions/63936268/how-to-generate-kubeadm-token-for-secondary-control-plane-nodes
190
* https://blog.scottlowe.org/2019/08/15/reconstructing-the-join-command-for-kubeadm/
191
192 53 Nico Schottelius
h3. How to fix etcd does not start when rejoining a kubernetes cluster as a control plane
193 52 Nico Schottelius
194
If during the above step etcd does not come up, @kubeadm join@ can hang as follows:
195
196
<pre>
197
[control-plane] Creating static Pod manifest for "kube-apiserver"                                                              
198
[control-plane] Creating static Pod manifest for "kube-controller-manager"                                                     
199
[control-plane] Creating static Pod manifest for "kube-scheduler"                                                              
200
[check-etcd] Checking that the etcd cluster is healthy                                                                         
201
error execution phase check-etcd: etcd cluster is not healthy: failed to dial endpoint https://[2a0a:e5c0:10:1:225:b3ff:fe20:37
202
8a]:2379 with maintenance client: context deadline exceeded                                                                    
203
To see the stack trace of this error execute with --v=5 or higher         
204
</pre>
205
206
Then the problem is likely that the etcd server is still a member of the cluster. We first need to remove it from the etcd cluster and then the join works.
207
208
To fix this we do:
209
210
* Find a working etcd pod
211
* Find the etcd members / member list
212
* Remove the etcd member that we want to re-join the cluster
213
214
215
<pre>
216
# Find the etcd pods
217
kubectl -n kube-system get pods -l component=etcd,tier=control-plane
218
219
# Get the list of etcd servers with the member id 
220
kubectl exec -n kube-system -ti ETCDPODNAME -- etcdctl --endpoints '[::1]:2379' --cacert /etc/kubernetes/pki/etcd/ca.crt --cert  /etc/kubernetes/pki/etcd/server.crt --key /etc/kubernetes/pki/etcd/server.key member list
221
222
# Remove the member
223
kubectl exec -n kube-system -ti ETCDPODNAME -- etcdctl --endpoints '[::1]:2379' --cacert /etc/kubernetes/pki/etcd/ca.crt --cert  /etc/kubernetes/pki/etcd/server.crt --key /etc/kubernetes/pki/etcd/server.key member remove MEMBERID
224
</pre>
225
226
Sample session:
227
228
<pre>
229
[10:48] line:~% kubectl -n kube-system get pods -l component=etcd,tier=control-plane
230
NAME            READY   STATUS    RESTARTS     AGE
231
etcd-server63   1/1     Running   0            3m11s
232
etcd-server65   1/1     Running   3            7d2h
233
etcd-server83   1/1     Running   8 (6d ago)   7d2h
234
[10:48] line:~% kubectl exec -n kube-system -ti etcd-server65 -- etcdctl --endpoints '[::1]:2379' --cacert /etc/kubernetes/pki/etcd/ca.crt --cert  /etc/kubernetes/pki/etcd/server.crt --key /etc/kubernetes/pki/etcd/server.key member list
235
356891cd676df6e4, started, server65, https://[2a0a:e5c0:10:1:225:b3ff:fe20:375c]:2380, https://[2a0a:e5c0:10:1:225:b3ff:fe20:375c]:2379, false
236
371b8a07185dee7e, started, server63, https://[2a0a:e5c0:10:1:225:b3ff:fe20:378a]:2380, https://[2a0a:e5c0:10:1:225:b3ff:fe20:378a]:2379, false
237
5942bc58307f8af9, started, server83, https://[2a0a:e5c0:10:1:3e4a:92ff:fe79:bb98]:2380, https://[2a0a:e5c0:10:1:3e4a:92ff:fe79:bb98]:2379, false
238
239
[10:48] line:~% kubectl exec -n kube-system -ti etcd-server65 -- etcdctl --endpoints '[::1]:2379' --cacert /etc/kubernetes/pki/etcd/ca.crt --cert  /etc/kubernetes/pki/etcd/server.crt --key /etc/kubernetes/pki/etcd/server.key member remove 371b8a07185dee7e
240
Member 371b8a07185dee7e removed from cluster e3c0805f592a8f77
241 1 Nico Schottelius
242
</pre>
243
244
SEE ALSO
245
246
* We found the solution using https://stackoverflow.com/questions/67921552/re-installed-node-cannot-join-kubernetes-cluster
247 56 Nico Schottelius
248 101 Nico Schottelius
h3. Hardware Maintenance using ungleich-hardware
249
250
Use the following manifest and replace the HOST with the actual host:
251
252
<pre>
253
apiVersion: v1
254
kind: Pod
255
metadata:
256
  name: ungleich-hardware-HOST
257
spec:
258
  containers:
259
  - name: ungleich-hardware
260
    image: ungleich/ungleich-hardware:0.0.5
261
    args:
262
    - sleep
263
    - "1000000"
264
    volumeMounts:
265
      - mountPath: /dev
266
        name: dev
267
    securityContext:
268
      privileged: true
269
  nodeSelector:
270
    kubernetes.io/hostname: "HOST"
271
272
  volumes:
273
    - name: dev
274
      hostPath:
275
        path: /dev
276
</pre>
277
278 102 Nico Schottelius
Also see: [[The_ungleich_hardware_maintenance_guide]]
279
280 105 Nico Schottelius
h3. Triggering a cronjob / creating a job from a cronjob
281 104 Nico Schottelius
282
To test a cronjob, we can create a job from a cronjob:
283
284
<pre>
285
kubectl create job --from=cronjob/volume2-daily-backup volume2-manual
286
</pre>
287
288
This creates a job volume2-manual based on the cronjob  volume2-daily
289
290 112 Nico Schottelius
h3. su-ing into a user that has nologin shell set
291
292
Many times users are having nologin as their shell inside the container. To be able to execute maintenance commands within the
293
container, we can use @su -s /bin/sh@ like this:
294
295
<pre>
296
su -s /bin/sh -c '/path/to/your/script' testuser
297
</pre>
298
299
Found on https://serverfault.com/questions/351046/how-to-run-command-as-user-who-has-usr-sbin-nologin-as-shell
300
301 113 Nico Schottelius
h3. How to print a secret value
302
303
Assuming you want the "password" item from a secret, use:
304
305
<pre>
306
kubectl get secret SECRETNAME -o jsonpath="{.data.password}" | base64 -d; echo "" 
307
</pre>
308
309 62 Nico Schottelius
h2. Calico CNI
310
311
h3. Calico Installation
312
313
* We install "calico using helm":https://docs.projectcalico.org/getting-started/kubernetes/helm
314
* This has the following advantages:
315
** Easy to upgrade
316
** Does not require os to configure IPv6/dual stack settings as the tigera operator figures out things on its own
317
318
Usually plain calico can be installed directly using:
319
320
<pre>
321 125 Nico Schottelius
VERSION=v3.23.3
322 120 Nico Schottelius
helm repo add projectcalico https://docs.projectcalico.org/charts
323 124 Nico Schottelius
helm upgrade --install --namespace tigera calico projectcalico/tigera-operator --version $VERSION --create-namespace
324 1 Nico Schottelius
</pre>
325 92 Nico Schottelius
326
* Check the tags on https://github.com/projectcalico/calico/tags for the latest release
327 62 Nico Schottelius
328
h3. Installing calicoctl
329
330 115 Nico Schottelius
* General installation instructions, including binary download: https://projectcalico.docs.tigera.io/maintenance/clis/calicoctl/install
331
332 62 Nico Schottelius
To be able to manage and configure calico, we need to 
333
"install calicoctl (we choose the version as a pod)":https://docs.projectcalico.org/getting-started/clis/calicoctl/install#install-calicoctl-as-a-kubernetes-pod
334
335
<pre>
336
kubectl apply -f https://docs.projectcalico.org/manifests/calicoctl.yaml
337
</pre>
338
339 93 Nico Schottelius
Or version specific:
340
341
<pre>
342
kubectl apply -f https://github.com/projectcalico/calico/blob/v3.20.4/manifests/calicoctl.yaml
343 97 Nico Schottelius
344
# For 3.22
345
kubectl apply -f https://projectcalico.docs.tigera.io/archive/v3.22/manifests/calicoctl.yaml
346 93 Nico Schottelius
</pre>
347
348 70 Nico Schottelius
And making it easier accessible by alias:
349
350
<pre>
351
alias calicoctl="kubectl exec -i -n kube-system calicoctl -- /calicoctl"
352
</pre>
353
354 62 Nico Schottelius
h3. Calico configuration
355
356 63 Nico Schottelius
By default our k8s clusters "BGP peer":https://docs.projectcalico.org/networking/bgp
357
with an upstream router to propagate podcidr and servicecidr.
358 62 Nico Schottelius
359
Default settings in our infrastructure:
360
361
* We use a full-mesh using the @nodeToNodeMeshEnabled: true@ option
362
* We keep the original next hop so that *only* the server with the pod is announcing it (instead of ecmp)
363 1 Nico Schottelius
* We use private ASNs for k8s clusters
364 63 Nico Schottelius
* We do *not* use any overlay
365 62 Nico Schottelius
366
After installing calico and calicoctl the last step of the installation is usually:
367
368 1 Nico Schottelius
<pre>
369 79 Nico Schottelius
calicoctl create -f - < calico-bgp.yaml
370 62 Nico Schottelius
</pre>
371
372
373
A sample BGP configuration:
374
375
<pre>
376
---
377
apiVersion: projectcalico.org/v3
378
kind: BGPConfiguration
379
metadata:
380
  name: default
381
spec:
382
  logSeverityScreen: Info
383
  nodeToNodeMeshEnabled: true
384
  asNumber: 65534
385
  serviceClusterIPs:
386
  - cidr: 2a0a:e5c0:10:3::/108
387
  serviceExternalIPs:
388
  - cidr: 2a0a:e5c0:10:3::/108
389
---
390
apiVersion: projectcalico.org/v3
391
kind: BGPPeer
392
metadata:
393
  name: router1-place10
394
spec:
395
  peerIP: 2a0a:e5c0:10:1::50
396
  asNumber: 213081
397
  keepOriginalNextHop: true
398
</pre>
399
400 126 Nico Schottelius
h2. Cilium CNI (experimental)
401
402 128 Nico Schottelius
h3. BGP configuration
403
404
* The cilium-operator will not start without a correct configmap being present beforehand (see error message below)
405
* Creating the bgp config beforehand as a configmap is thus required.
406
407
The error one gets without the configmap present:
408
409
Pods are hanging with:
410
411
<pre>
412
cilium-bpqm6                       0/1     Init:0/4            0             9s
413
cilium-operator-5947d94f7f-5bmh2   0/1     ContainerCreating   0             9s
414
</pre>
415
416
The error message in the cilium-*perator is:
417
418
<pre>
419
Events:
420
  Type     Reason       Age                From               Message
421
  ----     ------       ----               ----               -------
422
  Normal   Scheduled    80s                default-scheduler  Successfully assigned kube-system/cilium-operator-5947d94f7f-lqcsp to server56
423
  Warning  FailedMount  16s (x8 over 80s)  kubelet            MountVolume.SetUp failed for volume "bgp-config-path" : configmap "bgp-config" not found
424
</pre>
425
426
A correct bgp config looks like this:
427
428
<pre>
429
apiVersion: v1
430
kind: ConfigMap
431
metadata:
432
  name: bgp-config
433
  namespace: kube-system
434
data:
435
  config.yaml: |
436
    peers:
437
      - peer-address: 2a0a:e5c0::46
438
        peer-asn: 209898
439
        my-asn: 65533
440
      - peer-address: 2a0a:e5c0::47
441
        peer-asn: 209898
442
        my-asn: 65533
443
    address-pools:
444
      - name: default
445
        protocol: bgp
446
        addresses:
447
          - 2a0a:e5c0:0:14::/64
448
</pre>
449
450 127 Nico Schottelius
h3. Installation
451
452 130 Nico Schottelius
Adding the repo
453 127 Nico Schottelius
<pre>
454 1 Nico Schottelius
455 127 Nico Schottelius
helm repo add cilium https://helm.cilium.io/
456 129 Nico Schottelius
helm repo update
457 130 Nico Schottelius
</pre>
458 1 Nico Schottelius
459 130 Nico Schottelius
Installing + configuring cilium
460
<pre>
461 129 Nico Schottelius
version=1.12.1
462 135 Nico Schottelius
ipv6pool=2a0a:e5c0:0:14::/112
463 129 Nico Schottelius
464 130 Nico Schottelius
465 1 Nico Schottelius
helm upgrade --install cilium cilium/cilium --version $version \
466 129 Nico Schottelius
  --namespace kube-system \
467
  --set ipv4.enabled=false \
468 1 Nico Schottelius
  --set ipv6.enabled=true \
469 131 Nico Schottelius
  --set ipam.operator.clusterPoolIPv6PodCIDRList=$ipv6pool \
470 1 Nico Schottelius
  --set bgpControlPlane.enabled=true
471 136 Nico Schottelius
472
#   --set bgp.enabled=true --set bgp.announce.podCIDR=true \
473 127 Nico Schottelius
474
# Show possible configuration options
475
helm show values cilium/cilium
476
477 1 Nico Schottelius
</pre>
478 132 Nico Schottelius
479
Using a /64 for ipam.operator.clusterPoolIPv6PodCIDRList fails with:
480
481
<pre>
482
level=fatal msg="Unable to init cluster-pool allocator" error="unable to initialize IPv6 allocator New CIDR set failed; the node CIDR size is too big" subsys=cilium-operator-generic
483
</pre>
484
485 126 Nico Schottelius
486 1 Nico Schottelius
See also https://github.com/cilium/cilium/issues/20756
487 135 Nico Schottelius
488
Seems a /112 is actually working.
489
490
h3. Kernel modules
491
492
Cilium requires the following modules to be loaded on the host (not loaded by default):
493
494
<pre>
495
modprobe  ip6table_raw
496
modprobe  ip6table_filter
497
</pre>
498 133 Nico Schottelius
499 122 Nico Schottelius
h2. ArgoCD 
500 56 Nico Schottelius
501 60 Nico Schottelius
h3. Argocd Installation
502 1 Nico Schottelius
503 116 Nico Schottelius
* See https://argo-cd.readthedocs.io/en/stable/
504
505 60 Nico Schottelius
As there is no configuration management present yet, argocd is installed using
506
507 1 Nico Schottelius
<pre>
508 60 Nico Schottelius
kubectl create namespace argocd
509 86 Nico Schottelius
510 96 Nico Schottelius
# Specific Version
511
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.3.2/manifests/install.yaml
512 86 Nico Schottelius
513
# OR: latest stable
514 60 Nico Schottelius
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
515 56 Nico Schottelius
</pre>
516 1 Nico Schottelius
517 116 Nico Schottelius
518 1 Nico Schottelius
519 60 Nico Schottelius
h3. Get the argocd credentials
520
521
<pre>
522
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo ""
523
</pre>
524 52 Nico Schottelius
525 87 Nico Schottelius
h3. Accessing argocd
526
527
In regular IPv6 clusters:
528
529
* Navigate to https://argocd-server.argocd.CLUSTERDOMAIN
530
531
In legacy IPv4 clusters
532
533
<pre>
534
kubectl --namespace argocd port-forward svc/argocd-server 8080:80
535
</pre>
536
537 88 Nico Schottelius
* Navigate to https://localhost:8080
538
539 68 Nico Schottelius
h3. Using the argocd webhook to trigger changes
540 67 Nico Schottelius
541
* To trigger changes post json https://argocd.example.com/api/webhook
542
543 72 Nico Schottelius
h3. Deploying an application
544
545
* Applications are deployed via git towards gitea (code.ungleich.ch) and then pulled by argo
546 73 Nico Schottelius
* Always include the *redmine-url* pointing to the (customer) ticket
547
** Also add the support-url if it exists
548 72 Nico Schottelius
549
Application sample
550
551
<pre>
552
apiVersion: argoproj.io/v1alpha1
553
kind: Application
554
metadata:
555
  name: gitea-CUSTOMER
556
  namespace: argocd
557
spec:
558
  destination:
559
    namespace: default
560
    server: 'https://kubernetes.default.svc'
561
  source:
562
    path: apps/prod/gitea
563
    repoURL: 'https://code.ungleich.ch/ungleich-intern/k8s-config.git'
564
    targetRevision: HEAD
565
    helm:
566
      parameters:
567
        - name: storage.data.storageClass
568
          value: rook-ceph-block-hdd
569
        - name: storage.data.size
570
          value: 200Gi
571
        - name: storage.db.storageClass
572
          value: rook-ceph-block-ssd
573
        - name: storage.db.size
574
          value: 10Gi
575
        - name: storage.letsencrypt.storageClass
576
          value: rook-ceph-block-hdd
577
        - name: storage.letsencrypt.size
578
          value: 50Mi
579
        - name: letsencryptStaging
580
          value: 'no'
581
        - name: fqdn
582
          value: 'code.verua.online'
583
  project: default
584
  syncPolicy:
585
    automated:
586
      prune: true
587
      selfHeal: true
588
  info:
589
    - name: 'redmine-url'
590
      value: 'https://redmine.ungleich.ch/issues/ISSUEID'
591
    - name: 'support-url'
592
      value: 'https://support.ungleich.ch/Ticket/Display.html?id=TICKETID'
593
</pre>
594
595 80 Nico Schottelius
h2. Helm related operations and conventions
596 55 Nico Schottelius
597 61 Nico Schottelius
We use helm charts extensively.
598
599
* In production, they are managed via argocd
600
* In development, helm chart can de developed and deployed manually using the helm utility.
601
602 55 Nico Schottelius
h3. Installing a helm chart
603
604
One can use the usual pattern of
605
606
<pre>
607
helm install <releasename> <chartdirectory>
608
</pre>
609
610
However often you want to reinstall/update when testing helm charts. The following pattern is "better", because it allows you to reinstall, if it is already installed:
611
612
<pre>
613
helm upgrade --install <releasename> <chartdirectory>
614 1 Nico Schottelius
</pre>
615 80 Nico Schottelius
616
h3. Naming services and deployments in helm charts [Application labels]
617
618
* We always have {{ .Release.Name }} to identify the current "instance"
619
* Deployments:
620
** use @app: <what it is>@, f.i. @app: nginx@, @app: postgres@, ...
621 81 Nico Schottelius
* See more about standard labels on
622
** https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
623
** https://helm.sh/docs/chart_best_practices/labels/
624 55 Nico Schottelius
625 43 Nico Schottelius
h2. Rook / Ceph Related Operations
626
627 71 Nico Schottelius
h3. Executing ceph commands
628
629
Using the ceph-tools pod as follows:
630
631
<pre>
632
kubectl exec -n rook-ceph -ti $(kubectl -n rook-ceph get pods -l app=rook-ceph-tools -o jsonpath='{.items[*].metadata.name}') -- ceph -s
633
</pre>
634
635 43 Nico Schottelius
h3. Inspecting the logs of a specific server
636
637
<pre>
638
# Get the related pods
639
kubectl -n rook-ceph get pods -l app=rook-ceph-osd-prepare 
640
...
641
642
# Inspect the logs of a specific pod
643
kubectl -n rook-ceph logs -f rook-ceph-osd-prepare-server23--1-444qx
644
645 71 Nico Schottelius
</pre>
646
647
h3. Inspecting the logs of the rook-ceph-operator
648
649
<pre>
650
kubectl -n rook-ceph logs -f -l app=rook-ceph-operator
651 43 Nico Schottelius
</pre>
652
653 121 Nico Schottelius
h3. Restarting the rook operator
654
655
<pre>
656
kubectl -n rook-ceph delete pods  -l app=rook-ceph-operator
657
</pre>
658
659 43 Nico Schottelius
h3. Triggering server prepare / adding new osds
660
661
The rook-ceph-operator triggers/watches/creates pods to maintain hosts. To trigger a full "re scan", simply delete that pod:
662
663
<pre>
664
kubectl -n rook-ceph delete pods -l app=rook-ceph-operator
665
</pre>
666
667
This will cause all the @rook-ceph-osd-prepare-..@ jobs to be recreated and thus OSDs to be created, if new disks have been added.
668
669
h3. Removing an OSD
670
671
* See "Ceph OSD Management":https://rook.io/docs/rook/v1.7/ceph-osd-mgmt.html
672 77 Nico Schottelius
* More specifically: https://github.com/rook/rook/blob/release-1.7/cluster/examples/kubernetes/ceph/osd-purge.yaml
673 99 Nico Schottelius
* Then delete the related deployment
674 41 Nico Schottelius
675 98 Nico Schottelius
Set osd id in the osd-purge.yaml and apply it. OSD should be down before.
676
677
<pre>
678
apiVersion: batch/v1
679
kind: Job
680
metadata:
681
  name: rook-ceph-purge-osd
682
  namespace: rook-ceph # namespace:cluster
683
  labels:
684
    app: rook-ceph-purge-osd
685
spec:
686
  template:
687
    metadata:
688
      labels:
689
        app: rook-ceph-purge-osd
690
    spec:
691
      serviceAccountName: rook-ceph-purge-osd
692
      containers:
693
        - name: osd-removal
694
          image: rook/ceph:master
695
          # TODO: Insert the OSD ID in the last parameter that is to be removed
696
          # The OSD IDs are a comma-separated list. For example: "0" or "0,2".
697
          # If you want to preserve the OSD PVCs, set `--preserve-pvc true`.
698
          #
699
          # A --force-osd-removal option is available if the OSD should be destroyed even though the
700
          # removal could lead to data loss.
701
          args:
702
            - "ceph"
703
            - "osd"
704
            - "remove"
705
            - "--preserve-pvc"
706
            - "false"
707
            - "--force-osd-removal"
708
            - "false"
709
            - "--osd-ids"
710
            - "SETTHEOSDIDHERE"
711
          env:
712
            - name: POD_NAMESPACE
713
              valueFrom:
714
                fieldRef:
715
                  fieldPath: metadata.namespace
716
            - name: ROOK_MON_ENDPOINTS
717
              valueFrom:
718
                configMapKeyRef:
719
                  key: data
720
                  name: rook-ceph-mon-endpoints
721
            - name: ROOK_CEPH_USERNAME
722
              valueFrom:
723
                secretKeyRef:
724
                  key: ceph-username
725
                  name: rook-ceph-mon
726
            - name: ROOK_CEPH_SECRET
727
              valueFrom:
728
                secretKeyRef:
729
                  key: ceph-secret
730
                  name: rook-ceph-mon
731
            - name: ROOK_CONFIG_DIR
732
              value: /var/lib/rook
733
            - name: ROOK_CEPH_CONFIG_OVERRIDE
734
              value: /etc/rook/config/override.conf
735
            - name: ROOK_FSID
736
              valueFrom:
737
                secretKeyRef:
738
                  key: fsid
739
                  name: rook-ceph-mon
740
            - name: ROOK_LOG_LEVEL
741
              value: DEBUG
742
          volumeMounts:
743
            - mountPath: /etc/ceph
744
              name: ceph-conf-emptydir
745
            - mountPath: /var/lib/rook
746
              name: rook-config
747
      volumes:
748
        - emptyDir: {}
749
          name: ceph-conf-emptydir
750
        - emptyDir: {}
751
          name: rook-config
752
      restartPolicy: Never
753
754
755 99 Nico Schottelius
</pre>
756
757
Deleting the deployment:
758
759
<pre>
760
[18:05] bridge:~% kubectl -n rook-ceph delete deployment rook-ceph-osd-6
761
deployment.apps "rook-ceph-osd-6" deleted
762 98 Nico Schottelius
</pre>
763
764 76 Nico Schottelius
h2. Harbor
765
766
* We user "Harbor":https://goharbor.io/ for caching and as an image registry. Internal app reference: apps/prod/harbor.
767
* The admin password is in the password store, auto generated per cluster
768
* At the moment harbor only authenticates against the internal ldap tree
769
770
h3. LDAP configuration
771
772
* The url needs to be ldaps://...
773
* uid = uid
774
* rest standard
775 75 Nico Schottelius
776 89 Nico Schottelius
h2. Monitoring / Prometheus
777
778 90 Nico Schottelius
* Via "kube-prometheus":https://github.com/prometheus-operator/kube-prometheus/
779 89 Nico Schottelius
780 91 Nico Schottelius
Access via ...
781
782
* http://prometheus-k8s.monitoring.svc:9090
783
* http://grafana.monitoring.svc:3000
784
* http://alertmanager.monitoring.svc:9093
785
786
787 100 Nico Schottelius
h3. Prometheus Options
788
789
* "helm/kube-prometheus-stack":https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack
790
** Includes dashboards and co.
791
* "manifest based kube-prometheus":https://github.com/prometheus-operator/kube-prometheus
792
** Includes dashboards and co.
793
* "Prometheus Operator (mainly CRD manifest":https://github.com/prometheus-operator/prometheus-operator
794
795 91 Nico Schottelius
796 82 Nico Schottelius
h2. Nextcloud
797
798 85 Nico Schottelius
h3. How to get the nextcloud credentials 
799 84 Nico Schottelius
800
* The initial username is set to "nextcloud"
801
* The password is autogenerated and saved in a kubernetes secret
802
803
<pre>
804 85 Nico Schottelius
kubectl get secret RELEASENAME-nextcloud -o jsonpath="{.data.PASSWORD}" | base64 -d; echo "" 
805 84 Nico Schottelius
</pre>
806
807 83 Nico Schottelius
h3. How to fix "Access through untrusted domain"
808
809 82 Nico Schottelius
* Nextcloud stores the initial domain configuration
810 1 Nico Schottelius
* If the FQDN is changed, it will show the error message "Access through untrusted domain"
811 82 Nico Schottelius
* To fix, edit /var/www/html/config/config.php and correct the domain
812 83 Nico Schottelius
* Then delete the pods
813 82 Nico Schottelius
814 1 Nico Schottelius
h2. Infrastructure versions
815 35 Nico Schottelius
816 57 Nico Schottelius
h3. ungleich kubernetes infrastructure v5 (2021-10)
817 1 Nico Schottelius
818 57 Nico Schottelius
Clusters are configured / setup in this order:
819
820
* Bootstrap via kubeadm
821 59 Nico Schottelius
* "Networking via calico + BGP (non ECMP) using helm":https://docs.projectcalico.org/getting-started/kubernetes/helm
822
* "ArgoCD for CD":https://argo-cd.readthedocs.io/en/stable/
823
** "rook for storage via argocd":https://rook.io/
824 58 Nico Schottelius
** haproxy for in IPv6-cluster-IPv4-to-IPv6 proxy via argocd
825
** "kubernetes-secret-generator for in cluster secrets":https://github.com/mittwald/kubernetes-secret-generator
826
** "ungleich-certbot managing certs and nginx":https://hub.docker.com/repository/docker/ungleich/ungleich-certbot
827
828 57 Nico Schottelius
829
h3. ungleich kubernetes infrastructure v4 (2021-09)
830
831 54 Nico Schottelius
* rook is configured via manifests instead of using the rook-ceph-cluster helm chart
832 1 Nico Schottelius
* The rook operator is still being installed via helm
833 35 Nico Schottelius
834 57 Nico Schottelius
h3. ungleich kubernetes infrastructure v3 (2021-07)
835 1 Nico Schottelius
836 10 Nico Schottelius
* rook is now installed via helm via argocd instead of directly via manifests
837 28 Nico Schottelius
838 57 Nico Schottelius
h3. ungleich kubernetes infrastructure v2 (2021-05)
839 28 Nico Schottelius
840
* Replaced fluxv2 from ungleich k8s v1 with argocd
841 1 Nico Schottelius
** argocd can apply helm templates directly without needing to go through Chart releases
842 28 Nico Schottelius
* We are also using argoflow for build flows
843
* Planned to add "kaniko":https://github.com/GoogleContainerTools/kaniko for image building
844
845 57 Nico Schottelius
h3. ungleich kubernetes infrastructure v1 (2021-01)
846 28 Nico Schottelius
847
We are using the following components:
848
849
* "Calico as a CNI":https://www.projectcalico.org/ with BGP, IPv6 only, no encapsulation
850
** Needed for basic networking
851
* "kubernetes-secret-generator":https://github.com/mittwald/kubernetes-secret-generator for creating secrets
852
** Needed so that secrets are not stored in the git repository, but only in the cluster
853
* "ungleich-certbot":https://hub.docker.com/repository/docker/ungleich/ungleich-certbot
854
** Needed to get letsencrypt certificates for services
855
* "rook with ceph rbd + cephfs":https://rook.io/ for storage
856
** rbd for almost everything, *ReadWriteOnce*
857
** cephfs for smaller things, multi access *ReadWriteMany*
858
** Needed for providing persistent storage
859
* "flux v2":https://fluxcd.io/
860
** Needed to manage resources automatically