Class 3 - Deploying app on Kubernetes Cluster Flashcards

1
Q

What is a pod?

A
  • A pod is a basic building block of Kubernetes
  • It is very easy to horizontally scale a Pod
  • A pod represents a unit of deployment in Kubernetes cluster
  • A pod encapsulates single or multiple containers along with storage and unique network IP.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Relation between pod and containers

A

A pod can be consumed in two ways

1) Single Container per Pod
2) Multiple containers per Pod

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Single container pod

A

One container per Pod
Widely used when a container runs on physical machine on top of an operating system.
Unique network IP from pod network CIDR
Storage volume for persistent data

NOTE
One should not run individual pods for multiple instances of same application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Most used design patterns for Multi container pod

A

1) Side car pattern
2) Adapter pattern
3) Ambassador pattern

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe Side car pattern and when to use it

A

Side car pattern is used when there is reader and writer relationship between containers. When one container writes and other container reads.

In sidecar pattern there are two or more containers, there will be writer containers and reader container.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Multi Container Pod

A

When multiple containers live inside same pod. This is not a good design in general. Like keeping application server and web server in a single pod.

Multiple containers share the same IP and share the same volume.
As all the containers will have same IP address, so multiple instances of application will not be able to run on same port in case of Multiple container pod.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Adapter container pattern (Similar to OOP adapter pattern)

A

We have a Formatter container. Formatter is going to format the output produced by any of container.

When you have FluentDB or Splunk container as part of a single pod. FluentDB or Splunk will take logs from web server or other containers and format in the configurable way.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Ambassador container pattern

A

We have a proxy service, which is the only point of entry to the application. The proxy acts as API gateway to the web application.

So all the requests will land on proxy and will be forwarded to actual application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Need for pod

A

1) Containers can work well alone but when scaled up, it becomes difficult to apply patches to them their management becomes cumbersome.
2) Secondly orchestrator is required to help in scaling out or scaling in
3) This orchestration is provided by Kubernetes by using Pod abstraction
4) Pods are building blocks of Kubernetes
5) Each pod manages single or multiple containers depending upon the application workload.
6) Through pod, one can manage multiple containers as one entity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What features do pods provide?

A

1) Self healing - restart pod if it crashes. Restart policies are there.
2) Auto scaling - scale on basis of certain metrics like CPU, disk
3) Load balancing using services - single endpoint for set of pods
4) Rolling update/rollback - zero downtime application upgrade
5) Resource monitoring and logging - Prometheus can be used for monitoring. Kubernetes does not come with inbuilt monitoring capabilities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Pod Lifecycle phases

A

Pending - Goes to this state when it is first created. Pod is waiting for a node to be assigned to it. It reflects the time spent in downloading the container images and creating them. It also means that system has accepted the Pod.
Pending status time = (Scheduling time) + (Download and start container)

Running - Pod is tied up with the node, and atleast one of the container is running.

Succeeded - A container’s termination in Kubernetes was successful. “It will not be restarted.” Some pods that are small batch jobs that start and complete after doing their job and don’t need to be run continuously go into this state.
As opposed to webserver or database server that run in daemon mode and run continuously.

Failed - When one or more container’s termination is unsuccessful. Termination due to failure is either because of non-zero exit status of container. Any failure that happens as part of container means that exit status is not zero. Then the pod goes in Failed state.

Unknown - When there is communication problem of a container with the host machine, status of the container cannot be obtained. Since there is no status update, Kubernetes system marks it as “Unknown”
For such errors channels should be checked first.
Unknown state does not mean that pod is not running. It may be running and serving requests but the master is not able to get the current status of the pod due to underlying networking issue or similar. It takes time to troubleshoot this status.

NOTE : Pod does not have to go through all the above phases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Do containers have private IPs inside pod?

A

No, container networking is disabled when we install CNI (Container networking interface by CNCF).
The only IP they will have is the one of the pod.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What can be said about Succeeded state and restart in Kubernetes?

A

By default policy, restart is set as true for all pods as a part of self healing policy.
If pod fails then Kubernetes will try to restart that pod. But if the pod goes in Succeeded state then it will not be restarted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If we kill the container inside pod, which state will it go to?

A

When we kill the app the exit status will be > 0, so it will go to the FAILED state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which are the bare minimum fields required while creating a pod?

A

1) apiVersion
2) kind - Pod, Deployment etc
3) metadata
4) spec

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Give example of a bare minimum pod yaml file

A
apiVersion: v1
kind: pod
metadata:
  name: mypod
  labels:
    version: v1
    app: webserver
spec:
  containers:
    - images: nginx:latest
      name: myfirstcontainer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to view detailed events for pod?

A

kubectl describe pod

will show detail about all the events and status. Like image information, events etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How to get pods information in yaml format?

A

kubectl get pods -o yaml

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to get logs of pods?

A

kubectl logs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How to preserve the data that is part of pod that will vanish if the pod dies?

A

We need to mount the volume from the pod to the host machine location. So we need to identify the location from pod that we need to preserve and mount it to physical location on host machine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How many types of volumes does Kubernetes support?

A

1) hostPath - this path is located at the host at which pod is running. location on physical VM where to mount the data.
2) emptyDir - Ephemeral. It is present till the lifecycle of pod. Once pod is deleted, the emptyDir will go away
3) configMap
4) GlusterFS
5) ….

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Sample hostPath volume mapping yaml

A
spec:
  containers:
    - name: mysql
      image: mysql
      volumeMounts:
        - path: /var/lib/mysql
          name: mysqlvol
  volumes:
    hostPath:
      path: /data
      type: DirectoryOrCreate
    name: mysqlvol

Volume mapping is two part
1) VolumeMount - where we provide location inside the container/ pod
2) Volumes - where we provide location of physical VM.
To map volumeMount and Volumes we need to provide the same name for volumeMount and volume

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Cardinality relation between volumeMounts and Volumes

A

We can have multiple volumeMounts pointing to the same volume. Or you can have 5 volumeMounts pointing to 5 different types of volumes on host machine.

24
Q

Equivalent of docker exec command in Kubernetes which can be used to enter the pod

A

kubectl exec -it

kubectl exec -ti mysql bash

25
Q

What problem does Kubernetes sercret resource solve?

A

Kubernetes secret provides a way to securely store sensitive information such as passwords, private keys that we don’t have to give directly into yaml file. Otherwise anyone who has access to the machine will be able to view those passwords and sensitive values.

26
Q

Where are secrets stored in Kubernetes?

A

Secrets are stored in etcd and is a key value pair.

27
Q

How to create and use secret resource in Kubernetes?

A

1) First we have to create secret resource. Secret is a resource in Kubernetes and its data contains key value pairs.

Definition of secret - mysecret
data:
password: root

2) Now we use that in yaml where we need to use the secret

env:
  name: MYSQL_ROOT_PASSWORD
  valueFrom:
    secretKey:
      name: mysecret
      key: password
28
Q

How is secret encoded in Kubernetes?

A

Kubernetes secret is encoded in Base64

29
Q

How many formats of secrets does kubernetes provide?

A

1) generic - encoded by Base64

2) clear - no encoding (data is exposed)

30
Q

Command to generate a secret resource

A

kubectl create secret generic –from-literal==

kubectl create secret generic mysql-pass –from-literal=password=root

31
Q

Command to get list of all secrets

A

kubectl get secret

returns list of all secrets created.

32
Q

Command to get detail of secret

A

kubectl describe secret

Shows detail of secret and will show keys but will not show the value. Will just show size of value

kubectl describe secret -o yaml

Shows encoded base 64 value of password.

33
Q

If secrets are only encoded then how do we get security if anyone can decode the base 64 value?

A

In Kubernetes we can enable RBAC (Role based access control) so that only few people have access to some privileged resources.

34
Q

Sample YAML file way to create a secret

A
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  password:
35
Q

What is the difference between ephemeral region of pod and emptyDir volume?

A

ephemeral region of pod will be cleaned up when the pod crashes. So after pod dies/crash if the pod comes back up it will not have that data and will start with fresh data.

But in case of emtpyDir, the data lasts till the lifecycle of pod. So even if pod crashes and comes back up the data will be preserved.

36
Q

Create pod definition for following multi-container scenario.
Need to implement sidecar pattern for nginx container. Nginx container will serve index.html and the sidecar i.e. a debian based container will keep appending date output to index.html per second.

HINT: Use emptyDir volume mount

A
apiVersion: v1
kind: Pod
metadata:
  name: nginxsidecar
spec:
  volumes:
  - name: html
    emptyDir: {}
  containers:
  - name: 1st
    image: nginx
    volumeMounts:
    - name: html
      mountPath: /usr/share/nginx/html
  - name: 2nd
    image: debian
    volumeMounts:
    - name: html
      mountPath: /html
    command: ["/bin/sh", "-c"]
    args:
      - while true; do
          date >> /html/index.html;
          sleep 1;
        done
37
Q

How to view logs specific to a particular container when working with multi-container pods

A

If we don’t give any container name when trying to view logs in multicontainer pod then it will be confused and not show any output.
So we have to tell it which container logs need to be shown

kubectl logs -c

38
Q

How to run exec command for a particular container when working with multi-container pods

A

kubectl exec -ti -c

e.g.
kubectl exec -ti nginxsidecar -c 1st bash

Container name is required because without it kubernetes will not know which container to fire that command on.

39
Q

What are init containers?

A

Init containers are containers that run as part of actual pod deployment. You will deploy primary applications and have flexibility of deploy init containers.
Init containers is container that runs before the application container starts. There is dependency that application containers cannot start till the init container completes. So init containers always run to completion.

40
Q

Is init container part of application image?

A

No, init containers have custom code which is not part of application image.

41
Q

What happens if init container fails?

A

Kubernetes keeps on restarting the pod till the init container succeeds.

42
Q

What is the use of init containers?

A

Init containers are used to perform some pre-requisites. For example: In case of multi-tiered application, web containers should start only after database server starts. As part of web server deployment we can deploy init container which is a small script and does nslookup on the database container IP address or container service name.

Similarly downloading some content from GitHub repository for CI/CD to start, checking if certain ports are available or not, making sure dependent applications or services are up or not. These things are not responsibility of application. These things are done by infrastructure deployment. This responsibility is taken by init container.

43
Q

Is init container considered as multi-container pod?

A

No init container is not considered as multi-container pod. As init container runs before application container and will complete before application container starts. There will only be one container running. In multi-container there are multiple containers running in parallel.

44
Q

Is it mandatory to have init containers?

A

No it is not mandatory.

45
Q

Can we have multiple init containers?

A

Yes, a pod may have multiple-init containers.

If there are multiple all the containers run to completion before the application is started.

46
Q

What are advantages of multiple-init containers?

A

Since they a

47
Q

What is busybox?

A

Busybox is an OS image that is very lightweight and is useful to run lightweight containers that have some startup scripts as part of init containers.

48
Q

Are init containers visible in describe?

A

Yes, kubectl describe will provide information about the init container, its status and if completed the application container will be started.

49
Q

What is difference between kubectl create and kubectl apply?

A

Kubectl create is used to create the pod for the first time. Running that command again for an existing pod will give AlreadyExists error.
While lets say we change the image version inside pod spec and the fire apply. That will re-configure the pod.

50
Q

What are Pod Presets?

A

Pod preset allows you to reuse some information lets say ports, volumeMounts, environment variables, etc that need to be repeated for every deployment in different projects.
Pod Preset in an API resource which is used to provide additional runtime requirement to a Pod at the time of creation.

51
Q

How does Pod Preset help us?

A

It helps us because if you are working as developer, or devops person who so ever is maintainer of yaml files, as Pod template authors we don’t need to know about the environment variables, build number, that is something that is automated.

52
Q

Who is Pod template author?

A

Person who writes YAML files are called pod template authors.

53
Q

Relation between pod and pod presets?

A

While pods are created, it inherits all the extra information required from the Pod presets.

54
Q

How to view CPU utilization and resource consumption information of Pod (not individual containers) ?

A

kubectl top

command is used to view that information.

55
Q

How to view per container resource consumption information?

A

We have use some other tools like Prometheus or MetricServer to get that information, kubernetes does not provide in built way to monitor metrics of individual containers.

56
Q

What are pause containers?

A

TBA