topics/kubernetes/README.md
What's your goal?
| Name | Topic | Objective & Instructions | Solution | Comments |
|---|---|---|---|---|
| My First Pod | Pods | Exercise | Solution | |
| "Killing" Containers | Pods | Exercise | Solution |
| Name | Topic | Objective & Instructions | Solution | Comments |
|---|---|---|---|---|
| Creating a Service | Service | Exercise | Solution |
| Name | Topic | Objective & Instructions | Solution | Comments |
|---|---|---|---|---|
| Creating a ReplicaSet | ReplicaSet | Exercise | Solution | |
| Operating ReplicaSets | ReplicaSet | Exercise | Solution | |
| ReplicaSets Selectors | ReplicaSet | Exercise | Solution |
| Name | Topic | Objective & Instructions | Solution | Comments |
|---|---|---|---|---|
| Labels and Selectors 101 | Labels, Selectors | Exercise | Solution | |
| Node Selectors | Labels, Selectors | Exercise | Solution |
| Name | Topic | Objective & Instructions | Solution | Comments |
|---|---|---|---|---|
| Taints 101 | Taints | Exercise | Solution |
| Name | Topic | Objective & Instructions | Solution | Comments |
|---|---|---|---|---|
| common labels | Kustomize | Exercise | Solution |
Kubernetes is an open-source system that provides users with the ability to manage, scale and deploy containerized applications.
To understand what Kubernetes is good for, let's look at some examples:
</b></details>
<details> <summary>When or why NOT to use Kubernetes?</summary> <b></b></details>
<details> <summary>What are some of Kubernetes features?</summary> <b></b></details>
<details> <summary>What Kubernetes objects are there?</summary> <b>metadata, kind and apiVersion
</b></details>
<details> <summary>What is kubectl?</summary> <b>Kubectl is the Kubernetes command line tool that allows you to run commands against Kubernetes clusters. For example, you can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.
</b></details>
<details> <summary>What Kubernetes objects do you usually use when deploying applications in Kubernetes?</summary> <b></b></details>
<details> <summary>Why there is no such command in Kubernetes? <code>kubectl get containers</code></summary> <b>Becaused container is not a Kubernetes object. The smallest object unit in Kubernetes is a Pod. In a single Pod you can find one or more containers.
</b></details>
<details> <summary>What actions or operations you consider as best practices when it comes to Kubernetes?</summary> <b></b></details>
Red Hat Definition: "A Kubernetes cluster is a set of node machines for running containerized applications. If you’re running Kubernetes, you’re running a cluster. At a minimum, a cluster contains a worker node and a master node."
Read more here </b></details>
<details> <summary>What is a Node?</summary> <b>A node is a virtual or a physical machine that serves as a worker for running the applications.
It's recommended to have at least 3 nodes in a production environment. </b></details>
<details> <summary>What the master node is responsible for?</summary> <b>The master coordinates all the workflows in the cluster:
</b></details>
<details> <summary>Describe shortly and in high-level, what happens when you run <code>kubectl get nodes</code></summary> <b>False. A Kubernetes cluster consists of at least 1 master and can have 0 workers (although that wouldn't be very useful...)
</b></details>
<details> <summary>What are the components of the master node (aka control plane)?</summary> <b></b></details>
<details> <summary>What are the components of a worker node (aka data plane)?</summary> <b></b></details>
<details> <summary>Place the components on the right side of the image in the right place in the drawing </summary> <b></b></details>
<details> <summary>You are managing multiple Kubernetes clusters. How do you quickly change between the clusters using kubectl?</summary> <b>kubectl config use-context
</b></details>
Apply requests and limits, especially on third party applications (where the uncertainty is even bigger) </b></details>
<details> <summary>Do you have experience with deploying a Kubernetes cluster? If so, can you describe the process in high-level?</summary> <b>kubectl api-resources
</b></details>
Outputs the status of each of the control plane components. </b></details>
When you stop the kubelet service on a worker node, it will no longer be able to communicate with the Kubernetes API server. As a result, the node will be marked as NotReady and the pods running on that node will be marked as Unknown. The Kubernetes control plane will then attempt to reschedule the pods to other available nodes in the cluster. </b></details>
kubectl get nodes
Note: You might want to create an alias (alias k=kubectl) and get used to k get no
</b></details>
k get nodes -o json > some_nodes.json
</b></details>
k get no minikube --show-labels
</b></details>
A Pod is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers.
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.
</b></details>
<details> <summary>Deploy a pod called "my-pod" using the nginx:alpine image</summary> <b>kubectl run my-pod --image=nginx:alpine
If you are a Kubernetes beginner you should know that this is not a common way to run Pods. The common way is to run a Deployment which in turn runs Pod(s).
In addition, Pods and/or Deployments are usually defined in files rather than executed directly using only the CLI arguments. </b></details>
<details> <summary>What are your thoughts on "Pods are not meant to be created directly"?</summary> <b>Pods are usually indeed not created directly. You'll notice that Pods are usually created as part of another entities such as Deployments or ReplicaSets.
If a Pod dies, Kubernetes will not bring it back. This is why it's more useful for example to define ReplicaSets that will make sure that a given number of Pods will always run, even after a certain Pod dies. </b></details>
<details> <summary>How many containers can a pod contain?</summary> <b>A pod can include multiple containers but in most cases it would probably be one container per pod.
There are some patterns where it makes to run more than one container like the "side-car" pattern where you might want to perform logging or some other operation that is executed by another container running with your app container in the same Pod. </b></details>
<details> <summary>What use cases exist for running multiple containers in a single pod?</summary> <b>A web application with separate (= in their own containers) logging and monitoring components/adapters is one examples.
A CI/CD pipeline (using Tekton for example) can run multiple containers in one Pod if a Task contains multiple commands. </b></details>
<details> <summary>What are the possible Pod phases?</summary> <b>False. By default, pods are non-isolated = pods accept traffic from any source. </b></details>
<details> <summary>True or False? The "Pending" phase means the Pod was not yet accepted by the Kubernetes cluster so the scheduler can't run it unless it's accepted</summary> <b>False. "Pending" is after the Pod was accepted by the cluster, but the container can't run for different reasons like images not yet downloaded. </b></details>
<details> <summary>True or False? A single Pod can be split across multiple nodes</summary> <b>False. A single Pod can run on a single node. </b></details>
<details> <summary>You run a pod and you see the status <code>ContainerCreating</code></summary> <b> </b></details> <details> <summary>True or False? A volume defined in Pod can be accessed by all the containers of that Pod</summary> <b>True. </b></details>
<details> <summary>What happens when you run a Pod with kubectl?</summary> <b>kubectl describe pods <POD_NAME> it will tell whether the container is running:
Status: Runningkubectl exec web -- ls
</b></details>"CrashLoopBackOff" means the Pod is starting, crashing, starting...and so it repeats itself.
There are many different reasons to get this error - lack of permissions, init-container misconfiguration, persistent volume connection issue, etc.
One of the ways to check why it happened it to run kubectl describe po <POD_NAME> and having a look at the exit code
Last State: Terminated
Reason: Error
Exit Code: 100
Another way to check what's going on, is to run kubectl logs <POD_NAME>. This will provide us with the logs from the containers running in that Pod.
</b></details>
livenessProbe:
exec:
command:
- cat
- /appStatus
initialDelaySeconds: 10
periodSeconds: 5
These lines make use of liveness probe. It's used to restart a container when it reaches a non-desired state.
In this case, if the command cat /appStatus fails, Kubernetes will kill the container and will apply the restart policy. The initialDelaySeconds: 10 means that Kubelet will wait 10 seconds before running the command/probe for the first time. From that point on, it will run it every 5 seconds, as defined with periodSeconds
</b></details>
readinessProbe:
tcpSocket:
port: 2017
initialDelaySeconds: 15
periodSeconds: 20
They define a readiness probe where the Pod will not be marked as "Ready" before it will be possible to connect to port 2017 of the container. The first check/probe will start after 15 seconds from the moment the container started to run and will continue to run the check/probe every 20 seconds until it will manage to connect to the defined port. </b></details>
<details> <summary>What does the "ErrImagePull" status of a Pod means?</summary> <b>It wasn't able to pull the image specified for running the container(s). This can happen if the client didn't authenticated for example.
More details can be obtained with kubectl describe po <POD_NAME>.
</b></details>
TERM signal is sent to kill the main processes inside the containers of the given PodKILL signal is used to kill the processes forcefully and the containers as well
</b></details>Liveness probes is a useful mechanism used for restarting the container when a certain check/probe, the user has defined, fails.
For example, the user can define that the command cat /app/status will run every X seconds and the moment this command fails, the container will be restarted.
You can read more about it in kubernetes.io </b></details>
<details> <summary>Explain readiness probes</summary> <b>readiness probes used by Kubelet to know when a container is ready to start running, accepting traffic.
For example, a readiness probe can be to connect port 8080 on a container. Once Kubelet manages to connect it, the Pod is marked as ready
You can read more about it in kubernetes.io </b></details>
<details> <summary>How readiness probe status affect Services when they are combined?</summary> <b>Only containers whose state set to Success will be able to receive requests sent to the Service. </b></details>
<details> <summary>Why it's common to have only one container per Pod in most cases?</summary> <b>One reason is that it makes it harder to scale when you need to scale only one of the containers in a given Pod. </b></details>
<details> <summary>True or False? Once a Pod is assisgned to a worker node, it will only run on that node, even if it fails at some point and spins up a new Pod</summary> <b>True. </b></details>
<details> <summary>True or False? Each Pod, when created, gets its own public IP address</summary> <b>False. Each Pod gets an IP address but an internal one and not publicly accessible.
To make a Pod externally accessible, we need to use an object called Service in Kubernetes. </b></details>
Kubernetes.io: "Static Pods are managed directly by the kubelet daemon on a specific node, without the API server observing them. Unlike Pods that are managed by the control plane (for example, a Deployment); instead, the kubelet watches each static Pod (and restarts it if it fails)." </b></details>
<details> <summary>True or False? The same as there are "Static Pods" there are other static resources like "deployments" and "replicasets"</summary> <b>False. </b></details>
<details> <summary>What are some use cases for using Static Pods?</summary> <b>One clear use case is running Control Plane Pods - running Pods such as kube-apiserver, scheduler, etc. These should run and operate regardless of whether some components of the cluster work or not and they should run on specific nodes of the cluster. </b></details>
<details> <summary>How to identify which Pods are Static Pods?</summary> <b>The suffix of the Pods is the same as the name of the nodes on which they are running TODO: check if it's always the case. </b></details>
<details> <summary>Which of the following is not a static pod?:kube-proxy - it's a DaemonSet (since it has to be presented on every node in the cluster). There is no one specific node on which it has to run. </b></details>
<details> <summary>Where static Pods manifests are located?</summary> <b>Most of the time it's in /etc/kubernetes/manifests but you can verify with grep -i static /var/lib/kubelet/config.yaml to locate the value of statisPodsPath.
It might be that your config is in different path. To verify run ps -ef | grep kubelet and see what is the value of --config argument of the process /usr/bin/kubelet
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.
</b></details>
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 <STATIC_POD_PATH>/<POD_DEFINITION_FILE>)
</b></details>
kubectl get pods -o wide
</b></details>
kubectl delete pod pod_name
</b></details>
k get po -l env=prod
To count them: k get po -l env=prod --no-headers | wc -l
</b></details>
kubectl get po
</b></details>
kubectl get pods --all-namespaces
</b></details>
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.
</b></details>
Prints the logs for a container in a pod. </b></details>
<details> <summary>What <code>kubectl describe pod [pod name] does?</code> command does?</summary> <b>Show details of a specific resource or group of resources. </b></details>
<details> <summary>Create a static pod with the image <code>python</code> that runs the command <code>sleep 2017</code></summary> <b>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
</b></details>
Kubernetes.io: "Labels are key/value pairs that are attached to objects, such as pods. Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users, but do not directly imply semantics to the core system. Labels can be used to organize and to select subsets of objects. Labels can be attached to objects at creation time and subsequently added and modified at any time. Each object can have a set of key/value labels defined. Each Key must be unique for a given object." </b></details>
<details> <summary>Explain selectors</summary> <b>Kubernetes.io: "Unlike names and UIDs, labels do not provide uniqueness. In general, we expect many objects to carry the same label(s).
Via a label selector, the client/user can identify a set of objects. The label selector is the core grouping primitive in Kubernetes.
The API currently supports two types of selectors: equality-based and set-based. A label selector can be made of multiple requirements which are comma-separated. In the case of multiple requirements, all must be satisfied so the comma separator acts as a logical AND (&&) operator." </b></details>
<details> <summary>Provide some actual examples of how labels are used</summary> <b>Kubernetes.io: "You can use Kubernetes annotations to attach arbitrary non-identifying metadata to objects. Clients such as tools and libraries can retrieve this metadata." </b></details>
<details> <summary>How annotations different from labels?</summary> <b>[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." </b></details>
<details> <summary>How to view the logs of a container running in a Pod?</summary> <b>k logs POD_NAME
</b></details>
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
</b></details>
A Kubernetes Deployment is used to tell Kubernetes how to create or modify instances of the pods that hold a containerized application. Deployments can scale the number of replica pods, enable rollout of updated code in a controlled manner, or roll back to an earlier deployment version if necessary.
A Deployment is a declarative statement for the desired state for Pods and Replica Sets. </b></details>
<details> <summary>How to create a deployment with the image "nginx:alpine"?</code></summary> <b>kubectl create deployment my-first-deployment --image=nginx:alpine
OR
cat << EOF | kubectl create -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:alpine
</b></details>
<details> <summary>How to verify a deployment was created?</code></summary> <b>kubectl get deployments or kubectl get deploy
This command lists all the Deployment objects created and exist in the cluster. It doesn't mean the deployments are readt and running. This can be checked with the "READY" and "AVAILABLE" columns. </b></details>
<details> <summary>How to edit a deployment?</code></summary> <b>kubectl edit deployment <DEPLOYMENT_NAME>
</b></details>
The pod will terminate and another, new pod, will be created.
Also, when looking at the replicaset, you'll see the old replica doesn't have any pods and a new replicaset is created. </b></details>
<details> <summary>How to delete a deployment?</summary> <b>One way is by specifying the deployment name: kubectl delete deployment [deployment_name]
Another way is using the deployment configuration file: kubectl delete -f deployment.yaml
</b></details>
The pod related to the deployment will terminate and the replicaset will be removed. </b></details>
<details> <summary>What happens behind the scenes when you create a Deployment object?</summary> <b>The following occurs when you run kubectl create deployment some_deployment --image=nginx
Using a Service. </b></details>
<details> <summary>Can you use a Deployment for stateful applications?</summary> <b> </b></details> <details> <summary>Fix the following deployment manifestapiVersion: apps/v1
kind: Deploy
metadata:
creationTimestamp: null
labels:
app: dep
name: dep
spec:
replicas: 3
selector:
matchLabels:
app: dep
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: dep
spec:
containers:
- image: redis
name: redis
resources: {}
status: {}
Change kind: Deploy to kind: Deployment
</b></details>
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: dep
name: dep
spec:
replicas: 3
selector:
matchLabels:
app: depdep
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: dep
spec:
containers:
- image: redis
name: redis
resources: {}
status: {}
The selector doesn't match the label (dep vs depdep). To solve it, fix depdep so it's dep instead. </b></details>
k create deploy dep -o yaml --image=redis --dry-run=client --replicas 3 > deployment.yaml
</b></details>
<details> <summary>Delete the deployment `depdep`</summary> <b>k delete deploy depdep
</b></details>
<details> <summary>Create a deployment called "pluck" using the image "redis" and make sure it runs 5 replicas</summary> <b>kubectl create deployment pluck --image=redis
kubectl scale deployment pluck --replicas=5
</b></details>
kubectl create deployment blufer --image=python --replicas=3 -o yaml --dry-run=client > deployment.yaml
Add the following section (vi deployment.yaml):
spec:
affinity:
nodeAffinity:
requiredDuringSchedlingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: blufer
operator: Exists
kubectl apply -f deployment.yaml
</b></details>
"An abstract way to expose an application running on a set of Pods as a network service." - read more here
In simpler words, it allows you to add an internal or external connectivity to a certain application running in a container. </b></details>
<details> <summary>Place the components in the right placeholders in regards to Kubernetes service </summary> <b></b></details>
<details> <summary>How to create a service for an existing deployment called "alle" on port 8080 so the Pod(s) accessible via a Load Balancer?</summary> <b>The imperative way:
kubectl expose deployment alle --type=LoadBalancer --port 8080
</b></details>
True </b></details>
<details> <summary>After creating a service, how to check it was created?</summary> <b>kubectl get svc
</b></details>
ClusterIP - used for internal communication. </b></details>
<details> <summary>What Service types are there?</summary> <b>More on this topic here </b></details>
<details> <summary>How Service and Deployment are connected?</summary> <b>The truth is they aren't connected. Service points to Pod(s) directly, without connecting to the Deployment in any way. </b></details>
<details> <summary>What are important steps in defining/adding a Service?</summary> <b></b></details>
<details> <summary>What is the default service type in Kubernetes and what is it used for?</summary> <b>The default is ClusterIP and it's used for exposing a port internally. It's useful when you want to enable internal communication between Pods and prevent any external access.
</b></details>
<details> <summary>How to get information on a certain service?</summary> <b>kubctl describe service <SERVICE_NAME>
It's more common to use kubectl describe svc ...
</b></details>
<details> <summary>What the following command does?kubectl expose rs some-replicaset --name=replicaset-svc --target-port=2017 --type=NodePort
It exposes a ReplicaSet by creating a service called 'replicaset-svc'. The exposed port is 2017 (this is the port used by the application) and the service type is NodePort which means it will be reachable externally. </b></details>
<details> <summary>True or False? the target port, in the case of running the following command, will be exposed only on one of the Kubernetes cluster nodes but it will routed to all the podskubectl expose rs some-replicaset --name=replicaset-svc --target-port=2017 --type=NodePort
False. It will be exposed on every node of the cluster and will be routed to one of the Pods (which belong to the ReplicaSet) </b></details>
<details> <summary>How to verify that a certain service configured to forward the requests to a given pod</summary> <b>Run kubectl describe service and see if the IPs from "Endpoints" match any IPs from the output of kubectl get pod -o wide
</b></details>
apiVersion: v1
kind: Service
metadata:
name: some-app
spec:
type: NodePort
ports:
- port: 8080
nodePort: 2017
protocol: TCP
selector:
type: backend
service: some-app
It creates a new Service of the type "NodePort" which means it can be used for internal and external communication with the app.
The port of the application is 8080 and the requests will forwarded to this port. The exposed port is 2017. As a note, this is not a common practice, to specify the nodePort.
The port used TCP (instead of UDP) and this is also the default so you don't have to specify it.
The selector used by the Service to know to which Pods to forward the requests. In this case, Pods with the label "type: backend" and "service: some-app".
</b></details>
<details> <summary>How to turn the following service into an external one?spec:
selector:
app: some-app
ports:
- protocol: TCP
port: 8081
targetPort: 8081
Adding type: LoadBalancer and nodePort
spec:
selector:
app: some-app
type: LoadBalancer
ports:
- protocol: TCP
port: 8081
targetPort: 8081
nodePort: 32412
</b></details>
<details> <summary>What would you use to route traffic from outside the Kubernetes cluster to services within a cluster?</summary> <b>Ingress </b></details>
<details> <summary>True or False? When "NodePort" is used, "ClusterIP" will be created automatically?</summary> <b>True </b></details>
<details> <summary>When would you use the "LoadBalancer" type</summary> <b>Mostly when you would like to combine it with cloud provider's load balancer </b></details>
<details> <summary>How would you map a service to an external address?</summary> <b>Using the 'ExternalName' directive. </b></details>
<details> <summary>Describe in detail what happens when you create a service</summary> <b>kubectl get ep <name>
</b></details>
You can run kubectl exec <POD_NAME> -- env which will give you a couple environment variables related to the Service.
Variables such as [SERVICE_NAME]_SERVICE_HOST, [SERVICE_NAME]_SERVICE_PORT, ...
</b></details>
Explanation as to who added them:
You can run curl <SERVICE IP>:<SERVICE PORT> to examine the output.
</b></details>
An internal load balancer in Kubernetes is called Service and an external load balancer is Ingress </b></details>
From Kubernetes docs: "Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource."
Read more here </b></details>
<details> <summary>Complete the following configuration file to make it Ingressmetadata:
name: someapp-ingress
spec:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: someapp-ingress
spec:
rules:
- host: my.host
http:
paths:
- backend:
serviceName: someapp-internal-service
servicePort: 8080
</b></details>
<details> <summary>Explain the meaning of "http", "host" and "backend" directivesapiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: someapp-ingress
spec:
rules:
- host: my.host
http:
paths:
- backend:
serviceName: someapp-internal-service
servicePort: 8080
host is the entry point of the cluster so basically a valid domain address that maps to cluster's node IP address
the http line used for specifying that incoming requests will be forwarded to the internal service using http.
backend is referencing the internal service (serviceName is the name under metadata and servicePort is the port under the ports section). </b></details>
<details> <summary>Why using a wildcard in ingress host may lead to issues?</summary> <b>The reason you should not wildcard value in a host (like - host: *) is because you basically tell your Kubernetes cluster to forward all the traffic to the container where you used this ingress. This may cause the entire cluster to go down.
</b></details>
An implementation for Ingress. It's basically another pod (or set of pods) that does evaluates and processes Ingress rules and this it manages all the redirections.
There are multiple Ingress Controller implementations (the one from Kubernetes is Kubernetes Nginx Ingress Controller). </b></details>
<details> <summary>What are some use cases for using Ingress?</summary> <b>kubectl get ingress </b></details>
<details> <summary>What is Ingress Default Backend?</summary> <b>It specifies what do with an incoming request to the Kubernetes cluster that isn't mapped to any backend (= no rule to for mapping the request to a service). If the default backend service isn't defined, it's recommended to define so users still see some kind of message instead of nothing or unclear error. </b></details>
<details> <summary>How to configure a default backend?</summary> <b>Create Service resource that specifies the name of the default backend as reflected in kubectl describe ingress ... and the port under the ports section.
</b></details>
Add tls and secretName entries.
spec:
tls:
- hosts:
- some_app.com
secretName: someapp-secret-tls
</b></details>
<details> <summary>True or False? When configuring Ingress with TLS, the Secret component must be in the same namespace as the Ingress component</summary> <b>True </b></details>
<details> <summary>Which Kubernetes concept would you use to control traffic flow at the IP address or port level? </summary> <b>Network Policies </b></details>
<details> <summary>How to scale an application (deplyoment) so it runs more than one instance of the application?</summary> <b>To run two instances of the applicaation?
kubectl scale deployment <DEPLOYMENT_NAME> --replicas=2
You can specify any other number, given that your application knows how to scale. </b></details>
kubernetes.io: "A ReplicaSet's purpose is to maintain a stable set of replica Pods running at any given time. As such, it is often used to guarantee the availability of a specified number of identical Pods."
In simpler words, a ReplicaSet will ensure the specified number of Pods replicas is running for a selected Pod. If there are more Pods than defined in the ReplicaSet, some will be removed. If there are less than what is defined in the ReplicaSet then, then more replicas will be added. </b></details>
<details> <summary>What the following block of lines does?spec:
replicas: 2
selector:
matchLabels:
type: backend
template:
metadata:
labels:
type: backend
spec:
containers:
- name: httpd-yup
image: httpd
It defines a replicaset for Pods whose type is set to "backend" so at any given point of time there will be 2 concurrent Pods running. </b></details>
<details> <summary>What will happen when a Pod, created by ReplicaSet, is deleted directly with <code>kubectl delete po ...</code>?</summary> <b>The ReplicaSet will create a new Pod in order to reach the desired number of replicas. </b></details>
<details> <summary>True or False? If a ReplicaSet defines 2 replicas but there 3 Pods running matching the ReplicaSet selector, it will do nothing</summary> <b>False. It will terminate one of the Pods to reach the desired state of 2 replicas. </b></details>
<details> <summary>Describe the sequence of events in case of creating a ReplicaSet</summary> <b>kubectl get rs
</b></details>
Yes, with --cascase=false.
kubectl delete -f rs.yaml --cascade=false
</b></details>
1 </b></details>
<details> <summary>What the following output of <code>kubectl get rs</code> means?NAME DESIRED CURRENT READY AGE web 2 2 0 2m23s
</summary> <b>The replicaset web has 2 replicas. It seems that the containers inside the Pod(s) are not yet running since the value of READY is 0. It might be normal since it takes time for some containers to start running and it might be due to an error. Running kubectl describe po POD_NAME or kubectl logs POD_NAME can give us more information.
</b></details>
False. The Pods can be already running and initially they can be created by any object. It doesn't matter for the ReplicaSet and not a requirement for it to acquire and monitor them. </b></details>
<details> <summary>True or False? In case of a ReplicaSet, if Pods specified in the selector field don't exists, the ReplicaSet will wait for them to run before doing anything</summary> <b>False. It will take care of running the missing Pods. </b></details>
<details> <summary>In case of a ReplicaSet, Which field is mandatory in the spec section?</summary> <b>The field template in spec section is mandatory. It's used by the ReplicaSet to create new Pods when needed.
</b></details>
kubectl describe rs <ReplicaSet Name>
It will be visible under Events (the very last lines)
</b></details>
True (and not only the Pods but anything else it created). </b></details>
<details> <summary>True or False? Removing the label from a Pod that is tracked by a ReplicaSet, will cause the ReplicaSet to create a new Pod</summary> <b>True. When the label, used by a ReplicaSet in the selector field, removed from a Pod, that Pod no longer controlled by the ReplicaSet and the ReplicaSet will create a new Pod to compensate for the one it "lost". </b></details>
<details> <summary>How to scale a deployment to 8 replicas?</code></summary> <b>kubectl scale deploy <DEPLOYMENT_NAME> --replicas=8 </b></details>
<details> <summary>ReplicaSets are running the moment the user executed the command to create them (like <code>kubectl create -f rs.yaml</code>)</summary> <b>False. It can take some time, depends on what exactly you are running. To see if they are up and running, run kubectl get rs and watch the 'READY' column.
</b></details>
kubectl expose rs <ReplicaSet Name> --name=<Service Name> --target-port=<Port to expose> --type=NodePort
Few notes:
apiVersion: apps/v1
kind: ReplicaCet
metadata:
name: redis
labels:
app: redis
tier: cache
spec:
selector:
matchLabels:
tier: cache
template:
metadata:
labels:
tier: cachy
spec:
containers:
- name: redis
image: redis
kind should be ReplicaSet and not ReplicaCet :) </b></details>
<details> <summary>Fix the following ReplicaSet definitionapiVersion: apps/v1
kind: ReplicaSet
metadata:
name: redis
labels:
app: redis
tier: cache
spec:
selector:
matchLabels:
tier: cache
template:
metadata:
labels:
tier: cachy
spec:
containers:
- name: redis
image: redis
The selector doesn't match the label (cache vs cachy). To solve it, fix cachy so it's cache instead. </b></details>
<details> <summary>How to check which container image was used as part of replica set called "repli"?</summary> <b>k describe rs repli | grep -i image
</b></details>
k describe rs repli | grep -i "Pods Status"
</b></details>
k delete rs rori
</b></details>
k edis rs rori
</b></details>
k scale rs rori --replicas=5
</b></details>
k scale rs rori --replicas=1
</b></details>
Kubernetes.io: "A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. As nodes are added to the cluster, Pods are added to them. As nodes are removed from the cluster, those Pods are garbage collected. Deleting a DaemonSet will clean up the Pods it created." </b></details>
<details> <summary>What's the difference between a ReplicaSet and DaemonSet?</summary> <b>A ReplicaSet's purpose is to maintain a stable set of replica Pods running at any given time. A DaemonSet ensures that all Nodes run a copy of a Pod. </b></details>
<details> <summary>What are some use cases for using a DaemonSet?</summary> <b>Historically, up 1.12, it was done with NodeName attribute.
Starting 1.12, it's achieved with regular scheduler and node affinity. </b></details>
kubectl get ds
</b></details>
StatefulSet is the workload API object used to manage stateful applications. Manages the deployment and scaling of a set of Pods, and provides guarantees about the ordering and uniqueness of these Pods.Learn more </b></details>
A directory accessible by the containers inside a certain Pod and containers. The mechanism responsible for creating the directory, managing it, ... mainly depends on the volume type.
</b></details>
<details> <summary>What volume types are you familiar with?</summary> <b>/sys, /var/lib, etc.)</b></details>
<details> <summary>Which problems, volumes in Kubernetes solve?</summary> <b></b></details>
<details> <summary>Explain ephemeral volume types vs. persistent volumes in regards to Pods</summary> <b>Ephemeral volume types have the lifetime of a pod as opposed to persistent volumes which exist beyond the lifetime of a Pod.
</b></details>
<details> <summary>Provide at least one use-case for each of the following volume types:/sys or data generated in /var/lib)
</b></details>False. By default two Pods in two different namespaces are able to communicate with each other.
Try it for yourself:
kubectl run test-prod -n prod --image ubuntu -- sleep 2000000000 kubectl run test-dev -n dev --image ubuntu -- sleep 2000000000
k describe po test-prod -n prod to get the IP of test-prod Pod.
Access dev Pod: kubectl exec --stdin --tty test-dev -n dev -- /bin/bash
And ping the IP of test-prod Pod you get earlier.You'll see that there is communication between the two pods, in two separate namespaces.
</b></details>
kubernetes.io: "NetworkPolicies are an application-centric construct which allow you to specify how a pod is allowed to communicate with various network "entities"..."
In simpler words, Network Policies specify how pods are allowed/disallowed to communicate with each other and/or other network endpoints.
</b></details>
<details> <summary>What are some use cases for using Network Policies?</summary> <b></b></details>
<details> <summary>True or False? If no network policies are applied to a pod, then no connections to or from it are allowed</summary> <b>False. By default pods are non-isolated. </b></details>
<details> <summary>In case of two pods, if there is an egress policy on the source denining traffic and ingress policy on the destination that allows traffic then, traffic will be allowed or denied?</summary> <b>Denied. Both source and destination policies has to allow traffic for it to be allowed. </b></details>
<details> <summary>Where Kubernetes cluster stores the cluster state?</summary> <b>etcd </b></details>
etcd is an open source distributed key-value store used to hold and manage the critical information that distributed systems need to keep running.
</b></details>
<details> <summary>True or False? Etcd holds the current status of any kubernetes component</summary> <b>True </b></details>
<details> <summary>True or False? The API server is the only component which communicates directly with etcd</summary> <b>True </b></details>
<details> <summary>True or False? application data is not stored in etcd</summary> <b>True </b></details>
<details> <summary>Why etcd? Why not some SQL or NoSQL database?</summary> <b>When chosen as the data store etcd was (and still is of course):
Namespaces allow you split your cluster into virtual clusters where you can group your applications in a way that makes sense and is completely separated from the other groups (so you can for example create an app with the same name in two different namespaces) </b></details>
<details> <summary>Why to use namespaces? What is the problem with using one default namespace?</summary> <b>When using the default namespace alone, it becomes hard over time to get an overview of all the applications you manage in your cluster. Namespaces make it easier to organize the applications into groups that makes sense, like a namespace of all the monitoring applications and a namespace for all the security applications, etc.
Namespaces can also be useful for managing Blue/Green environments where each namespace can include a different version of an app and also share resources that are in other namespaces (namespaces like logging, monitoring, etc.).
Another use case for namespaces is one cluster, multiple teams. When multiple teams use the same cluster, they might end up stepping on each others toes. For example if they end up creating an app with the same name it means one of the teams overridden the app of the other team because there can't be too apps in Kubernetes with the same name (in the same namespace). </b></details>
<details> <summary>True or False? When a namespace is deleted all resources in that namespace are not deleted but moved to another default namespace</summary> <b>False. When a namespace is deleted, the resources in that namespace are deleted as well. </b></details>
<details> <summary>What special namespaces are there by default when creating a Kubernetes cluster?</summary> <b>True. Try create two pods in two separate namespaces for example, and you'll see there is a connection between the two. </b></details>
kubectl get namespaces OR kubectl get ns
</b></details>
<details> <summary>Create a namespace called 'alle'</summary> <b>k create ns alle
</b></details>
<details> <summary>Check how many namespaces are there</summary> <b>k get ns --no-headers | wc -l
</b></details>
<details> <summary>Check how many pods exist in the "dev" namespace</summary> <b>k get po -n dev
</b></details>
<details> <summary>Create a pod called "kartos" in the namespace dev. The pod should be using the "redis" image.</summary> <b>If the namespace doesn't exist already: k create ns dev
k run kratos --image=redis -n dev
</b></details>
<details> <summary>You are looking for a Pod called "atreus". How to check in which namespace it runs?</summary> <b>k get po -A | grep atreus
</b></details>
<details> <summary>What kube-public contains?</summary> <b>kubectl config view | grep namespace
</b></details>
It holds information on heartbeats of nodes. Each node gets an object which holds information about its availability. </b></details>
<details> <summary>True or False? With namespaces you can limit the resources consumed by the users/teams</summary> <b>True. With namespaces you can limit CPU, RAM and storage usage. </b></details>
<details> <summary>How to switch to another namespace? In other words how to change active namespace?</code></summary> <b>kubectl config set-context --current --namespace=some-namespace and validate with kubectl config view --minify | grep namespace:
OR
kubens some-namespace
</b></details>
Resource quota provides constraints that limit aggregate resource consumption per namespace. It can limit the quantity of objects that can be created in a namespace by type, as well as the total amount of compute resources that may be consumed by resources in that namespace. </b></details>
<details> <summary>How to create a Resource Quota?</code></summary> <b>kubectl create quota some-quota --hard-cpu=2,pods=2 </b></details>
<details> <summary>Which resources are accessible from different namespaces?</code></summary> <b>Services. </b></details>
<details> <summary>Which service and in which namespace the following file is referencing?apiVersion: v1
kind: ConfigMap
metadata:
name: some-configmap
data:
some_url: samurai.jack
It's referencing the service "samurai" in the namespace called "jack". </b></details>
<details> <summary>Which components can't be created within a namespace?</code></summary> <b>Volume and Node. </b></details>
<details> <summary>How to list all the components that bound to a namespace?</code></summary> <b>kubectl api-resources --namespaced=true
</b></details>
One way is by specifying --namespace like this: kubectl apply -f my_component.yaml --namespace=some-namespace
Another way is by specifying it in the YAML itself:
apiVersion: v1
kind: ConfigMap
metadata:
name: some-configmap
namespace: some-namespace
and you can verify with: kubectl get configmap -n some-namespace
</b></details>
kubectl exec some-pod -it -- ls </b></details>
<details> <summary>How to create a service that exposes a deployment?</code></summary> <b>kubectl expose deploy some-deployment --port=80 --target-port=8080 </b></details>
<details> <summary>How to create a pod and a service with one command?</code></summary> <b>kubectl run nginx --image=nginx --restart=Never --port 80 --expose </b></details>
<details> <summary>Describe in detail what the following command does <code>kubectl create deployment kubernetes-httpd --image=httpd</code></summary> <b> </b></details> <details> <summary>Why to create kind deployment, if pods can be launched with replicaset?</summary> <b> </b></details> <details> <summary>How to get list of resources which are not bound to a specific namespace?</code></summary> <b>kubectl api-resources --namespaced=false </b></details>
<details> <summary>How to delete all pods whose status is not "Running"?</code></summary> <b>kubectl delete pods --field-selector=status.phase!='Running' </b></details>
<details> <summary>How to display the resources usages of pods?</summary> <b>kubectl top pod </b></details>
<details> <summary>Perhaps a general question but, you suspect one of the pods is having issues, you don't know what exactly. What do you do?</summary> <b>Start by inspecting the pods status. we can use the command kubectl get pods (--all-namespaces for pods in system namespace)
If we see "Error" status, we can keep debugging by running the command kubectl describe pod [name]. In case we still don't see anything useful we can try stern for log tailing.
In case we find out there was a temporary issue with the pod or the system, we can try restarting the pod with the following kubectl scale deployment [name] --replicas=0
Setting the replicas to 0 will shut down the process. Now start it with kubectl scale deployment [name] --replicas=1
</b></details>
They become candidates to for termination. </b></details>
<details> <summary>Describe how roll-back works</summary> <b> </b></details> <details> <summary>True or False? Memory is a compressible resource, meaning that when a container reach the memory limit, it will keep running</summary> <b>False. CPU is a compressible resource while memory is a non compressible resource - once a container reached the memory limit, it will be terminated. </b></details>
Explained here
"Operators are software extensions to Kubernetes that make use of custom resources to manage applications and their components. Operators follow Kubernetes principles, notably the control loop."
In simpler words, you can think about an operator as a custom control loop in Kubernetes. </b></details>
<details> <summary>Why do we need Operators?</summary> <b>The process of managing stateful applications in Kubernetes isn't as straightforward as managing stateless applications where reaching the desired status and upgrades are both handled the same way for every replica. In stateful applications, upgrading each replica might require different handling due to the stateful nature of the app, each replica might be in a different status. As a result, we often need a human operator to manage stateful applications. Kubernetes Operator is suppose to assist with this.
This also help with automating a standard process on multiple Kubernetes clusters </b></details>
<details> <summary>What components the Operator consists of?</summary> <b></b></details>
<details> <summary>Explain CRD</summary> <b>CRD is Custom Resource Definitions. It's custom Kubernetes component which extends K8s API.
TODO(abregman): add more info.
</b></details>
<details> <summary>How Operator works?</summary> <b>It uses the control loop used by Kubernetes in general. It watches for changes in the application state. The difference is that is uses a custom control loop.
In addition, it also makes use of CRD's (Custom Resources Definitions) so basically it extends Kubernetes API.
</b></details>
<details> <summary>True or False? Kubernetes Operator used for stateful applications</summary> <b>True </b></details>
<details> <summary>Explain what is the OLM (Operator Lifecycle Manager) and what is it used for</summary> <b></b></details>
<details> <summary>What is the Operator Framework?</summary> <b>open source toolkit used to manage k8s native applications, called operators, in an automated and efficient way.
</b></details>
<details> <summary>What components the Operator Framework consists of?</summary> <b></b></details>
<details> <summary>Describe in detail what is the Operator Lifecycle Manager</summary> <b>It's part of the Operator Framework, used for managing the lifecycle of operators. It basically extends Kubernetes so a user can use a declarative way to manage operators (installation, upgrade, ...).
</b></details>
<details> <summary>What openshift-operator-lifecycle-manager namespace includes?</summary> <b>It includes:
</b></details>
<details> <summary>What is kubconfig? What do you use it for?</summary> <b>A kubeconfig file is a file used to configure access to Kubernetes when used in conjunction with the kubectl commandline tool (or other clients). Use kubeconfig files to organize information about clusters, users, namespaces, and authentication mechanisms. </b></details>
<details> <summary>Would you use Helm, Go or something else for creating an Operator?</summary> <b>Depends on the scope and maturity of the Operator. If it mainly covers installation and upgrades, Helm might be enough. If you want to go for Lifecycle management, insights and auto-pilot, this is where you'd probably use Go. </b></details>
<details> <summary>Are there any tools, projects you are using for building Operators?</summary> <b>This one is based more on a personal experience and taste...
Secrets let you store and manage sensitive information (passwords, ssh keys, etc.)
</b></details>
<details> <summary>How to create a Secret from a key and value?</summary> <b>kubectl create secret generic some-secret --from-literal=password='donttellmypassword'
</b></details>
<details> <summary>How to create a Secret from a file?</summary> <b>kubectl create secret generic some-secret --from-file=/some/file.txt
</b></details>
Opaque is the default type used for key-value pairs. </b></details>
<details> <summary>True or False? storing data in a Secret component makes it automatically secured</summary> <b>False. Some known security mechanisms like "encryption" aren't enabled by default. </b></details>
<details> <summary>What is the problem with the following Secret file:apiVersion: v1
kind: Secret
metadata:
name: some-secret
type: Opaque
data:
password: mySecretPassword
Password isn't encrypted.
You should run something like this: echo -n 'mySecretPassword' | base64 and paste the result to the file instead of using plain-text.
</b></details>
<details> <summary>What the following in a Deployment configuration file means?spec:
containers:
- name: USER_PASSWORD
valueFrom:
secretKeyRef:
name: some-secret
key: password
USER_PASSWORD environment variable will store the value from password key in the secret called "some-secret" In other words, you reference a value from a Kubernetes Secret.
</b></details>
<details> <summary>How to commit secrets to Git and in general how to use encrypted secrets?</summary> <b>One possible process would be as follows:
False </b></details>
<details> <summary>Explain "Persistent Volumes". Why do we need it?</summary> <b>Persistent Volumes allow us to save data so basically they provide storage that doesn't depend on the pod lifecycle. </b></details>
<details> <summary>True or False? Persistent Volume must be available to all nodes because the pod can restart on any of them</summary> <b>True </b></details>
<details> <summary>What types of persistent volumes are there?</summary> <b>Volume snapshots let you create a copy of your volume at a specific point in time. </b></details>
<details> <summary>True or False? Kubernetes manages data persistence</summary> <b>False </b></details>
<details> <summary>Explain Storage Classes</summary> <b> </b></details> <details> <summary>Explain "Dynamic Provisioning" and "Static Provisioning"</summary> <b>The main difference relies on the moment when you want to configure storage. For instance, if you need to pre-populate data in a volume, you choose static provisioning. Whereas, if you need to create volumes on demand, you go for dynamic provisioning. </b></details>
<details> <summary>Explain Access Modes</summary> <b> </b></details> <details> <summary>What is CSI Volume Cloning?</summary> <b> </b></details> <details> <summary>Explain "Ephemeral Volumes"</summary> <b> </b></details> <details> <summary>What types of ephemeral volumes Kubernetes supports?</summary> <b> </b></details> <details> <summary>What is Reclaim Policy?</summary> <b> </b></details> <details> <summary>What reclaim policies are there?</summary> <b>RBAC in Kubernetes is the mechanism that enables you to configure fine-grained and specific sets of permissions that define how a given user, or group of users, can interact with any Kubernetes object in cluster, or in a specific Namespace of cluster. </b></details>
<details> <summary>Explain the <code>Role</code> and <code>RoleBinding"</code> objects</summary> <b> </b></details> <details> <summary>What is the difference between <code>Role</code> and <code>ClusterRole</code> objects?</summary> <b>The difference between them is that a Role is used at a namespace level whereas a ClusterRole is for the entire cluster. </b></details>
<details> <summary>Explain what are "Service Accounts" and in which scenario would use create/use one</summary> <b>Kubernetes.io: "A service account provides an identity for processes that run in a Pod."
An example of when to use one: You define a pipeline that needs to build and push an image. In order to have sufficient permissions to build an push an image, that pipeline would require a service account with sufficient permissions. </b></details>
<details> <summary>What happens you create a pod and you DON'T specify a service account?</summary> <b>The pod is automatically assigned with the default service account (in the namespace where the pod is running). </b></details>
<details> <summary>Explain how Service Accounts are different from User Accounts</summary> <b>kubectl get serviceaccounts
</b></details>
kubernetes.io: "A security context defines privilege and access control settings for a Pod or Container." </b></details>
A CronJob creates Jobs on a repeating schedule. One CronJob object is like one line of a crontab (cron table) file. It runs a job periodically on a given schedule, written in Cron format. </b></details>
<details> <summary>What possible issue can arise from using the following spec and how to fix it?apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: some-cron-job
spec:
schedule: '*/1 * * * *'
startingDeadlineSeconds: 10
concurrencyPolicy: Allow
If the cron job fails, the next job will not replace the previous one due to the "concurrencyPolicy" value which is "Allow". It will keep spawning new jobs and so eventually the system will be filled with failed cron jobs. To avoid such problem, the "concurrencyPolicy" value should be either "Replace" or "Forbid". </b></details>
<details> <summary>What issue might arise from using the following CronJob and how to fix it?apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: "some-cron-job"
spec:
schedule: '*/1 * * * *'
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
The following lines placed under the template:
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
As a result this configuration isn't part of the cron job spec hence the cron job has no limits which can cause issues like OOM and potentially lead to API server being down.
To fix it, these lines should placed in the spec of the cron job, above or under the "schedule" directive in the above example. </b></details>
</b></details>
<details> <summary>Explain what Kubernetes Service Discovery means</summary> <b> </b></details> <details> <summary>You have one Kubernetes cluster and multiple teams that would like to use it. You would like to limit the resources each team consumes in the cluster. Which Kubernetes concept would you use for that?</summary> <b>Namespaces will allow to limit resources and also make sure there are no collisions between teams when working in the cluster (like creating an app with the same name). </b></details>
<details> <summary>What Kube Proxy does?</summary> <b> Kube Proxy is a network proxy that runs on each node in your cluster, implementing part of the Kubernetes Service concept </b></details> <details> <summary>What "Resources Quotas" are used for and how?</summary> <b> </b></details> <details> <summary>Explain ConfigMap</summary> <b>Separate configuration from pods. It's good for cases where you might need to change configuration at some point but you don't want to restart the application or rebuild the image so you create a ConfigMap and connect it to a pod but externally to the pod.
Overall it's good for:
False. Use secret. </b></details>
<details> <summary>Explain "Horizontal Pod Autoscaler"</summary> <b>In Kubernetes, a HorizontalPodAutoscaler automatically updates a workload resource with the aim of automatically scaling the workload to match demand. </b></details>
<details> <summary>When you delete a pod, is it deleted instantly? (a moment after running the command)</summary> <b> </b></details> <details> <summary>What does being cloud-native mean?</summary> <b> The term cloud native refers to the concept of building and running applications to take advantage of the distributed computing offered by the cloud delivery model. </b></details> <details> <summary>Explain the pet and cattle approach of infrastructure with respect to kubernetes</summary> <b> </b></details> <details> <summary>Describe how you one proceeds to run a containerized web app in K8s, which should be reachable from a public URL.</summary> <b> </b></details> <details> <summary>How would you troubleshoot your cluster if some applications are not reachable any more?</summary> <b> </b></details> <details> <summary>Describe what CustomResourceDefinitions there are in the Kubernetes world? What they can be used for?</summary> <b> </b></details> <details> <summary> How does scheduling work in kubernetes?</summary> <b>The control plane component kube-scheduler asks the following questions,
View more here </b></details>
<details> <summary> How are labels and selectors used?</summary> <b> </b></details> <details> <summary>What QoS classes are there?</summary> <b>Kubernetes labels are key-value pairs that can connect identifying metadata with Kubernetes objects. </b></details>
<details> <summary>Explain Selectors</summary> <b> </b></details> <details> <summary>What is Kubeconfig?</summary> <b> </b></details>Gatekeeper docs: "Gatekeeper is a validating (mutating TBA) webhook that enforces CRD-based policies executed by Open Policy Agent" </b></details>
<details> <summary>Explain how Gatekeeper works</summary> <b>On every request sent to the Kubernetes cluster, Gatekeeper sends the policies and the resources to OPA (Open Policy Agent) to check if it violates any policy. If it does, Gatekeeper will return the policy error message back. If it isn't violates any policy, the request will reach the cluster. </b></details>
Conftest allows you to write tests against structured files. You can think of it as tests library for Kubernetes resources.
It is mostly used in testing environments such as CI pipelines or local hooks. </b></details>
<details> <summary>What is Datree? How is it different from Conftest?</summary> <b>Same as Conftest, it is used for policy testing and enforcement. The difference is that it comes with built-in policies. </b></details>
Package manager for Kubernetes. Basically the ability to package YAML files and distribute them to other users and apply them in the cluster(s).
As a concept it's quite common and can be found in many platforms and services. Think for example on package managers in operating systems. If you use Fedora/RHEL that would be dnf. If you use Ubuntu then, apt. If you don't use Linux, then a different question should be asked and it's why? but that's another topic :) </b></details>
<details> <summary>Why do we need Helm? What would be the use case for using it?</summary> <b>Sometimes when you would like to deploy a certain application to your cluster, you need to create multiple YAML files/components like: Secret, Service, ConfigMap, etc. This can be tedious task. So it would make sense to ease the process by introducing something that will allow us to share these bundle of YAMLs every time we would like to add an application to our cluster. This something is called Helm.
A common scenario is having multiple Kubernetes clusters (prod, dev, staging). Instead of individually applying different YAMLs in each cluster, it makes more sense to create one Chart and install it in every cluster.
Another scenario is, you would like to share what you've created with the community. For people and companies to easily deploy your application in their cluster. </b></details>
<details> <summary>Explain "Helm Charts"</summary> <b>Helm Charts is a bundle of YAML files. A bundle that you can consume from repositories or create your own and publish it to the repositories. </b></details>
<details> <summary>It is said that Helm is also Templating Engine. What does it mean?</summary> <b>It is useful for scenarios where you have multiple applications and all are similar, so there are minor differences in their configuration files and most values are the same. With Helm you can define a common blueprint for all of them and the values that are not fixed and change can be placeholders. This is called a template file and it looks similar to the following
apiVersion: v1
kind: Pod
metadata:
name: {[ .Values.name ]}
spec:
containers:
- name: {{ .Values.container.name }}
image: {{ .Values.container.image }}
port: {{ .Values.container.port }}
The values themselves will in separate file:
name: some-app
container:
name: some-app-container
image: some-app-image
port: 1991
</b></details>
<details> <summary>What are some use cases for using Helm template file?</summary> <b>someChart/ -> the name of the chart Chart.yaml -> meta information on the chart values.yaml -> values for template files charts/ -> chart dependencies templates/ -> templates files :) </b></details>
<details> <summary>How Helm supports release management?</summary> <b>Helm allows you to upgrade, remove and rollback to previous versions of charts. In version 2 of Helm it was with what is known as "Tiller". In version 3, it was removed due to security concerns. </b></details>
helm search hub [some_keyword]
</b></details>
Or directly on the command line: helm install --set some_key=some_value
</b></details>
helm ls or helm list
</b></details>
helm rollback RELEASE_NAME REVISION_ID
</b></details>
helm history RELEASE_NAME
</b></details>
helm upgrade RELEASE_NAME CHART_NAME
</b></details>
One possible path is to run kubectl describe pod <pod name> to get more details.
You might see one of the following:
If none of the above helped, run the command (get pods) with -o wide to see if the node is assigned to a node. If not, there might be an issue with scheduler.
</b></details>
One possible path is to start with checking the Pod status.
kubectl describe pod <pod name>
TODO: finish this...
</b></details>Istio is an open source service mesh that helps organizations run distributed, microservices-based apps anywhere. Istio enables organizations to secure, connect, and monitor microservices, so they can modernize their enterprise apps more swiftly and securely. </b></details>
Kubernetes.io: "In Kubernetes, controllers are control loops that watch the state of your cluster, then make or request changes where needed. Each controller tries to move the current cluster state closer to the desired state." </b></details>
<details> <summary>Name two controllers you are familiar with</summary> <b>Kube-Controller-Manager </b></details>
<details> <summary>What is the control loop? How it works?</summary> <b>Explained here </b></details>
<details> <summary>What are all the phases/steps of a control loop?</summary> <b>False. While the scheduler is responsible for choosing the node on which the Pod will run, Kubelet is the one that actually runs the Pod. </b></details>
<details> <summary>How to schedule a pod on a node called "node1"?</summary> <b>k run some-pod --image=redix -o yaml --dry-run=client > pod.yaml
vi pod.yaml and add:
spec:
nodeName: node1
k apply -f pod.yaml
Note: if you don't have a node1 in your cluster the Pod will be stuck on "Pending" state. </b></details>
vi pod.yaml
affinity:
nodeAffinity:
requiredDuringSchedlingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: region
operator: In
values:
- asia
- emea
</b></details>
<details> <summary>Using node affinity, set a Pod to never schedule on a node where the key is "region" and value is "neverland"</summary> <b>vi pod.yaml
affinity:
nodeAffinity:
requiredDuringSchedlingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: region
operator: NotIn
values:
- neverland
</b></details>
<details> <summary>True of False? Using the node affinity type "requiredDuringSchedlingIgnoredDuringExecution" means the scheduler can't schedule unless the rule is met</summary> <b>True </b></details>
<details> <summary>True of False? Using the node affinity type "preferredDuringSchedlingIgnoredDuringExecution" means the scheduler can't schedule unless the rule is met</summary> <b>False. The scheduler tries to find a node that meets the requirements/rules and if it doesn't it will schedule the Pod anyway. </b></details>
<details> <summary>Can you deploy multiple schedulers?</summary> <b>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
...
</b></details>
<details> <summary>Assuming you have multiple schedulers, how to know which scheduler was used for a given Pod?</summary> <b>Running kubectl get events you can see which scheduler was used.
</b></details>
Add the following to the spec of the Pod:
spec:
schedulerName: some-custom-scheduler
</b></details>
k describe no master | grep -i taints
</b></details>
k taint node minikube app=web:NoSchedule
k describe no minikube | grep -i taints
</b></details>
The Pod will remain in "Pending" status due to the only node in the cluster having a taint of "app=web". </b></details>
<details> <summary>You applied a taint with <code>k taint node minikube app=web:NoSchedule</code> on the only node in your cluster and then executed <code>kubectl run some-pod --image=redis</code> but the Pod is in pending state. How to fix it?</summary> <b>kubectl edit po some-pod and add the following
- effect: NoSchedule
key: app
operator: Equal
value: web
Exit and save. The pod should be in Running state now. </b></details>
<details> <summary>Remove an existing taint from one of the nodes in your cluster</summary> <b>k taint node minikube app=web:NoSchedule-
</b></details>
NoSchedule: prevents from resources to be scheduled on a certain node
PreferNoSchedule: will prefer to shcedule resources on other nodes before resorting to scheduling the resource on the chosen node (on which the taint was applied)
NoExecute: Applying "NoSchedule" will not evict already running Pods (or other resources) from the node as opposed to "NoExecute" which will evict any already running resource from the Node
</b></details>
False. It's per container and not per Pod. </b></details>
kubectl describe po <POD_NAME> | grep -i limits
</b></details>
kubectl run yay --image=python --dry-run=client -o yaml > pod.yaml
vi pod.yaml
spec:
containers:
- image: python
imagePullPolicy: Always
name: yay
resources:
requests:
cpu: 250m
memory: 64Mi
kubectl apply -f pod.yaml
</b></details>
kubectl run yay2 --image=python --dry-run=client -o yaml > pod.yaml
vi pod.yaml
spec:
containers:
- image: python
imagePullPolicy: Always
name: yay2
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 250m
memory: 64Mi
kubectl apply -f pod.yaml
</b></details>
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:
</b></details>
<details> <summary>Describe how the monitoring solution you are working with monitors Kubernetes and </summary> <b>This very much depends on what you chose to use. Let's address some of the solutions:
kubectl top node and kubectl top pod to view performance metrics on nodes, pods and other resources.TODO: add more monitoring solutions
</b></details>
kustomize build APP_PATH where your kustomization.yml also resides
</b></details>Blue/Green deployment steps:
Users -> Load Balancer -> App Version 1
Users -> Load Balancer -> App Version 1 App Version 2
User -> Load Balancer App version 1 -> App Version 2
Pros:
</b></details>
<details> <summary>Explain Canary deployments/rollouts in detail</summary> <b>Canary deployment steps:
Users -> Load Balancer -> App Version 1
Users -> Load Balancer ->(95% of the traffic) App Version 1 ->(5% of the traffic) App Version 2
Users -> Load Balancer ->(70% of the traffic) App Version 1 ->(30% of the traffic) App Version 2
Users -> Load Balancer -> App Version 2
Pros:
</b></details>
<details> <summary>What ways are you familiar with to implement deployment strategies (like canary, blue/green) in Kubernetes?</summary> <b>There are multiple ways. One of them is Argo Rollouts. </b></details>
Namespaces. See the following namespaces question and answer for more information. </b></details>
<details> <summary>An engineer in your team runs a Pod but the status he sees is "CrashLoopBackOff". What does it means? How to identify the issue?</summary> <b>The container failed to run (due to different reasons) and Kubernetes tries to run the Pod again after some delay (= BackOff time).
Some reasons for it to fail:
Some ways to debug:
kubectl describe pod POD_NAME
State (which should be Waiting, CrashLoopBackOff) and Last State which should tell what happened before (as in why it failed)kubectl logs mypod
-c CONTAINER_NAME
</b></details>Yes, using taints, we could run the following command and it will prevent from all resources with label "app=web" to be scheduled on node1: kubectl taint node node1 app=web:NoSchedule
</b></details>
Using ResourceQuats </b></details>
<!-- {% endraw %} -->