From d2f681f56ea74c035687fe297e5389e363de3beb Mon Sep 17 00:00:00 2001 From: abregman Date: Fri, 21 Oct 2022 17:28:51 +0300 Subject: [PATCH] Add a couple of Kubernetes questions Also updated CKA page. --- README.md | 2 +- topics/kubernetes/CKA.md | 90 ++++++++++++++++++++++++++++++++- topics/kubernetes/README.md | 99 +++++++++++++++++++++++++++++++++++-- 3 files changed, 185 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index db8b369..df2f819 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ :information_source:  This repo contains questions and exercises on various technical topics, sometimes related to DevOps and SRE -:bar_chart:  There are currently **2406** exercises and questions +:bar_chart:  There are currently **2415** exercises and questions :books:  To learn more about DevOps and SRE, check the resources in [devops-resources](https://github.com/bregman-arie/devops-resources) repository diff --git a/topics/kubernetes/CKA.md b/topics/kubernetes/CKA.md index 36ffd34..d864d5a 100644 --- a/topics/kubernetes/CKA.md +++ b/topics/kubernetes/CKA.md @@ -17,6 +17,8 @@ - [Node Selector](#node-selector) - [Taints](#taints) - [Resources Limits](#resources-limits) + - [Monitoring](#monitoring) + - [Scheduler](#scheduler-1) ## Setup @@ -150,6 +152,24 @@ You can also run `k describe po POD_NAME` To count them: `k get po -l env=prod --no-headers | wc -l` +
+Create a static pod with the image python that runs the command sleep 2017
+ +First change to the directory tracked by kubelet for creating static pod: `cd /etc/kubernetes/manifests` (you can verify path by reading kubelet conf file) + +Now create the definition/manifest in that directory +`k run some-pod --image=python --command sleep 2017 --restart=Never --dry-run=client -o yaml > statuc-pod.yaml` +
+ +
+Describe how would you delete a static Pod +
+ +Locate the static Pods directory (look at `staticPodPath` in kubelet configuration file). + +Go to that directory and remove the manifest/definition of the staic Pod (`rm /`) +
+ ### Troubleshooting Pods
@@ -187,7 +207,7 @@ You can confirm with `kubectl describe po POD_NAME`
-Run the following command: kubectl run ohno --image=sheris. Did it work? why not? fix it without removing the Pod and using any image you want
+Run the following command: kubectl run ohno --image=sheris. Did it work? why not? fix it without removing the Pod and using any image you would like
Because there is no such image `sheris`. At least for now :) @@ -200,6 +220,18 @@ To fix it, run `kubectl edit ohno` and modify the following line `- image: sheri 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.
+
+How to view the logs of a container running in a Pod?
+ +`k logs POD_NAME` +
+ +
+There are two containers inside a Pod called "some-pod". What will happen if you run kubectl logs some-pod
+ +It won't work because there are two containers inside the Pod and you need to specify one of them with `kubectl logs POD_NAME -c CONTAINER_NAME` +
+ ## Namespaces
@@ -769,4 +801,60 @@ spec: ``` `kubectl apply -f pod.yaml` +
+ +## Monitoring + +
+Deploy metrics-server
+ +`kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml` +
+ +
+Using metrics-server, view the following: + +* top performing nodes in the cluster +* top performing Pods +
+ +* top nodes: `kubectl top nodes` +* top pods: `kubectl top pods` + +
+ +## Scheduler + +
+Can you deploy multiple schedulers?
+ +Yes, it is possible. You can run another pod with a command similar to: + +``` +spec: + containers: + - command: + - kube-scheduler + - --address=127.0.0.1 + - --leader-elect=true + - --scheduler-name=some-custom-scheduler +... +``` +
+ +
+Assuming you have multiple schedulers, how to know which scheduler was used for a given Pod?
+ +Running `kubectl get events` you can see which scheduler was used. +
+ +
+You want to run a new Pod and you would like it to be scheduled by a custom schduler. How to achieve it?
+ +Add the following to the spec of the Pod: + +``` +spec: + schedulerName: some-custom-scheduler +```
\ No newline at end of file diff --git a/topics/kubernetes/README.md b/topics/kubernetes/README.md index 564fa47..5fc2c7f 100644 --- a/topics/kubernetes/README.md +++ b/topics/kubernetes/README.md @@ -24,8 +24,8 @@ What's your goal? - [Nodes Commands](#nodes-commands) - [Pods](#pods-1) - [Static Pods](#static-pods) - - [Pods - Commands](#pods---commands) - - [Pods - Troubleshooting and Debugging](#pods---troubleshooting-and-debugging) + - [Pods Commands](#pods-commands) + - [Pods Troubleshooting and Debugging](#pods-troubleshooting-and-debugging) - [Labels and Selectors](#labels-and-selectors-1) - [Deployments](#deployments) - [Deployments Commands](#deployments-commands) @@ -62,6 +62,7 @@ What's your goal? - [Taints](#taints) - [Resource Limits](#resource-limits) - [Resources Limits - Commands](#resources-limits---commands) + - [Monitoring](#monitoring) - [Scenarios](#scenarios) ## Kubernetes Exercises @@ -583,7 +584,16 @@ It might be that your config is in different path. To verify run `ps -ef | grep The key itself for defining the path of static Pods is `staticPodPath`. So if your config is in `/var/lib/kubelet/config.yaml` you can run `grep staticPodPath /var/lib/kubelet/config.yaml`. -#### Pods - Commands +
+Describe how would you delete a static Pod +
+ +Locate the static Pods directory (look at `staticPodPath` in kubelet configuration file). + +Go to that directory and remove the manifest/definition of the staic Pod (`rm /`) +
+ +#### Pods Commands
How to check to which worker node the pods were scheduled to? In other words, how to check on which node a certain Pod is running?
@@ -617,7 +627,7 @@ To count them: `k get po -l env=prod --no-headers | wc -l` `kubectl get pods --all-namespaces`
-#### Pods - Troubleshooting and Debugging +#### Pods Troubleshooting and Debugging
You try to run a Pod but it's in "Pending" state. What might be the reason?
@@ -637,6 +647,15 @@ Prints the logs for a container in a pod. Show details of a specific resource or group of resources.
+
+Create a static pod with the image python that runs the command sleep 2017
+ +First change to the directory tracked by kubelet for creating static pod: `cd /etc/kubernetes/manifests` (you can verify path by reading kubelet conf file) + +Now create the definition/manifest in that directory +`k run some-pod --image=python --command sleep 2017 --restart=Never --dry-run=client -o yaml > statuc-pod.yaml` +
+ ### Labels and Selectors
@@ -674,6 +693,18 @@ The API currently supports two types of selectors: equality-based and set-based. [Kuberenets.io](Labels can be used to select objects and to find collections of objects that satisfy certain conditions. In contrast, annotations are not used to identify and select objects. The metadata in an annotation can be small or large, structured or unstructured, and can include characters not permitted by labels.): "Labels can be used to select objects and to find collections of objects that satisfy certain conditions. In contrast, annotations are not used to identify and select objects. The metadata in an annotation can be small or large, structured or unstructured, and can include characters not permitted by labels."
+
+How to view the logs of a container running in a Pod?
+ +`k logs POD_NAME` +
+ +
+There are two containers inside a Pod called "some-pod". What will happen if you run kubectl logs some-pod
+ +It won't work because there are two containers inside the Pod and you need to specify one of them with `kubectl logs POD_NAME -c CONTAINER_NAME` +
+ ### Deployments
@@ -2749,6 +2780,40 @@ True False. The scheduler tries to find a node that meets the requirements/rules and if it doesn't it will schedule the Pod anyway.
+
+Can you deploy multiple schedulers?
+ +Yes, it is possible. You can run another pod with a command similar to: + +``` +spec: + containers: + - command: + - kube-scheduler + - --address=127.0.0.1 + - --leader-elect=true + - --scheduler-name=some-custom-scheduler +... +``` +
+ +
+Assuming you have multiple schedulers, how to know which scheduler was used for a given Pod?
+ +Running `kubectl get events` you can see which scheduler was used. +
+ +
+You want to run a new Pod and you would like it to be scheduled by a custom schduler. How to achieve it?
+ +Add the following to the spec of the Pod: + +``` +spec: + schedulerName: some-custom-scheduler +``` +
+ ### Taints
@@ -2870,6 +2935,32 @@ spec: `kubectl apply -f pod.yaml`
+### Monitoring + +
+What monitoring solutions are you familiar with in regards to Kubernetes?
+ +There are many types of monitoring solutions for Kubernetes. Some open-source, some are in-memory, some of them cost money, ... here is a short list: + +* metrics-server: in-memory open source monitoring +* datadog: $$$ +* promethues: open source monitoring solution + +
+ +
+Describe how the monitoring solution you are working with monitors Kubernetes and
+ +This very much depends on what you chose to use. Let's address some of the solutions: + +* metrics-server: an open source and free monitoring solution that uses the cAdvisor component of kubelet to retrieve information on the cluster and its resources and stores them in-memory. +Once installed, after some time you can run commands like `kubectl top node` and `kubectl top pod` to view performance metrics on nodes, pods and other resources. + +TODO: add more monitoring solutions + +
+ + ### Scenarios