Project

General

Profile

The ungleich kubernetes infrastructure » History » Version 53

Nico Schottelius, 10/18/2021 10:52 AM

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 48 Nico Schottelius
| Cluster         | Purpose/Setup     | Maintainer   | Master(s)                                                | argo | rook | last verified |
13
| c0.k8s.ooo      | Dev               | -            | UNUSED                                                   |      |      |    2021-10-05 |
14
| c1.k8s.ooo      | Dev p6 VM         | Nico         | 2a0a-e5c0-2-11-0-62ff-fe0b-1a3d.k8s-1.place6.ungleich.ch |      |      |    2021-10-05 |
15
| c2.k8s.ooo      | Dev p7 HW         | Nico         | server47 server53 server54                               | x    | x    |    2021-10-05 |
16
| c3.k8s.ooo      | Test p7 PI        | -            | UNUSED                                                   |      |      |    2021-10-05 |
17
| c4.k8s.ooo      | Dev2 p7 HW        | Fran/Jin-Guk | server52 server53 server54                               |      |      |             - |
18
| c5.k8s.ooo      | Dev p6 VM Amal    | Nico/Amal    | 2a0a-e5c0-2-11-0-62ff-fe0b-1a46.k8s-1.place6.ungleich.ch |      |      |               |
19
| c6.k8s.ooo      | Dev p6 VM Jin-Guk | Jin-Guk      |                                                          |      |      |               |
20
| [[p6.k8s.ooo]]  | production        |              | server67 server69 server71                               | x    | x    |    2021-10-05 |
21
| [[p10.k8s.ooo]] | production        |              | server63 server65 server83                               | x    | x    |    2021-10-05 |
22
|                 |                   |              |                                                          |      |      |               |
23
24 21 Nico Schottelius
25 1 Nico Schottelius
h2. General architecture and components overview
26
27
* All k8s clusters are IPv6 only
28
* We use BGP peering to propagate podcidr and serviceCidr networks to our infrastructure
29
* The main public testing repository is "ungleich-k8s":https://code.ungleich.ch/ungleich-public/ungleich-k8s
30 18 Nico Schottelius
** Private configurations are found in the **k8s-config** repository
31 1 Nico Schottelius
32
h3. Cluster types
33
34 28 Nico Schottelius
| **Type/Feature**            | **Development**                | **Production**         |
35
| Min No. nodes               | 3 (1 master, 3 worker)         | 5 (3 master, 3 worker) |
36
| Recommended minimum         | 4 (dedicated master, 3 worker) | 8 (3 master, 5 worker) |
37
| Separation of control plane | optional                       | recommended            |
38
| Persistent storage          | required                       | required               |
39
| Number of storage monitors  | 3                              | 5                      |
40 1 Nico Schottelius
41 43 Nico Schottelius
h2. General k8s operations
42 1 Nico Schottelius
43 46 Nico Schottelius
h3. Cheat sheet / external great references
44
45
* "kubectl cheatsheet":https://kubernetes.io/docs/reference/kubectl/cheatsheet/
46
47 36 Nico Schottelius
h3. Get the argocd credentials
48
49
<pre>
50 37 Nico Schottelius
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo ""
51 36 Nico Schottelius
</pre>
52
53 44 Nico Schottelius
h3. Get the cluster admin.conf
54
55
* On the masters of each cluster you can find the file @/etc/kubernetes/admin.conf@
56
* To be able to administrate the cluster you can copy the admin.conf to your local machine
57
* Multi cluster debugging can very easy if you name the config ~/cX-admin.conf (see example below)
58
59
<pre>
60
% scp root@server47.place7.ungleich.ch:/etc/kubernetes/admin.conf ~/c2-admin.conf
61
% export KUBECONFIG=~/c2-admin.conf    
62
% kubectl get nodes
63
NAME       STATUS                     ROLES                  AGE   VERSION
64
server47   Ready                      control-plane,master   82d   v1.22.0
65
server48   Ready                      control-plane,master   82d   v1.22.0
66
server49   Ready                      <none>                 82d   v1.22.0
67
server50   Ready                      <none>                 82d   v1.22.0
68
server59   Ready                      control-plane,master   82d   v1.22.0
69
server60   Ready,SchedulingDisabled   <none>                 82d   v1.22.0
70
server61   Ready                      <none>                 82d   v1.22.0
71
server62   Ready                      <none>                 82d   v1.22.0               
72
</pre>
73
74 18 Nico Schottelius
h3. Installing a new k8s cluster
75 8 Nico Schottelius
76 9 Nico Schottelius
* Decide on the cluster name (usually *cX.k8s.ooo*), X counting upwards
77 28 Nico Schottelius
** Using pXX.k8s.ooo for production clusters of placeXX
78 9 Nico Schottelius
* Use cdist to configure the nodes with requirements like crio
79
* Decide between single or multi node control plane setups (see below)
80 28 Nico Schottelius
** Single control plane suitable for development clusters
81 9 Nico Schottelius
82 28 Nico Schottelius
Typical init procedure:
83 9 Nico Schottelius
84 28 Nico Schottelius
* Single control plane: @kubeadm init --config bootstrap/XXX/kubeadm.yaml@
85
* Multi control plane (HA): @kubeadm init --config bootstrap/XXX/kubeadm.yaml --upload-certs@
86 10 Nico Schottelius
87 29 Nico Schottelius
h3. Deleting a pod that is hanging in terminating state
88
89
<pre>
90
kubectl delete pod <PODNAME> --grace-period=0 --force --namespace <NAMESPACE>
91
</pre>
92
93
(from https://stackoverflow.com/questions/35453792/pods-stuck-in-terminating-status)
94
95 42 Nico Schottelius
h3. Listing nodes of a cluster
96
97
<pre>
98
[15:05] bridge:~% kubectl get nodes
99
NAME       STATUS   ROLES                  AGE   VERSION
100
server22   Ready    <none>                 52d   v1.22.0
101
server23   Ready    <none>                 52d   v1.22.2
102
server24   Ready    <none>                 52d   v1.22.0
103
server25   Ready    <none>                 52d   v1.22.0
104
server26   Ready    <none>                 52d   v1.22.0
105
server27   Ready    <none>                 52d   v1.22.0
106
server63   Ready    control-plane,master   52d   v1.22.0
107
server64   Ready    <none>                 52d   v1.22.0
108
server65   Ready    control-plane,master   52d   v1.22.0
109
server66   Ready    <none>                 52d   v1.22.0
110
server83   Ready    control-plane,master   52d   v1.22.0
111
server84   Ready    <none>                 52d   v1.22.0
112
server85   Ready    <none>                 52d   v1.22.0
113
server86   Ready    <none>                 52d   v1.22.0
114
</pre>
115
116
117 41 Nico Schottelius
h3. Removing / draining a node
118
119
Usually @kubectl drain server@ should do the job, but sometimes we need to be more aggressive:
120
121
<pre>
122
kubectl drain --delete-emptydir-data --ignore-daemonsets server23
123 42 Nico Schottelius
</pre>
124
125
h3. Readding a node after draining
126
127
<pre>
128
kubectl uncordon serverXX
129 1 Nico Schottelius
</pre>
130 43 Nico Schottelius
131 50 Nico Schottelius
h3. (Re-)joining worker nodes after creating the cluster
132 49 Nico Schottelius
133
* We need to have an up-to-date token
134
* We use different join commands for the workers and control plane nodes
135
136
Generating the join command on an existing control plane node:
137
138
<pre>
139
kubeadm token create --print-join-command
140
</pre>
141
142 50 Nico Schottelius
h3. (Re-)joining control plane nodes after creating the cluster
143 1 Nico Schottelius
144 50 Nico Schottelius
* We generate the token again
145
* We upload the certificates
146
* We need to combine/create the join command for the control plane node
147
148
Example session:
149
150
<pre>
151
% kubeadm token create --print-join-command
152
kubeadm join p10-api.k8s.ooo:6443 --token xmff4i.ABC --discovery-token-ca-cert-hash sha256:longhash 
153
154
% kubeadm init phase upload-certs --upload-certs
155
[upload-certs] Storing the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace
156
[upload-certs] Using certificate key:
157
CERTKEY
158
159
# Then we use these two outputs on the joining node:
160
161
kubeadm join p10-api.k8s.ooo:6443 --token xmff4i.ABC --discovery-token-ca-cert-hash sha256:longhash --control-plane --certificate-key CERTKEY
162
</pre>
163
164
Commands to be used on a control plane node:
165
166
<pre>
167
kubeadm token create --print-join-command
168
kubeadm init phase upload-certs --upload-certs
169
</pre>
170
171
Commands to be used on the joining node:
172
173
<pre>
174
JOINCOMMAND --control-plane --certificate-key CERTKEY
175
</pre>
176 49 Nico Schottelius
177 51 Nico Schottelius
SEE ALSO
178
179
* https://stackoverflow.com/questions/63936268/how-to-generate-kubeadm-token-for-secondary-control-plane-nodes
180
* https://blog.scottlowe.org/2019/08/15/reconstructing-the-join-command-for-kubeadm/
181
182 53 Nico Schottelius
h3. How to fix etcd does not start when rejoining a kubernetes cluster as a control plane
183 52 Nico Schottelius
184
If during the above step etcd does not come up, @kubeadm join@ can hang as follows:
185
186
<pre>
187
[control-plane] Creating static Pod manifest for "kube-apiserver"                                                              
188
[control-plane] Creating static Pod manifest for "kube-controller-manager"                                                     
189
[control-plane] Creating static Pod manifest for "kube-scheduler"                                                              
190
[check-etcd] Checking that the etcd cluster is healthy                                                                         
191
error execution phase check-etcd: etcd cluster is not healthy: failed to dial endpoint https://[2a0a:e5c0:10:1:225:b3ff:fe20:37
192
8a]:2379 with maintenance client: context deadline exceeded                                                                    
193
To see the stack trace of this error execute with --v=5 or higher         
194
</pre>
195
196
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.
197
198
To fix this we do:
199
200
* Find a working etcd pod
201
* Find the etcd members / member list
202
* Remove the etcd member that we want to re-join the cluster
203
204
205
<pre>
206
# Find the etcd pods
207
kubectl -n kube-system get pods -l component=etcd,tier=control-plane
208
209
# Get the list of etcd servers with the member id 
210
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
211
212
# Remove the member
213
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
214
</pre>
215
216
Sample session:
217
218
<pre>
219
[10:48] line:~% kubectl -n kube-system get pods -l component=etcd,tier=control-plane
220
NAME            READY   STATUS    RESTARTS     AGE
221
etcd-server63   1/1     Running   0            3m11s
222
etcd-server65   1/1     Running   3            7d2h
223
etcd-server83   1/1     Running   8 (6d ago)   7d2h
224
[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
225
356891cd676df6e4, started, server65, https://[2a0a:e5c0:10:1:225:b3ff:fe20:375c]:2380, https://[2a0a:e5c0:10:1:225:b3ff:fe20:375c]:2379, false
226
371b8a07185dee7e, started, server63, https://[2a0a:e5c0:10:1:225:b3ff:fe20:378a]:2380, https://[2a0a:e5c0:10:1:225:b3ff:fe20:378a]:2379, false
227
5942bc58307f8af9, started, server83, https://[2a0a:e5c0:10:1:3e4a:92ff:fe79:bb98]:2380, https://[2a0a:e5c0:10:1:3e4a:92ff:fe79:bb98]:2379, false
228
229
[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
230
Member 371b8a07185dee7e removed from cluster e3c0805f592a8f77
231
232
</pre>
233
234
SEE ALSO
235
236
* We found the solution using https://stackoverflow.com/questions/67921552/re-installed-node-cannot-join-kubernetes-cluster
237
238 43 Nico Schottelius
h2. Rook / Ceph Related Operations
239
240
h3. Inspecting the logs of a specific server
241
242
<pre>
243
# Get the related pods
244
kubectl -n rook-ceph get pods -l app=rook-ceph-osd-prepare 
245
...
246
247
# Inspect the logs of a specific pod
248
kubectl -n rook-ceph logs -f rook-ceph-osd-prepare-server23--1-444qx
249
250
</pre>
251
252
h3. Triggering server prepare / adding new osds
253
254
The rook-ceph-operator triggers/watches/creates pods to maintain hosts. To trigger a full "re scan", simply delete that pod:
255
256
<pre>
257
kubectl -n rook-ceph delete pods -l app=rook-ceph-operator
258
</pre>
259
260
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.
261
262
h3. Removing an OSD
263
264
* See "Ceph OSD Management":https://rook.io/docs/rook/v1.7/ceph-osd-mgmt.html
265 41 Nico Schottelius
266 1 Nico Schottelius
h2. Infrastructure versions
267 35 Nico Schottelius
268
h3. ungleich kubernetes infrastructure v3
269
270
* rook is now installed via helm via argocd instead of directly via manifests
271 10 Nico Schottelius
272 28 Nico Schottelius
h3. ungleich kubernetes infrastructure v2
273
274
* Replaced fluxv2 from ungleich k8s v1 with argocd
275
** argocd can apply helm templates directly without needing to go through Chart releases
276
* We are also using argoflow for build flows
277
* Planned to add "kaniko":https://github.com/GoogleContainerTools/kaniko for image building
278
279
h3. ungleich kubernetes infrastructure v1
280
281
We are using the following components:
282
283
* "Calico as a CNI":https://www.projectcalico.org/ with BGP, IPv6 only, no encapsulation
284
** Needed for basic networking
285
* "kubernetes-secret-generator":https://github.com/mittwald/kubernetes-secret-generator for creating secrets
286
** Needed so that secrets are not stored in the git repository, but only in the cluster
287
* "ungleich-certbot":https://hub.docker.com/repository/docker/ungleich/ungleich-certbot
288
** Needed to get letsencrypt certificates for services
289
* "rook with ceph rbd + cephfs":https://rook.io/ for storage
290
** rbd for almost everything, *ReadWriteOnce*
291
** cephfs for smaller things, multi access *ReadWriteMany*
292
** Needed for providing persistent storage
293
* "flux v2":https://fluxcd.io/
294
** Needed to manage resources automatically