Skip to content

Commit 64e6614

Browse files
author
abregman
committed
Add a couple of Kubernetes questions and exercises
Also updated CKA page.
1 parent 9d01834 commit 64e6614

File tree

7 files changed

+353
-76
lines changed

7 files changed

+353
-76
lines changed

topics/kubernetes/CKA.md

+143
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
- [Troubleshooting ReplicaSets](#troubleshooting-replicasets)
1212
- [Deployments](#deployments)
1313
- [Troubleshooting Deployments](#troubleshooting-deployments)
14+
- [Scheduler](#scheduler)
15+
- [Labels and Selectors](#labels-and-selectors)
16+
- [Taints](#taints)
1417

1518
## Setup
1619

@@ -136,6 +139,14 @@ You can also run `k describe po POD_NAME`
136139
`k delete po nm`
137140
</b></details>
138141

142+
<details>
143+
<summary>List all the pods with the label "env=prod"</summary><br><b>
144+
145+
`k get po -l env=prod`
146+
147+
To count them: `k get po -l env=prod --no-headers | wc -l`
148+
</b></details>
149+
139150
### Troubleshooting Pods
140151

141152
<details>
@@ -180,6 +191,12 @@ Because there is no such image `sheris`. At least for now :)
180191
To fix it, run `kubectl edit ohno` and modify the following line `- image: sheris` to `- image: redis` or any other image you prefer.
181192
</b></details>
182193

194+
<details>
195+
<summary>You try to run a Pod but it's in "Pending" state. What might be the reason?</summary><br><b>
196+
197+
One possible reason is that the scheduler which supposed to schedule Pods on nodes, is not running. To verify it, you can run `kubectl get po -A | grep scheduler` or check directly in `kube-system` namespace.
198+
</b></details>
199+
183200
## Namespaces
184201

185202
<details>
@@ -194,6 +211,32 @@ To fix it, run `kubectl edit ohno` and modify the following line `- image: sheri
194211
`k create ns alle`
195212
</b></details>
196213

214+
<details>
215+
<summary>Check how many namespaces are there</summary><br><b>
216+
217+
`k get ns --no-headers | wc -l`
218+
</b></details>
219+
220+
<details>
221+
<summary>Check how many pods exist in the "dev" namespace</summary><br><b>
222+
223+
`k get po -n dev`
224+
</b></details>
225+
226+
<details>
227+
<summary>Create a pod called "kartos" in the namespace dev. The pod should be using the "redis" image.</summary><br><b>
228+
229+
If the namespace doesn't exist already: `k create ns dev`
230+
231+
`k run kratos --image=redis -n dev`
232+
</b></details>
233+
234+
<details>
235+
<summary>You are looking for a Pod called "atreus". How to check in which namespace it runs?</summary><br><b>
236+
237+
`k get po -A | grep atreus`
238+
</b></details>
239+
197240
## Nodes
198241

199242
<details>
@@ -212,10 +255,57 @@ Note: create an alias (`alias k=kubectl`) and get used to `k get no`
212255

213256
## Services
214257

258+
<details>
259+
<summary>Check how many services are running in the current namespace</summary><br><b>
260+
261+
`k get svc`
262+
</b></details>
263+
215264
<details>
216265
<summary>Create an internal service called "sevi" to expose the app 'web' on port 1991</summary><br><b>
217266
</b></details>
218267

268+
<details>
269+
<summary>How to reference by name a service called "app-service" within the same namespace?</summary><br><b>
270+
271+
app-service
272+
</b></details>
273+
274+
<details>
275+
<summary>How to check the TargetPort of a service?</summary><br><b>
276+
277+
`k describe svc <SERVICE_NAME>`
278+
</b></details>
279+
280+
<details>
281+
<summary>How to check what endpoints the svc has?</summary><br><b>
282+
283+
`k describe svc <SERVICE_NAME>`
284+
</b></details>
285+
286+
<details>
287+
<summary>How to reference by name a service called "app-service" within a different namespace, called "dev"?</summary><br><b>
288+
289+
app-service.dev.svc.cluster.local
290+
</b></details>
291+
292+
<details>
293+
<summary>Assume you have a deployment running and you need to create a Service for exposing the pods. This is what is required/known:
294+
295+
* Deployment name: jabulik
296+
* Target port: 8080
297+
* Service type: NodePort
298+
* Selector: jabulik-app
299+
* Port: 8080
300+
</summary><br><b>
301+
302+
`kubectl expose deployment jabulik --name=jabulik-service --target-port=8080 --type=NodePort --port=8080 --dry-run=client -o yaml -> svc.yaml`
303+
304+
`vi svc.yaml` (make sure selector is set to `jabulik-app`)
305+
306+
`k apply -f svc.yaml`
307+
</b></details>
308+
219309
## ReplicaSets
220310

221311
<details>
@@ -427,3 +517,56 @@ status: {}
427517

428518
The selector doesn't match the label (dep vs depdep). To solve it, fix depdep so it's dep instead.
429519
</b></details>
520+
521+
## Scheduler
522+
523+
<details>
524+
<summary>How to schedule a pod on a node called "node1"?</summary><br><b>
525+
526+
`k run some-pod --image=redix -o yaml --dry-run=client > pod.yaml`
527+
528+
`vi pod.yaml` and add:
529+
530+
```
531+
spec:
532+
nodeName: node1
533+
```
534+
535+
`k apply -f pod.yaml`
536+
537+
Note: if you don't have a node1 in your cluster the Pod will be stuck on "Pending" state.
538+
</b></details>
539+
540+
## Labels and Selectors
541+
542+
<details>
543+
<summary>How to list all the Pods with the label "app=web"?</summary><br><b>
544+
545+
`k get po -l app=web`
546+
</b></details>
547+
548+
<details>
549+
<summary>How to list all objects labeled as "env=staging"?</summary><br><b>
550+
551+
`k get all -l env=staging`
552+
</b></details>
553+
554+
<details>
555+
<summary>How to list all deployments from "env=prod" and "type=web"?</summary><br><b>
556+
557+
`k get deploy -l env=prod,type=web`
558+
</b></details>
559+
560+
## Taints
561+
562+
<details>
563+
<summary>Check if there are taints on node "master"</summary><br><b>
564+
565+
`k describe no master | grep -i taints`
566+
</b></details>
567+
568+
<details>
569+
<summary>Create a taint on one of the nodes in your cluster with key of "app" and value of "web" and effect of "NoSchedule"</summary><br><b>
570+
571+
`k taint node minikube app=web:NoSchedule`
572+
</b></details>

0 commit comments

Comments
 (0)