|
| 1 | +# CKA (Certified Kubernetes Administrator) |
| 2 | + |
| 3 | +- [CKA (Certified Kubernetes Administrator)](#cka-certified-kubernetes-administrator) |
| 4 | + - [Setup](#setup) |
| 5 | + - [Kubernetes Nodes](#kubernetes-nodes) |
| 6 | + - [Pods](#pods) |
| 7 | + - [Troubleshooting Pods](#troubleshooting-pods) |
| 8 | + - [Namespaces](#namespaces) |
| 9 | + |
| 10 | +## Setup |
| 11 | + |
| 12 | +* Set up Kubernetes cluster. Use on of the following |
| 13 | + 1. Minikube for local free & simple cluster |
| 14 | + 2. Managed Cluster (EKS, GKE, AKS) |
| 15 | + |
| 16 | +* Set aliases |
| 17 | + |
| 18 | +``` |
| 19 | +alias k=kubectl |
| 20 | +alias kd=kubectl delete |
| 21 | +alias kds=kubectl describe |
| 22 | +alias ke=kubectl edit |
| 23 | +alias kr=kubectl run |
| 24 | +alias kg=kubectl get |
| 25 | +``` |
| 26 | + |
| 27 | +## Kubernetes Nodes |
| 28 | + |
| 29 | +<details> |
| 30 | +<summary>Run a command to view all nodes of the cluster</summary><br><b> |
| 31 | + |
| 32 | +`kubectl get nodes` |
| 33 | + |
| 34 | +Note: create an alias (`alias k=kubectl`) and get used to `k get no` |
| 35 | +</b></details> |
| 36 | + |
| 37 | +## Pods |
| 38 | + |
| 39 | +<details> |
| 40 | +<summary>Run a command to view all the pods in current namespace</summary><br><b> |
| 41 | + |
| 42 | +Note: create an alias (`alias k=kubectl`) and get used to `k get po` |
| 43 | +</b></details> |
| 44 | + |
| 45 | +<details> |
| 46 | +<summary>Run a pod called "nginx-test" using the "nginx" image</summary><br><b> |
| 47 | + |
| 48 | +`k run nginx-test --image=nginx` |
| 49 | +</b></details> |
| 50 | + |
| 51 | +<details> |
| 52 | +<summary>Assuming you have a Pod called "nginx-test", how to remove it?</summary><br><b> |
| 53 | + |
| 54 | +`k delete nginx-test` |
| 55 | +</b></details> |
| 56 | + |
| 57 | +<details> |
| 58 | +<summary>In what namespace the <code>etcd</code> pod is running? list the pods in that namespace</summary><br><b> |
| 59 | + |
| 60 | +`k get po -n kube-system` |
| 61 | +</b></details> |
| 62 | + |
| 63 | +<details> |
| 64 | +<summary>List pods from all namespaces</summary><br><b> |
| 65 | + |
| 66 | +`k get po --all-namespaces` |
| 67 | +</b></details> |
| 68 | + |
| 69 | +<details> |
| 70 | +<summary>Write a YAML of a Pod with two containers and use the YAML file to create the Pod (use whatever images you prefer)</summary><br><b> |
| 71 | + |
| 72 | +``` |
| 73 | +cat > pod.yaml <<EOL |
| 74 | +apiVersion: v1 |
| 75 | +kind: Pod |
| 76 | +metadata: |
| 77 | + name: test |
| 78 | +spec: |
| 79 | + containers: |
| 80 | + - image: alpine |
| 81 | + name: alpine |
| 82 | + - image: nginx-unprivileged |
| 83 | + name: nginx-unprivileged |
| 84 | +EOL |
| 85 | +
|
| 86 | +k create -f pod.yaml |
| 87 | +``` |
| 88 | +</b></details> |
| 89 | + |
| 90 | +<details> |
| 91 | +<summary>Create a YAML of a Pod without actually running the Pod with the kubectl command (use whatever image you prefer)</summary><br><b> |
| 92 | + |
| 93 | +`k run some-pod -o yaml --image nginx-unprivileged --dry-run=client > pod.yaml` |
| 94 | +</b></details> |
| 95 | + |
| 96 | +<details> |
| 97 | +<summary>How to test a manifest is valid?</summary><br><b> |
| 98 | + |
| 99 | +with `--dry-run` flag which will not actually create it, but it will test it and you can find this way any syntax issues. |
| 100 | + |
| 101 | +`kubectl create -f YAML_FILE --dry-run` |
| 102 | +</b></details> |
| 103 | + |
| 104 | +### Troubleshooting Pods |
| 105 | + |
| 106 | +<details> |
| 107 | +<summary>You try to run a Pod but see the status "CrashLoopBackOff". What does it means? How to identify the issue?</summary><br><b> |
| 108 | + |
| 109 | +The container failed to run (due to different reasons) and Kubernetes tries to run the Pod again after some delay (= BackOff time). |
| 110 | + |
| 111 | +Some reasons for it to fail: |
| 112 | + - Misconfiguration - mispelling, non supported value, etc. |
| 113 | + - Resource not available - nodes are down, PV not mounted, etc. |
| 114 | + |
| 115 | +Some ways to debug: |
| 116 | + |
| 117 | +1. `kubectl describe pod POD_NAME` |
| 118 | + 1. Focus on `State` (which should be Waiting, CrashLoopBackOff) and `Last State` which should tell what happened before (as in why it failed) |
| 119 | +2. Run `kubectl logs mypod` |
| 120 | + 1. This should provide an accurate output of |
| 121 | + 2. For specific container, you can add `-c CONTAINER_NAME` |
| 122 | +3. If you still have no idea why it failed, try `kubectl get events` |
| 123 | +</b></details> |
| 124 | + |
| 125 | +<details> |
| 126 | +<summary>What the error <code>ImagePullBackOff</code> means?</summary><br><b> |
| 127 | + |
| 128 | +Most likely you didn't write correctly the name of the image you try to pull and run |
| 129 | + |
| 130 | +You can confirm with `kubectl describe po POD_NAME` |
| 131 | +</b></details> |
| 132 | + |
| 133 | +## Namespaces |
| 134 | + |
| 135 | +<details> |
| 136 | +<summary>List all the namespaces</summary><br><b> |
| 137 | + |
| 138 | +`k get ns` |
| 139 | +</b></details> |
0 commit comments