Kubernetes Interview Questions
Kubernetes Interview Questions
Answer:
While this seems easy, a prepared and practiced answer is significantly better than an
impromptu one.
You answer would be uniqe to your experience, but, here are some possibilities.
a. created clusters
e. added weave
g. deployed spinnaker
h. configured HPA
k. stateful sets
........
2. You have 2 different contexts (A and B). Context A has a secret named foo.
Context B does not. What would be a quick way to create the same exact secret in
Context B?
Answer:
1. Switch to Context A
2. kubetcl get secret foo -o yaml > foo.yaml
3. Switch to Context B
4. kubectl apply -f foo.yaml
......
3. There are more than one way to implement Ingress? What did you use to
implement Ingress?
......
.....
5. What is the difference between Ingress and Ingress Controller:
.....
.....
.....
a. HA Proxy
b. Istio Ingress
c. Traefik kubernetes Ingress Provider
d. Skipper
e. Voyager
f. Tyk Operator
g. Gloo (open source)
h. AKS Application Gateway Ingress Controller (Azure)
i. Ambassador (envoy-based)
j. Enroute (another envoy-based Ingress Controller)
(and more)
.,...
Answer:
a. via GCP GUI OR
b. via GCP cloud shell window OR
c. gcloud CLI
d. Terraform
e. Google Deployment Manager
......
Answer: You can use --previous option with logs command to see the logs of a
crashed container.
(kubectl logs --previous)
.
......
11. What happens to containers if they use too much cpu or memory?
......
Answer:
This artcile answers it very well:
https://www.replex.io/blog/kubernetes-in-production-best-practices-for-
cluster-autoscaler-hpa-and-vpa
......
Answer: Answer will depend on your use case. One possible answer is to have
Service accounts that do certain things within the cluster.
By the way, RBAC in Kubernetes is just AWS IAM Policies and
Bindings. In RBAC, you have subjects (who gets the permission), verbs (what
can the subject actually do), and rolebinding (subject linking to roles) and
roles.
.
......
14. If you have 200 micro-services in your clusters, how do you manage security of
each one? How do you avoid toil?
Answer: RBAC is the answer. You define roles. And you place subjects in
those roles. Each role then will have access to X Y Z etc. This is really no
different than AWS or AD.
......
15. Tell me about the hardest production Kubernetes issue you solved or faced?
Answer:
There are N micro-services. One of them gets a new version. But, the HPA
for those pods are set wrong. Container keep crashing. This causes cascading
failures for many other micro-services.
Solution: Fix the HPA settings and add circuit-breakers in the consuming
micro-services.
......
16. You want to know how to make yaml files for making PODs and you have no
access to internet. What do you do?
It will show you all fields in a mapped kind of fromat so you exacly what
field go where
......
Answer: SSL cert can be a secret. Then that secret can be mounted on a pod
and that pod can whatever it wants with it (e.g. host a SSL web site)
......
Answer: kubectx
......
Answer: k9s
......
20. "kubectl explain" command is great, but you must know the exact name of the
resource (e.g. pod/services/persistentvolume) to get the details, unless you do
recursive. How do you get the names of these resources from command line?
Answer: kubectl api-resources (gives you a list and shortnames and more)
.
......
21. Name some of the other verbs that kubectl has besides "run" "create" or
"apply" ?
Some of more frequently used ones are: logs, get, port-forward and
label.
......
22. What might you get when you run kubectl api-resources?
Answer: api-resources is fancy term. Basically you get stuff like pods/
secrets/config-maps all that stuff.
......
23. How else can you get help with kubectl? (besides kubectl explain command)
.
......
24. You ran "kubectl --help" , but you want a little more help. What to do?
Answer:
kubectl get --help
kubectl top --help
kubectl describe --help
......
25. Outline the steps to deploy additional scheduler on a Kubernetes cluster (not
GKE)
Answer:
Package the new scheduler in a docker image
Put that image in a registry
Create a deploymentment file with type: deployment and component:
scheduler (in namespace kube-system)
Deploy the the scheduler with apply -f scheduler.yaml command
......
26. List out 2 use cases for Daemonsets and explain why it is more appropriate to
use daemonset than deployment for those use case:
Answer:
1. Pod that collects logs. Better to use daemonsets for this because you
can logs to be fed from all pods (e.g. to kibana). Otherwise you have to
make this part of EVERY deployment which would be annoying and repetitive.
2. Pod that runs monitoring (e.g. dynatrace or datadog). Reason is the
same as above.
.
......
......
Ans: Private
......
29. Which one will allow to access your services from internet: cluster ip or
nodeport?
......
30. For a service, when we use nodeport, EVERY node does what?
......
31. What does it mean when we say that a node proxy's a service?
Answer: The node forwards the traffic to a pod that is part of the service.
......
......
33. How can a container have access to secret via ENV variable?
Answer: You can define a ENV in yaml file just like everyhing else and
container can just do echo $WHATEVER
......
.
......
......
......
37. Whenever you run a kubectl command, it runs in the the default namespace.
How do you make in run in a different namespace?
......
......
39. When using kubectl command, how do you to get output in json format?
......
Answer:
port : on the cluster
targetport: on the container (just like ALB)
......
......
......
43. Command to create a deployment from image: foobar/webapp-color
......
......
......
46. If you want your kubernetes command to have a scope of ALL namespaces,
how do you do that?
......
......
48. By default, can a pod in one namespace talk to another pod in another
namespace?
Answer: Yes.
......
49. How to generate a yaml file from an imperative command you know works ?
......
50. Write a kubectl command to Create a static pod, have it run a command (so it does not
exit). dryrun so that you get yaml file saved :
......
51. By default, where does yaml files for static POD files go:
Answer: /etc/kubernetes/manifests/ (on the node)
......
......
53. Kubectl command to take all the details for a.yaml file and create the resource
it tells API to crate:
......
......
55. There is pod named foo. it is in crashloopbackoff state. How to find the cause
using a kubectl command?
Answer: kubectl describe pod foo
What you might see is for example, container's "command" has a mispelling in
it. (Just an example)
......
56. Scenario Question: You have a container that keeps crashing because its
"command" section has a misspelling. How do you fix this?
Answer:
1. generate the yaml file,
2. fix it,
3. kill the pod,
4. re-run with the correct yaml file (kubectl apply -f)
.......
.......
.
......
......
60. Kubectl command to make a new yaml file for a service by exposing a already
running deployment that runs a pod. Name of the deployment: foo.
......
61. jsonpath example of getting "everything" (about nodes) . This is not really an
interview question. But, its goog to know this in case JSON PATH topic comes up.
......
62. jsonpath example of getting just the level "status" for all nodes
......
63. jsonpath comamnd to get only status.nodeInfo of each node . This is not really
an interview question. But, its goog to know this in case JSON PATH topic comes
up.
.......
64: Your computer has no access to internet. Which kubectl command can you use
to find out syntax of making a pv.yaml :
......
......
......
.......
.......
69. Some example of commands the master server can send to etcd (once
authenticated with certs and key):
Answer:
member list
snapshot save /tmp/etcd-backup.db
snapshot status /tmp/etcd-backup.db -w table
.
.......
70. Steps to create a pod called foo with image redis with CPU Request set to 2
CPU and Request as 400MiB
Answer:
a. first create a yaml file: (dry-run command)
kubectl run --generator=run-pod/v1 foo --image=redis --dry-run -o
yaml > foo.yaml
b. edit the yaml file:
in the resources section of "spec" section:
cpu: 2
memory: 400MiB
c. kubectl apply -f ./foo.yaml
......
71. True or False: POD DEFINITION (yaml) ONLY points to PVC (claim), it does not
refer to the PV anywhere.
Answer: True
.......
......
......
74. kubectl command to change the image version of a deployment on the fly:
......
......
Answer: For one thing, the API server won't talk to you , if you don't have
a signed client certificate. So, any client who wants to do ANYTHING with
the API server (e.g. even kubectl) better have a signed certificate!
......
77. Why are .csr files have CSR extension? What is CSR all about?
......
......
79. What's an easy way lookup kubernetes documenation on the fly simply using
kubectl command?
......
80. Kubernetes Security: How are some of the ways you can protect your container
images?
Answer:
a. Update them (to get latest security patches at the OS level)
b. Scan them regularly
c. Sign them digitally
......
81. Can you think of some general areas of Kubernetes where you would want to
think about security:
Answer:
a. Your container images
b. Your container registry
c. Your kubernetes run time infrastructure (e.g. etcd)
d. Hosts (where Kubernetes nodes are running)
e. Kubernetes Secrets
f. Kubernetes Certificates
g. RBAC entities
......
82. Processes within a container: How to they (security-wise) talk to API server
running on the master node?
......
Note: The reason why this is related to Kubernetes is that sometimes you
use this command to encode soemthing before putting it in the yaml file.
......
Answer:
a. create a .csr file using openssl command (and a private key, but does
not matter to Kubernetes)
b. encode it
c. create a yaml file (Kind: CertificateSigningRequest) using the encoded
CSR
d. kubectl apply -f CertificateSigningRequest.yaml
......
85. If you have created CertificateSigningRequest, but you have not approved it
yet, what status do you get if you run "kubectl get csr" command?
.......
......
......
......
Answer: etcd data store all your Kubernetes data including Kubernetes
secrets
......
.......
Answer: (On a managed Kubernetes like GKE and EKS, you don't need to do
this):
a. create a private key
b. create CSR
c. self-sign the CSR
.......
Answer: Yes, but horrible idea, basically all traffic do and from etcd will not be
encrypted
.......
......
94. When you tell Kubernetes to run a pod, who decides which node gets that
pod?
Answer: Scheduler
......
95. What if you don't like the default scheduler that comes with Kubernetes?
.......
96. If a node has taint, what you have to do to your pod, for it to be able to run on
that node?
......
97. If you want a pod to run on specific node, which feature do you have to use?
......
Answer: There are times, when a container fails liveness probe and yet we do not
want to container to be killed. For example, if a container takes time to ready (loads
large data set). In this case, liveness probe would fail and (without a readiness probe),
Kubernetes would kill the container. A readiness probe tell Kubernetes to wait for the
container finish doing all its prep work.
.
......
99. What does it mean for Kubernetes to drop support for Docker?
.......
Answer: Docker has the ability to send logs to various places (e.g. awslogs or fluent
and many more). Each one of these is a logging driver.
......
Answer: cAdvisor (which is part of kubelet on worker nodes) Those are then sent to
Metric Server (running on master nodes). Metrics Server exposes them via kube-api
(also running on the master node)
.......
102. When you run "kubetcl top", which component are you talking to?
.
......
.......
.......
Answer: When the sidecar proxy's the connections from the main container to
the outside world.
.......
......
107. Can you describe a use-case where the ambassador pattern can be of use?
Answer: If you have legacy application which cannot be modified, BUT you
have a need to change to the port on which this app needs to listen on, the
ambassador container can listen on the new port and pass on the traffic to
the old port which did not get modified.
.......
Answer: Labels are basically tags. Selectors use key-value pairs to pick
out objects (e.g. pods) to work on.
......
.
.......
......
......
112. Why do we need HPA when we already have maxSurge and maxUnavailable?
......
Answer: Service Port is where users come to get the micro-service. Target
Port is the port of the container/pod where the application listens and
exposes.
.
......
114. You are configuring a service and you have made a mistake with labels and/or
selectors. How does this manifest itself often?
Answer: You will see the service and there will be no endpoint.
......
115. You are logged in to conext via kubectl on your Mac. How can you see if you
have permission to update pods?
......
116. Let's say you manage 100 GKE Clusters. You want to run a kubectl command.
How do you make sure your command will be executed on the right cluster?
Answer: You will have 100 contexts (one for each cluster you have logged in
to). You must switch to to the right context before running the command.
There is a open-source CLI tool called kubectx that helps you with this.
......
......
.......
119. If you are on a node, how do you look for running container?
......
120. Let's say you know how to run a pod via command line. You can do this very
easily because you have done it many times. Given that, how can you quickly
generate a YAML file for doing the same thing?
.
......
121. You ran: kubectl get po foo -o yaml > foo.yaml . The problem is that this YAML
file has lots on info about the running pod in addition to the "core" yaml content
need. How do you get a clean YAML file out of this?
Answer: You can delete most of those lines (e.g. the status fields and
many others)
.......
.......
123. If you want a pod to be associated with a service account name, how do you
do it in yaml file?
......
124. What does a YAML file for a pod that has 2 containers look like?
Answer: "containers" section is an array. So, you can define as many
containers as you like using dashes.
Here is an example:
apiversion v1
kind pod
metadata
name foo2containers
spec
containers
- image nginx
name ONE
env
- name ONE
value foo
- image busybox
name TWO
command sleep 1000
.....
125. How to see what network policies you have in default namespace?
........
Answer: Yes.
.......
127. What is the deal with "api-versions". What is the context for this?
Answer: Kubernetes is not one API. It is set of APIs. As in the case of any
large scale development project, each api is it's stage of maturity. This is
why 1. you see so many Kubernetes APIs
and 2. Each has different versions (alpha, beta etc.)
......
128. How to see the correct network api version to use in neteork policy yaml file?
......
.......
130. You have a deployment named foo. How can you scale it up via cli:
(imperative way) ?
......
131. You suspect something is wrong with the control plane pods. What should
your run?
.......
132. You see that a pod is in "imagepullbackoff" state (ie not running),
Answer: You should see which image that pod is configured to use.
"imagepullbackoff" means that, for some reason, Kubernetes could
not pull the docker image.
This could be because image is not there OR there are permission
issues prohibiting the download of that image.
.......
You found out that the controller-manager pod on the master had issues. You
fixed that so, controller-manager pod
is now running. What do you have to do next so that scaling finally
happens?
......
134. How do you list out all pods running in the namespace foo?
Answer: kubectl get pods -namespace=foo
........
Answer:
Imperative: Basically via commands
Declarative: basically via yaml files
.......
136. Assume that you are connected to the cluster and context, how do you
quickly create an NGINX pod using an imperative approach?
........
Answer:
It's like an isolation process. e.g. If you namespaces dev and prod, you
can have pods named foo in both namespaces and there is no conflict. (In the
same cluster)
In Kubernetes, you can have the dev team their own namespace and prod can
have its own namespace.
.
........
Outline the steps that you use to troubleshoot and the kubectl command
you use to diagnose the problem.
Answer:
Step 1: run the describe pod command and read through events
Step 2: run the kubectl logs -p podname and see what is going on with
pods (use --previous option, since pod has already crashed)
......
139. What are the functions of Kubernetes control plane? Where do those
functions reside?
.......
Answer: scheduler
.
.......
142. When a new GKE cluster is created, what are the main namespaces created?
........
Answer: So that you can select something based on those labels. They are
like tags in AWS. Let's say I want to use node-affinity. We can use labels
to select (selector argument in yaml or command) the ones desired.
.......
Answer:
kubetcl label pods pod1 owner=mamun
kubectl label pods pod2 owner=foo
.......
........
146. What are annotations use for in Kubernetes and how are they different from
labels and selectors
.......
147. Is deployment and service the same - Explain the difference or the sameness
between the 2 concepts
Answer: No.
Deployment is like terraform apply (of pods) that you can run a bunch
of time with changing configurations (Kubernetes keeps track and so you can
roll back).
Service is basically an entrypoint for users to hit the pods with the
right application. Users only know about service and not the pods behind it.
........
.........
149. What are the 3 main characteristics you should focus on to troubleshoot what
can go wrong between pods and services?
.........
Answer: pods ---> service ---> Public IP ---> DNS ---> External Users
.........
..........
152. List some useful commands to troubleshoot Pods issues: (These will come in
handy on various interview questions)
Answer:
Kubectl describe pod
Kubectl port-forward podname 3000:80 (example)
Kubectl get pods -o wide
Kubectl logs podname
Kubectl get pod podname
Kubectl exec -ti podname bash
.......
Answer: You make a link between a port on your Mac or PC (localhost) and a
port on a pod.
For example, pod is open on port 443. If you set up port-forward to
you localhost port 4430, you can get to the web server on pod via https://
localhost:4430
........
154. Pods can have startup and runtime errors - Explain what some of these errors
mean and 2-3 common culprits (These wil come in handy for various interview
questions)
Imagine the interviewer asking you about each specific one and you
having explain that one.
Answer:
ImagePullBackOff
: the docker image could not be gotten
Registry name is bad or not reachable
Docker image name is bad or image no longer exists
CrashLoopBackOff
: container comes up and crashes/exists
Container has nothing to do, so it shuts down
Initial value of readiness probe is too small compared to what is
needed by container¿s tasks
RunContainerError
: container could not be kicked off
Pod network solution is not working
Authorization Issues
........
155. Can you schedule regular pods on the master node (general Kubernetes, not
GKE).
Answer: Yes. BUT, the noschedule taint (which is there by default) has to
be removed first.
.........
156. You have a node A with taint=blue. You have a Pod X with toleration for
taint=blue. Would pod X always be placed on Node A. Explain your answer in
detail (Why yes or no)
Answer:
Taint is a barrier. The fact that pod X has toleration for blue means
that it CAN be scheduled on node A.
However, if there are other nodes with no taint or taint of blue, X can
land there too.
...........
Answer:
nodeSelector is simplistic based on labels whereas node affinity allows
much more complex matching, soft-matching and un-matching.
nodeSelector use cases: pods belonging to a team go on the same node(s).
Pods belonging to an environment (e.g. dev) go on the same node(s).
node affinity use cases: geographic location. Pods go on nodes where some
pods live (OR do not live)
........
158. How do you find out what image of the running container (in a pod)?
.......
159. Command used to find out what node the pods are running on:
Answer: kubectl get pods -o wide
........
160. What does the READY column in the output column of the "kubectl get pods"
command indicate?
Answer: How many containers are supposed to run in the pod and how many are
actually running.
........
161. What happens if all master nodes are unavailable on (GKE) ? would that
impact workloads running on the worker nodes?
......
162. Why are worker nodes spread out on multiple availability zones in GKE?
Answer:
If Google Cloud has an outage in one AZ, application will still be
available.
.......
163. What is the difference between setting up a GKE cluster as regional versus
zonal. This will require you read up on GKE implementation of K8s
Answer:
Multi-zonal cluster: master is present in only one zone + nodes are in N
zones
Regional cluster: masters are present in N zones + nodes are in N zone
So, In Regional cluster, master is HA at the regional level, whereas in
Multi-zonal cluster, it is not.
......
Answer: Sometimes there is a need to have some pods on EVERY node (e.g. DNS
server or a log collector). One can deploy these ¿sets¿ as a daemon set on
each node.
Deployment is a declarative definition of replicasets/pods. You
define what needs to go on (how many, what type etc) and the deployment
controller ensures that the "desired state" is always there.
........
.......
166. In a replica set definition how do we tell the replica set that a set of pods is
part of the replica set?
.......
.......
Answer: kube-system
........
Answer: no, because kubectl does not recognize "pods" as valid 2nd level
command
.
.......
Answer: This is the way to make sure the containers do not consume more resources
than desired. This way, 2 things can happen: Runaway containers do no affect others
We get alerted when resource increase over time does not reach a certain limit.
........
.......
172. Explain what is meant by resource request and resource limits setting.
Answer:
Request: amount of resources a container asks for and scheduler only
schedules IF that amount IS available on a node. ("entrypoint")
Limit: container is killed or throttled IF a container ever tries to get
this much resource.("bad boy level")
........
.......
........
Answer: True
.......
176. Why would you have many Deployments work together in the virtual network
of the cluster?
Answer: There are many use cases for this. One example would be to deploy
many micro-services. Each micro-service would be a deployment.
......
177. To expose a pod so that users can get to it, you need to create ________ ?
Answer: Service
.
.......
.......
179. Deployments are meant to contain stateless services. If you need to store a
state you need to create ________ instead (e.g. for a database service).
Answer: StatefulSet
.......
180. How do you see which pods or nodes are using the most resources?
.......
Answer: No
.
.......
Answer: Yes
.......
183. Let's say that you want to add a "sleep" command to your container. Where
does that go in the YAML file?
........
........
185. Can you edit any live object using "kubectl edit" command?
Answer: No
........
186. Command to edit the configuration of a live pod:
........
......
.......
189. Pods come and go. So, how in the world, does Kubernetes provide any real
service?
Answer: Service's IP NEVER changes. You can point DNS to it. Behind the
"service" are the ephemeral pods.
........
190. (Real Interview Question asked 2022): You run "k get po" and you ass a pod
that is in "completed" state. What does that mean?
Answer: This means that pod came up, did its job and finished. It did not
crash. It is not running. You can still get to its logs
.......
191. (Real Interview Question asked 2022): What kind of troubleshooting have you
done in Kubernetes?
Answer: This depends on your experience, but some ideas include ingress,
capacity, pods crashing, slow service, certificate expiring etc.
........
192. (Real Interview Question asked 2022): How is Anthos Service Mesh compared
to Istio?
.........
Answer: kube-proxy
.........
194. What component of Kubernetes is basically a crude Load Balancer?
Answer: service
..........
........
...........
..........
.........
199. Why are there 3 versions of NGINX ingress controller for Kubernetes?
.......
200. Why would you go with Nginx Ingress Controller (and not the Kubernetes
Community One)
Answer: With Nginx one, you get HTTP Load Balancing (You don't get with
community one)
Source: https://www.youtube.com/watch?v=OM_N0jjghqI
............
201. When impleneting Prometheus, why is it best use the Adapter pattern?
Answer: Because otherwise, you will have re-write each application "data"
to the format that Prometheus expects. The prometheus sidecar will do that
and send the data along w/o you having to modify the application container.
.
............
...........
203. (Actual interview question 2022): What is the difference between Docker
Compose and Kubernetes ?
........
..........
205. When we run "kubectl run pods" , that gets to the API server on the master
node. What does the API server do with that request?
.
..........
206. How do you combine kubectl and jsonpath to get the info you need?
..........
..........
..........
Answer: When a client hits a Service, Service needs to know where to send
the request to (much like a Load Balancer). It forwards it to an Endpoint.
When a Service is created based on a "match" with a pod (or pods),
Kubernetes automatically creates an Endpoint to the pod's IP and port.
SERVICE ---> ENDPOINT (automaticlaly created) --> POD'S IP and PORT
.
..........
..........
211. How can you verify that your binary executables (Kubernetes) have not been
corrupted?
Answer: Create SHA256 Hash of the binary and compare the message digest
with the one given on the official web site.
..........
212. (Not really an interview question, more a real life question) . You are trying to
run a pod with "kubectl run" command, but running into issues with exact formats
and options, what do you do (besides googling)?
..........
213. (Not really an interview question, more a real life question) . When you are
creating a pod using "kubectl run" command, How can you supply a command to
run on the container (like sleep 3600)
Answer: Simply supply the command with --command -- option.
e.g. kubectl run foo --image=nginx --command -- sh -c "sleep 3600"
..........
214. How can you login into a pod (assuming it only has 1 container) ?
..........
215. When you create a pod you can give it 3 restart options. What are they?
Answer: 1. Always
2. Never
3. OnFailure
..........
216. When you create a pod you can give it 3 restart options. What are the use
cases for each?
..........
217. If there is a pod already running and you want to restart using a DIFFERENT
image, how do you do that using command line?
..........
217. When your run k get pods , how do you sort by name?
..........
218. When your run k get pods , how do you sort by creationtime?
..........
219. In the YAML file for a pod that has more than 1 containers, how do they
container specs show up?
..........
220. In the YAML file , what is always the first line?
Answer: apiVersion:
..........
221. In the YAML file , how do you define what you are building (pod. replicaset,
secret, etc.) ?
..........
222. How to get logs from a container (not a pod) via command line?
..........
..........
Answer: Custom Resource Definition. You wanted to create your own type of
resource (like pod, rs, depployments etc), you use CRD to define your own
resource type.
Operators use CRD.
..........
..........
..........
Answer: Yes
..........
228. What is the esiest quickest way to create a service for a running pod?
..........
..........
230. If you are using minikube or kubeadm etc., what is a big limitation in terms or
Load Balancing?
Answer: There is no integrated load balancers (as you would have in AWS
or GCP)
..........
231. When does Kubernetes pull new version of image upon Pod creation ?
Answer: if either
1. Using images tagged :latest
2. imagePullPolicy: Always is specified
Source: https://stackoverflow.com/questions/33112789/how-do-i-force-
kubernetes-to-re-pull-an-image
..........
232. What is super quick way to create a service pointing to a running pod?
..........
Answer: Conatiners
..........
233. Why do we need Ingress when we alrady have "service" that can send traffic
to many pods of the same type?
Answer: One big reason is this: Without Ingress, you would have to have
a Load Balancer for every single web application you are hosting in your
cluster.
That can get very expensive and hard to manage.
With Ingress , you can have ONE load balancer that can take in
traffic for many web applications and forward them to the right pods.
..........
234. In the kube confi file, what does the URL point to? (for each context)
..........
Answer: 1. (If you want 1, then you cna leave out that option in an
imperative command)
..........
236. How can you update the image of a running deployment using an imperative
command ?
.
..........
..........
238. In the definition of a service what is "port" and what is "Target Port"?
..........
239. Your pod uses a Config Map. How Can you automatically restart pod if the
Config Map changes?
Answer: For this, you have to use deployment. In the config of the
deployment, use the CM.
When CM changes, and the new CM values breaks things,
Deployment is smart enough NOT to scale down.
BUT, if the new CM does NOT break things, deployment will scale
down and up with the new value.
..........
..........
Answer: 3 parts
1. Control Pane (Not much you can do)
2. Worker Nodes (making sure you are autoscaling)
3. Optimal usage of cpu/memory by pods (use Metrics Server or
open source tool kubecost)
..........
..........
..........
..........
..........
..........
..........
..........
..........
Answer: You can create a deployment using nginx image. That would be
one ay of doing it.
..........
..........
..........
Answer: Every pod comes with default service account , which in turns
gives the pod a token. Whatever permissions that token has, that is what a
pod can do.
..........
..........
255. When you create Nginx Ingress Controller via YAML file, what would be the
"Kind" ? (e.g. pod, secret, service ....)
..........
256. How can you create an YAML file on the fly without creating a resource ?
..........
Answer: Helm Charts. It has become industry standard for deploying 3rd
party applications. For deploying your own apps to your own Kubernetes
Cluster, you may choose something else because Helm is very easy to use.
Theere is a learning curve.
..........
..........
..........
..........
..........
..........
..........
Answer: Kyverno
OPA Gatekeeper
..........
265. You are setting a new image for deployment
imperatively. How can you make sure you can rollback
if needed?
..........
.......
267. You have web application hostend on containers on Kubernetes. This web app
is accessed via a domain e.g. foobar.com. You need to add a SSL certificate to
somewhere in your Kubernetes infrastructure for this domain.
Answer: This page does a fantastic job of explaning step by step with lots
of details.
https://devopscube.com/configure-ingress-tls-kubernetes/
Summary:
1. Get a certificate (either self-signed or otherwise)
2. deploy the application in Kubernetes cluster (this should
already be done)
3. create a TLS secret in Kubernetes
4. add TLS block to ingress object
5. Validate using simple curl command (e.g. curl https://
foobar.com -kv )
.
.......
268. What if you want to to actively prohibit pods of certain type to be created
(e.g. previleged containers)? How do you accomplish that?
Answer:
.......
.......
......
......
......
273. Easiest to get a bearer token for Kubernetes API server auth.
......
......
.
......
276. How does API Server authenticate a request for object creation in etcd?
......
277. How can you a list of types of resources (like pods, secrets, nodes, services
and lot more)
......
278. What is the MAIN difference between stateless and stateful sets (in terms of what is being
used in Kubernetes) ?
......
279. What are the main 3 things that a worker node will run?
Answer:
Kubelet
Proxy
Caontainer Run Time Engine
.
.....
Answer: kubelet
......
Answer: YAML
......
282. Kube Proxy runs on each worker node. For all practical
purposes, what is it, really?
......
.
.......
......
......
Answer: You can convert a Docker container image (e.g. Ubuntu) and add 2
packages (one of them is a File System package)
......
Answer: ?????
.
......
Finalizers are namespaced keys that tell Kubernetes to wait until specific
conditions are met before it
fully deletes resources marked for deletion. Finalizers alert controllers to
clean up resources the deleted object owned.
When you tell Kubernetes to delete an object that has finalizers specified
for it, the Kubernetes API marks the object for
deletion by populating .metadata.deletionTimestamp, and returns a 202 status
code (HTTP "Accepted"). The target object
remains in a terminating state while the control plane, or other components,
take the actions defined by the finalizers.
After these actions are complete, the controller removes the relevant
finalizers from the target object. When the
metadata.finalizers field is empty, Kubernetes considers the deletion
complete and deletes the object.
......
......
290. If you have a YAML file that has codes for 10 different
resources (pods, deployments etc). How can delete all resources
made from this YAML file?
......
......
292. Why do we need PV and PVC? Why not just PV or just PVC?
Answer: de-coupling. This way, you can define your PVs not knowing when they
will be used. Similarly, you can create PVC knowking PV already exists.
......
Answer: Again, de-coupling. You can define many kinds of storage (fast,
slow, EBS, GCS, NFS, on and on). You can just use them as you see fit.
.
......
Answer: Actually containers depends on the pods to "define" the volume and
give it a name. Container then uses that "name" and mounts it on whichever
directory it wants to. This way, two conatiners on the SAME pod can mount
the same volume on two different mounting locations.
......
295. Explain the flow from a CSR all the way to a user having
permission to describe a pod?
Answer:
1. CSR is created
2. That is submitted to Kubernetes cluster
3. Someone approves the csr within Kubernetes.
4. That creates a valid certificate which has an embedded user
5. On the other side of things, a role is create with certain permissions
(e.g. describe a pod)
6. That user/certificate is associated with that role via roleBinding. This
completes the path.
......
......
297. You are applying a YAML file. But, you get an error ,
something like: "expecting X got Y" (e.g. expecting map, got
string). How do you fix this?
Answer: Note the line number the error message tells you. See, which
attribute is mentioned in that line. Then, use kubectl explain command to
see what type of a thing is expected. May there is supposed to be an array
of strings. But, because of a typo, to Kubernetes, it looks like a string or
map/object. This will give a great clue as to what the typo is.
......
Answer: Node Pools are nodes that share the same configurations (e.g. cpu/
memory etc.). What if some of your pods needs more resources and you want
those pods to go into only a certian node pool. And, you do not want other
normal pods to go into those nodes. In this case, having 2 node pools would
be very useful. Node pools can also be used to segment out usage by
different teams/environments/departments.
......
Answer: values.yaml in Helm charts save all the env specific values (lets
say , server type, application name etc.). This way, we cna follow DRY
principles of coding when we code for multiple environments. These "values"
in turn can "feed" the configmaps in Kubernetes environments.
.
......
......
Answer: Sometimes there is a need for pod to be created for the sole reason
of doing a task ONLY once. "job" is how you define that.
......
......
......
......
304. You just created a cluster. How do you know what is running
there by default?
......
.
......
Answer: base64 encoding --> make a secret, "data" section, key-value pair
--> mount it on a pod/container
......
307. All I am giving you a docker image (that runs a web server).
You don't even have a cluster. Walk me through how you take this
service live. Assume that you don't scaling or HA.
Answer: Create a cluster. Upload the image one GCP container registry.
Creat a YAML file that creates a deployment using that image. Create a
service (Type Load Balancer) using that deployment. Create a DNS recording
pointing to the endpoint of that service.
......