Skip to content

Commit a649032

Browse files
committed
Final slides for 20231018
1 parent a48f868 commit a649032

17 files changed

+400
-109
lines changed

120_kubernetes/ci_cd/hpa.demo

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Horizontal Pod Autoscaler (HPA)
2+
3+
# Deploy metrics-server
4+
helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
5+
helm upgrade --install --namespace=kube-system metrics-server metrics-server/metrics-server \
6+
--set args[0]=--kubelet-insecure-tls
7+
8+
# Deploy nginx
9+
helm upgrade --install my-nginx bitnami/nginx \
10+
--set service.type=ClusterIP \
11+
--set resources.requests.cpu=50m \
12+
--set autoscaling.enabled=true \
13+
--set autoscaling.minReplicas=2 \
14+
--set autoscaling.maxReplicas=10 \
15+
--set autoscaling.targetCPU=20
16+
17+
# Monitor replicas
18+
watch kubectl get pods
19+
20+
# Monitor HPA
21+
watch kubectl get hpa
22+
23+
# Create load
24+
kubectl run -it --rm --image=cmd.cat/bash/curl --command -- bash
25+
while true; do curl -so /dev/null http://my-nginx; done

120_kubernetes/ci_cd/inside.drawio.svg

+11-12
Loading

120_kubernetes/ci_cd/side-by-side.drawio.svg

+9-9
Loading

120_kubernetes/ci_cd/slides.md

+82-39
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,76 @@
22

33
![](images/automate_all_the_things.webp) <!-- .element: style="float: right; width: 40%;" -->
44

5-
XXX version control because YAML is text
5+
Handle Ops stuff like a developer would
66

7-
XXX separate instance for testing
7+
Everything in version control...
88

9-
XXX PR/MR for Ops changes
9+
...because YAML is text
1010

11-
XXX automated tests
11+
Use branches for stages (e.g. dev, qa, live)
12+
13+
Pipeline to deploy to stages
14+
15+
Integrate changes using pull/merge requests
16+
17+
Add automated tests to pipeline
18+
19+
Changes are pushed into Kubernetes cluster
1220

1321
---
1422

1523
## Cluster access 1/
1624

1725
Different approches to access the cluster from a pipeline
1826

27+
![](120_kubernetes/ci_cd/inside.drawio.svg) <!-- .element: style="float: right; width: 20%; margin-top: 1em;" -->
28+
1929
### Inside cluster
2030

2131
Pipeline runs inside the target cluster
2232

23-
![](120_kubernetes/ci_cd/inside.drawio.svg) <!-- .element: style="width: 50%;" -->
24-
2533
Direct API access with RBAC
2634

27-
### Demo
35+
![](120_kubernetes/ci_cd/side-by-side.drawio.svg) <!-- .element: style="float: right; width: 20%; margin-top: 1em;" -->
2836

29-
XXX
37+
### Next to cluster
3038

31-
---
39+
Pipeline runs somewhere else...
3240

33-
## Cluster access 2/2
41+
...or does not have direct access to Kubernetes API
3442

35-
Different approches to access the cluster from a pipeline
43+
Pipeline fetches (encrypted) kubeconfig
3644

37-
### Next to cluster
45+
---
3846

39-
Pipeline runs somewhere else...
47+
## Useful tools
4048

41-
...or does not have direct access to Kubernetes API
49+
Validate YAML using `yamllint` [](https://github.com/adrienverge/yamllint)
4250

43-
![](120_kubernetes/ci_cd/side-by-side.drawio.svg) <!-- .element: style="width: 50%;" -->
51+
```bash
52+
helm template my-ntpd ../helm/ntpd/ >ntpd.yaml
53+
yamllint ntpd.yaml
54+
cat <<EOF >.yamllint
55+
rules:
56+
indentation:
57+
indent-sequences: consistent
58+
EOF
59+
yamllint ntpd.yaml
60+
```
4461

45-
Pipeline fetches (encrypted) kubeconfig
62+
Validate against official schemas using `kubeval` [](https://github.com/instrumenta/kubeval):
4663

47-
### Demo
64+
```bash
65+
kubeval ntpd.yaml
66+
```
4867

49-
XXX
68+
Static analysis using `kube-linter` [](https://github.com/stackrox/kube-linter)
69+
70+
```bash
71+
kube-linter lint ntpd.yaml
72+
kube-linter lint ../helm/ntpd/
73+
kube-linter checks list
74+
```
5075

5176
---
5277

@@ -121,8 +146,6 @@ Resource requests are important for scheduling
121146

122147
Limits are important for eviction
123148

124-
XXX usage
125-
126149
### You want `(requests == limits)`
127150

128151
Pods will not be evicted...
@@ -162,7 +185,10 @@ Next pipeline run will fail because resource already exists
162185
Instead create resource definition on-the-fly:
163186

164187
```bash
165-
kubectl create secret --dry-run=client \
188+
kubectl create secret generic foo \
189+
--from-literal=bar=baz \
190+
--dry-run=client \
191+
--output=yaml \
166192
| kubectl apply -f -
167193
```
168194

@@ -179,8 +205,17 @@ Do not use sleep after apply, scale, delete
179205
Let `kubectl` do the waiting:
180206

181207
```bash
182-
kubectl wait --for=condition=ready pod/foo
183-
kubectl rollout status deployment bar --timeout=15m
208+
helm upgrade --install my-nginx bitnami/nginx \
209+
--set service.type=ClusterIP
210+
kubectl rollout status deployment my-nginx --timeout=15m
211+
kubectl wait pods \
212+
--for=condition=ready \
213+
--selector app.kubernetes.io/instance=my-nginx
214+
```
215+
216+
Works for jobs as well:
217+
218+
```bash
184219
kubectl wait --for=condition=complete job/baz
185220
```
186221

@@ -195,13 +230,22 @@ Finding the pod name is error prone
195230
Filter by label:
196231

197232
```bash
198-
kubectl delete pod --selector app=foo,component=db
233+
helm upgrade --install my-nginx bitnami/nginx \
234+
--set service.type=ClusterIP \
235+
--set replicaCount=2
236+
kubectl delete pod --selector app.kubernetes.io/instance=my-nginx
237+
```
238+
239+
Show logs of the first pod of a deployment:
240+
241+
```bash
242+
kubectl logs deployment/my-nginx
199243
```
200244

201-
Show logs of a deployment with a single pod:
245+
Show logs of multiple pods at once with stern [](https://github.com/stern/stern):
202246

203247
```bash
204-
kubectl logs deployment/foo
248+
stern --selector app.kubernetes.io/instance=my-nginx
205249
```
206250

207251
---
@@ -215,15 +259,24 @@ When a pod is broken, it can be investigated
215259
Remove a label to exclude it from `ReplicaSet`, `Deployment`, `Service`
216260

217261
```bash
218-
kubectl label pod foo-12345 app-
262+
helm upgrade --install my-nginx bitnami/nginx \
263+
--set service.type=ClusterIP \
264+
--set replicaCount=2
265+
kubectl get pods -l app.kubernetes.io/instance=my-nginx -o name \
266+
| head -n 1 \
267+
| xargs -I{} kubectl label {} app.kubernetes.io/instance-
219268
```
220269

221270
`ReplicaSet` replaces missing pod
222271

223-
Pod `foo-12345` can be investigated
224-
225272
Remove after troubleshooting
226273

274+
```bash
275+
kubectl logs --selector '!app.kubernetes.io/instance'
276+
kubectl delete pod \
277+
-l 'app.kubernetes.io/name=nginx,!app.kubernetes.io/instance'
278+
```
279+
227280
---
228281

229282
## Lessons Learnt 5/
@@ -267,13 +320,3 @@ Doing updates regularly is easier
267320
Automerge for patches can help stay on top of things
268321

269322
Automated tests help decide whether an update is safe
270-
271-
---
272-
273-
## Lessons Learnt 7/7
274-
275-
### Image tags
276-
277-
XXX immutable tags
278-
279-
XXX version pinning

120_kubernetes/helm/chart.demo

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Create chart
2+
3+
# Check files
4+
cat Chart.yaml
5+
cat templates/daemonset.yaml
6+
cat templates/_helpers.tpl
7+
8+
# Lint chart
9+
helm lint .
10+
11+
# Create resources
12+
helm template my-ntpd .
13+
14+
# Check resources
15+
helm template my-ntpd . \
16+
| kubectl apply --dry-run=server -f -
17+
18+
# Package chart (upload to repository is manual)
19+
helm package .
20+
21+
# Push to OCI registry
22+
helm push ntpd-1.0.0.tgz oci://nicholasdille/ntpd

120_kubernetes/helm/helm.demo

+35-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
11
# Helm
22

3-
## XXX
4-
echo
3+
# Add repository
4+
helm repo add bitnami https://charts.bitnami.com/bitnami
5+
6+
# Search for chart
7+
helm search repo bitnami/nginx
8+
9+
# Search for chart versions
10+
helm search repo bitnami/nginx --versions
11+
12+
# Install chart
13+
helm install my-nginx bitnami/nginx
14+
15+
# Check release
16+
helm list
17+
18+
# Check resources
19+
kubectl get all
20+
21+
# Fix service
22+
helm upgrade my-nginx bitnami/nginx --set service.type=ClusterIP
23+
24+
# Check service
25+
kubectl get service my-nginx -o yaml
26+
27+
# Downgrade nginx to stable
28+
helm upgrade my-nginx bitnami/nginx --reuse-values --set image.tag=1.24.0
29+
30+
# Check image tag
31+
kubectl get deployments.apps my-nginx -o yaml | grep image:
32+
33+
# Read values from release
34+
helm get values my-nginx
35+
36+
# Display release history
37+
helm history my-nginx

0 commit comments

Comments
 (0)