Skip to content

Commit df21836

Browse files
committed
ckad lab init commit
Signed-off-by: Ken Sipe <[email protected]>
0 parents  commit df21836

18 files changed

+650
-0
lines changed

Readme.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Labs for Certified Kubernetes Application Developer (CKAD)
2+
3+
These labs support training necessary for passing the Certified Kubernetes Applcation Developer (CKAD) Test.
4+
5+
## Requirements
6+
7+
* git
8+
* Kubernetes 1.15+ cluster
9+
* [Kubernetes in Docker (KinD)](https://github.com/kubernetes-sigs/kind) **note:** v0.7.0 used for lab creation
10+
* [Minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/)
11+
* curl or httpie
12+
13+
## Notes:
14+
15+
Common `alias k=kubectl`
16+
17+
18+
## Labs
19+
20+
### Lab 1: [Kind Setup and Kubernetes Basics](lab1.md)
21+
22+
### Lab 2: [Core Concepts](lab2.md)
23+
24+
### Lab 3: [Configuration (ENV, Configs, Secrets, Tolerations and Affinity)]((lab3.md))
25+
26+
### Lab 4: [Pod Design (Labels, Deployments, Jobs and Crons)](lab4.md)
27+
28+
### Lab 5: [Observability](lab5.md)
29+
30+
### Lab 6: [Services and Networking](lab6.md)
31+
32+
### Lab 7: [State Persistence](lab7.md)
33+
34+
35+
** Multi-container does not have a specific lab
36+
37+
## Tips and References
38+
39+
* [Tips](tips.md)
40+
* [Bookmarks](bookmarks.html)

bookmarks.html

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE NETSCAPE-Bookmark-file-1>
2+
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
3+
<TITLE>Bookmarks</TITLE>
4+
<H1>Bookmarks</H1>
5+
<DL><p>
6+
<DT><H3 ADD_DATE="1497301221" LAST_MODIFIED="1578373289" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks Bar</H3>
7+
<DL><p>
8+
<DT><H3 ADD_DATE="1578373157" LAST_MODIFIED="1578748454">ckad</H3>
9+
<DL><p>
10+
<DT><A HREF="https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/#list-containers-by-pod" >List All Container Images Running in a Cluster - Kubernetes</A>
11+
<DT><A HREF="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" >Rewrite - NGINX Ingress Controller</A>
12+
<DT><A HREF="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistent-volumes" >Persistent Volumes - Kubernetes</A>
13+
<DT><A HREF="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#claims-as-volumes" >Persistent Volumes - Kubernetes</A>
14+
<DT><A HREF="https://kubernetes.io/docs/concepts/storage/volumes/#example-pod-2" >Volumes - Kubernetes</A>
15+
<DT><A HREF="https://kubernetes.io/docs/concepts/services-networking/network-policies/" >Network Policies - Kubernetes</A>
16+
<DT><A HREF="https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/" >Taints and Tolerations - Kubernetes</A>
17+
<DT><A HREF="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity" >Affinity Pods to Nodes - Kubernetes</A>
18+
<DT><A HREF="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/" >Jobs - Run to Completion - Kubernetes</A>
19+
<DT><A HREF="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" >CronJob - Kubernetes</A>
20+
<DT><A HREF="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#example" >ReplicaSet - Kubernetes</A>
21+
<DT><A HREF="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment" >Deployments - Kubernetes</A>
22+
<DT><A HREF="https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/" >Configure Service Accounts for Pods - Kubernetes</A>
23+
<DT><A HREF="https://kubernetes.io/docs/concepts/configuration/secret/#creating-a-secret-manually" >Secrets - Kubernetes</A>
24+
<DT><A HREF="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-configmaps-from-directories" >Configure a Pod to Use a ConfigMap - Kubernetes</A>
25+
<DT><A HREF="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#interacting-with-running-pods" >kubectl Cheat Sheet - Kubernetes</A>
26+
<DT><A HREF="https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-memory" >Managing Compute Resources for Containers - Kubernetes</A>
27+
<DT><A HREF="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#rolling-back-a-deployment" >Deployments - Kubernetes</A>
28+
<DT><A HREF="https://kubernetes.io/docs/concepts/services-networking/ingress/" >Ingress - Kubernetes</A>
29+
<DT><A HREF="https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/" >Get a Shell to a Running Container - Kubernetes</A>
30+
<DT><A HREF="https://kubernetes.io/docs/concepts/configuration/secret/#creating-a-secret-using-kubectl-create-secret" >Secrets Create- Kubernetes</A>
31+
<DT><A HREF="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolume" >PersistentVolume hostpath - Kubernetes</A>
32+
<DT><A HREF="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/" >Configure Liveness, Readiness and Startup Probes - Kubernetes</A>
33+
</DL><p>
34+
</DL><p>
35+
</DL><p>

kind-3.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Cluster
2+
apiVersion: kind.sigs.k8s.io/v1alpha3
3+
nodes:
4+
- role: control-plane
5+
- role: worker
6+
- role: worker

lab1.md

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Lab Kind, VI and YAML
2+
3+
## Objective
4+
5+
The focus of this lab is to become familar with kubernetes through the use of the kind kubernetes environemnt.
6+
7+
1. Start cluster
8+
9+
`kind create cluster`
10+
11+
```bash
12+
kind create cluster
13+
Creating cluster "kind" ...
14+
✓ Ensuring node image (kindest/node:v1.17.0) 🖼
15+
✓ Preparing nodes 📦
16+
✓ Writing configuration 📜
17+
⠊⠁ Starting control-plane 🕹️ on
18+
✓ Starting control-plane 🕹️
19+
✓ Installing CNI 🔌
20+
✓ Installing StorageClass 💾
21+
Set kubectl context to "kind-kind"
22+
You can now use your cluster with:
23+
24+
kubectl cluster-info --context kind-kind
25+
26+
Have a nice day! 👋
27+
```
28+
29+
2. Setup the alias `alias k=kubectl`
30+
31+
3. Get the kube version with `kubectl`
32+
33+
```
34+
k version
35+
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.6", GitCommit:"dff82dc0de47299ab66c83c626e08b245ab19037", GitTreeState:"clean", BuildDate:"2020-07-16T00:04:31Z", GoVersion:"go1.14.4", Compiler:"gc", Platform:"darwin/amd64"}
36+
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2020-01-14T00:09:19Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
37+
```
38+
39+
4. api-resouces
40+
41+
Lets get a list of resources from `kubectl`
42+
`k api-resources`
43+
44+
Which resources are namespaced? and which are cluster scoped?
45+
46+
For cluster scoped: `k api-resources --namespaced=false`
47+
48+
What is the shortname for `PodSecurityPolicy`?
49+
50+
5. Explaining Resources
51+
52+
Explain is a great way to understand the defined structure of a resource or kind. This is accomplish through `k explain <kind>`
53+
54+
`k explain ns`
55+
56+
Almost all resources at this high level report roughly the same apiVersion, kind, metadata, spec, status information. In order to get the full structure of this kind use the `--recursive` flag.
57+
58+
`k explain ns --recursive`
59+
60+
Notice the status field `phase`. Let's display that as an output.
61+
62+
`k get ns -o custom-columns=NAME:.metadata.name,PHASE:.status.phase`
63+
64+
Example output:
65+
```
66+
NAME PHASE
67+
default Active
68+
kube-node-lease Active
69+
kube-public Active
70+
kube-system Active
71+
local-path-storage Active
72+
```
73+
74+
Explain is incredibly useful in understanding the structure of types deployed in kubernetes.
75+
76+
6. Increase verbosity
77+
78+
Get the namespaces again using the `-v #` such as `-v 6`
79+
80+
```
81+
k get ns -v 6
82+
I0821 08:59:23.530922 5867 loader.go:375] Config loaded from file: /Users/kensipe/.kube/config
83+
I0821 08:59:23.546835 5867 round_trippers.go:443] GET https://127.0.0.1:32769/api/v1/namespaces?limit=500 200 OK in 11 milliseconds
84+
```
85+
86+
increase to max value of `9`
87+
88+
7. Setup VI
89+
90+
Install if missing...
91+
92+
` vi ~/.vimrc`
93+
94+
```
95+
:set number
96+
:set et
97+
:set sw=2 ts=2 sts=2
98+
```
99+
100+
8. VI Working with YAML
101+
102+
```
103+
k create deployment nginx --image=nginx --dry-run -o yaml > pod.yaml
104+
105+
vi pod.yaml
106+
```
107+
108+
## Summary
109+
110+
At the conclusion of this lab, you should be familar with starting and delete a kind cluster along with interact with the cluster via `kubectl`. Additionally, you should be comfortable with working with VI, setting up tab stops and work with `kubectl` to create YAML manifests.

lab2-1.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: lab2-1
5+
spec:
6+
containers:
7+
- image: foo
8+
name: nginx

lab2.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Lab Kube Basics
2+
3+
## Objective
4+
5+
The focus of this lab is to become familar the different kubernetes objects that affect Pods. This includes namespaces and deployments.
6+
7+
1. In 1 terminal or tab, watch for pods
8+
9+
`k get pod -w`
10+
11+
2. Create a pod imperatively
12+
13+
`k run nginx --image nginx`
14+
15+
Watch pod cycle thru statuses
16+
17+
3. Without examining the yaml... deploy lab2-1.yaml to cluster:
18+
19+
`k apply -f lab2-1.yaml`
20+
21+
Did it deploy? What is the status? Why?
22+
23+
Edit pod and fix
24+
25+
4. Look a entire cluster
26+
27+
`k get all`
28+
29+
**note:** This is a handy command to understand the entire environment for a test question.
30+
31+
5. Delete all pods
32+
33+
`k delete pod --all`
34+
35+
6. Create a ReplicaSet for nginx pod with 3 replicas
36+
37+
image: nginx
38+
39+
7. Delete and Create Deployment for nginx Pod with 3 replicas
40+
41+
image: nginx
42+
43+
8. Update the Deployment Image to `nginx:1.7.9`
44+
45+
9. Create namespace `foo`
46+
47+
10. Change context use `foo` is the default context
48+
49+
50+
## Summary
51+
52+
After lab 1 and 2, you should be comfortable with create and deleting pods, along with creating ReplicaSets and Deployments.

lab3.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Lab CKAD Configuration
2+
3+
## Objective
4+
5+
The focus of this lab is to become familar with quickly starting a pod imperatively. This lab is also setup to understand how to debug and env either by starting a shell in a pod or by executing a pod with a specific command.
6+
7+
1. Execute an imperative command to see what is in a standard Pods ENV
8+
9+
```
10+
kubectl run busybox --image=busybox --command --restart=Never -- env
11+
```
12+
13+
How do you see the output?
14+
15+
2. Add an ENV to the pod from step 1. (you'll like to add it to the yaml and replace)
16+
17+
3. Create a config map with the key `APP_ENV` and value of `dev`
18+
19+
4. Create a pod that shows the mapping
20+
21+
5. Create a namespace foo, what is the value of the service account token?
22+
23+
6. Start a shell in a pod (start an nginx pod if one isn't running) and view the mounted token.
24+
25+
`k exec -it nginx /bin/bash`
26+
27+
7. Recreate cluster with multi-nodes and run nginx pod
28+
29+
```
30+
# needs kind and kubectl on path
31+
./setup-lab3.sh
32+
```
33+
wait for "Lab 3 is Ready"
34+
35+
Launch a standard pod: `k run nginx --image nginx`
36+
37+
What is the status? Why?
38+
39+
Fix the pod.
40+
41+
8. What does the following command do?
42+
43+
`kubectl patch nodes kind-worker -p '{"spec":{"taints":[]}}'`
44+
45+
9. Node `kind-worker` has a label that doesn't exist on `kind-worker2`. Create a pod that has node affinity to this node `kind-worker` passed on this label.

lab4.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Lab CKAD Pod Design
2+
3+
## Objective
4+
5+
The focus of this lab is to be able to debug and access a cluster by get a pods yaml or by inspecting it's "description" through `describe`. Additionally, you will rollout a deployment and roll it back.
6+
7+
1. Setup Lab 4 by running `./setup-lab4.sh`. (without looking at sipt yet)
8+
9+
2. Question to answer about cluster:
10+
11+
How many pods have the label `app=front-end`?
12+
How many pods in total?
13+
How many pods in `foo` namespace?
14+
How many pods with label `app=front-end` in entire cluster?
15+
Display all of them?
16+
17+
3. Create and run Deployment file which matches the nginx pods with the `app=front-end` label with replicas = 4.
18+
19+
4. Change the image to `nginx:1.9.1` for the deployment
20+
21+
hint: `k set image deploy nginx nginx=nginx:1.9.1`
22+
23+
5. Looking at deployment rollout history
24+
25+
6. Undo the last rollout
26+
27+
7. Create a Job that will run every 2 mins and print to STDOUT a random number. What is the value of the 1st random number?
28+
29+
hint: `shuf -i 0-999 -n1` will print a random number 0 - 999
30+
hint: `*/2 * * * *` is a cron for every 2 mins

lab5-1.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: webapp
5+
labels:
6+
name: webapp
7+
spec:
8+
containers:
9+
- name: webapp
10+
image: nginx
11+
ports:
12+
- containerPort: 80
13+
readinessProbe:
14+
httpGet:
15+
path: /
16+
port: 8080

lab5.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Lab CKAD Observability
2+
3+
## Objective
4+
5+
The focus of this lab is to become familar with pod readiness and liveliness.
6+
7+
1. Clear all pods
8+
9+
`k delete pod --all`
10+
11+
2. Run the following pod:
12+
13+
`kubectl run box --image=busybox -- /bin/sh -c 'i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 1; done'`
14+
15+
3. Read the logs of this pod
16+
17+
4. IF there were more than 1 container... how would you view logs of this container?
18+
19+
5. Without looking at the file, apply the manifest `lab5-1.yaml`
20+
21+
6. What is the status of the pod?
22+
23+
7. Is it ready?
24+
25+
8. Fix any issue
26+
27+

0 commit comments

Comments
 (0)