Kubernetes 2 Flashcards

1
Q

What happens when you run the kubectl delete command on a Pod without specifying the –grace-period parameter?

A

The Pod will be marked for deletion, but it may take some time for it to be terminated, and it will go through the standard termination process.

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

How can you run a command inside a running Pod interactively using kubectl?

A

You can use the kubectl exec -it command followed by the Pod name and the program you want to run to open an interactive session inside the Pod.

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

What does the initContainer section in a Pod’s YAML definition specify?

A

The initContainer section specifies one or more containers that run before the main application container starts and are used to initialize or prepare the environment for the application.

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

What happens if an init container in a Pod fails?

A

If an init container fails, the kubelet will repeatedly restart it until it succeeds, unless the restart policy is set to “Never.”

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

What is the purpose of using init containers in Kubernetes?

A

Init containers are used to perform tasks such as waiting for dependencies, initialization, or setup before the main application container starts, helping to keep the main container focused on the application logic.

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

In the context of Kubernetes, what does the term “ephemeral” mean when referring to Pods?

A

In Kubernetes, “ephemeral” means that Pods are short-lived and disposable. They can be replaced easily and are not meant to store long-term data.

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

How do you specify environment variables for a container within a Pod’s YAML definition?

A

You can specify environment variables in the env section of a container’s definition within the Pod’s YAML file.

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

What is the purpose of labels in a Pod’s definition?

A

Labels are used to identify, describe, and group related sets of objects and resources, allowing for easy organization and selection of Pods based on specific criteria.

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

How does a Pod’s deletion process work in Kubernetes?

A

When you delete a Pod in Kubernetes, it is marked for deletion, and a grace period of 30 seconds is added. The kubelet sends a termination signal to the container, and if it doesn’t stop within the grace period, the container is killed.

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

Why is the kubectl describe command useful when troubleshooting Pods?

A

The kubectl describe command provides detailed information about a Pod, including events and statuses, making it valuable for diagnosing issues and understanding the state of the Pod.

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

What is the purpose of an init container in Kubernetes?

A

An init container in Kubernetes is used to perform setup tasks or checks before the main application container starts. It helps initialize the environment for the main container.

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

How do init containers differ from main application containers in terms of their behavior?

A

Init containers run to completion before the main application containers start. They are designed for one-time initialization tasks or checks and do not continuously run like the main containers.

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

Can a Pod have multiple init containers, and if so, how do they execute?

A

Yes, a Pod can have multiple init containers. They execute in sequence, and each init container must complete successfully before the next one starts.

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

What happens if an init container in a Pod fails to complete successfully?

A

If an init container fails to complete successfully (exits with a non-zero status), Kubernetes will repeatedly restart it until it succeeds, unless its restart policy is set to “Never.”

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

When would you use an init container in a Pod?

A

Init containers are useful when you need to perform tasks such as database initialization, service availability checks, or configuration setup before launching the main application container in a Pod.

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

How does an init container’s completion affect the start of the main application container?

A

The main application container in a Pod starts only after all init containers have successfully completed.

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

What happens if an init container fails to complete successfully and its restart policy is set to “Always”?

A

If an init container fails and its restart policy is set to “Always,” Kubernetes will keep restarting it in an attempt to make it succeed indefinitely.

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

Can init containers share volumes or network namespaces with the main application container?

A

Yes, init containers can share volumes and network namespaces with the main application container, allowing them to exchange data or access network resources.

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

Is it possible to run commands inside an init container like in a regular container?

A

Yes, you can run commands inside an init container just like in a regular container. Init containers are essentially lightweight containers.

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

In what scenarios might you use multiple init containers in a Pod?

A

Multiple init containers can be used when you have multiple initialization tasks that need to be completed sequentially before the main application container can start.

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

What is a node pool in Kubernetes?

A

A node pool in Kubernetes is a group of virtual machines (nodes) of the same size within a cluster.

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

How can a cluster have multiple node pools, and what’s the purpose of having them?

A

A cluster can have multiple node pools, and each node pool can host virtual machines of different sizes. Node pools allow you to manage different types of nodes within a single cluster, such as nodes with and without GPUs, to optimize resource allocation.

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

In the context of Docker Desktop, why is there usually only one node?

A

Docker Desktop typically runs with only one node because it’s designed for local development and testing, where running master components and application containers on the same node is sufficient.

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

What does network traffic in Kubernetes go through on each node?

A

In Kubernetes, network traffic goes through the kube-proxy (kube proxy) on each node.

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

Which container runtimes does Kubernetes support, and what is the container runtime interface specification?

A

Kubernetes supports container runtimes that implement the Kubernetes Container Runtime Interface (CRI) specification. The CRI is a standard interface that container runtimes must follow to work with Kubernetes.

26
Q

What was the situation with the Mobi container runtime in earlier Kubernetes versions?

A

In Kubernetes versions prior to 1.19, the Mobi container runtime was used, but it didn’t fully implement the CRI specification. It received container runtime interface calls through a shim.

27
Q

How does the removal of Mobi affect Docker containers in Kubernetes?

A

The removal of Mobi doesn’t impact running Docker containers in Kubernetes. Docker containers will continue to run as usual. What changes is the ability to access the Docker engine directly inside a node, which requires the use of tools like docker or ctr instead of Docker commands directly within a node.

28
Q

What is a pod in Kubernetes?

A

In Kubernetes, a pod is the smallest deployable unit. It represents a single instance of a running process and can contain one or more containers.

29
Q

How do containers within a pod share resources like IP address and storage volumes?

A

Containers within a pod share the same network namespace, which means they have the same IP address and can communicate using localhost. They can also share storage volumes mounted into the pod.

30
Q

Why are pods considered ephemeral?

A

Pods in Kubernetes are considered ephemeral because they can be easily created, deleted, and replaced. If a pod crashes or needs to be updated, it is replaced with a new one.

31
Q

What is the typical usage of a pod with multiple containers?

A

In a pod with multiple containers, there is usually one main application container where the primary logic resides, and additional helper containers that provide services to the main application container.

32
Q

What is the purpose of having multiple containers within a single pod?

A

Multiple containers within a pod can share resources, communicate easily through localhost, and are scheduled and scaled together, making it convenient for certain scenarios where closely related processes need to run together.

33
Q

How does Kubernetes ensure that pods are replaced when they fail?

A

Kubernetes monitors pods, and if a pod fails or crashes, it is automatically replaced with a new one, ensuring the desired state is maintained.

34
Q

What happens if a pod’s main application container crashes?

A

If a pod’s main application container crashes, Kubernetes will restart the entire pod, including all the containers within it.

35
Q

Can multiple pods share the same IP address?

A

No, each pod in Kubernetes has its own unique IP address.

36
Q

What are the different phases in a pod’s lifecycle?

A

The different phases in a pod’s lifecycle are:

Pending
Running
Succeeded
Failed
Unknown
CrashLoopBackOff

37
Q

What does the “Pending” phase in a pod’s lifecycle indicate?

A

The “Pending” phase indicates that the pod has been scheduled to run but is waiting for resources to be allocated and containers to be created.

38
Q

How is a pod’s state tracked during its lifecycle?

A

A pod’s state during its lifecycle is tracked by Kubernetes and stored in its etcd datastore, ensuring a single source of truth for the cluster’s state.

39
Q

What is the “CrashLoopBackOff” phase in a pod’s lifecycle?

A

The “CrashLoopBackOff” phase indicates that the pod has repeatedly crashed and is not able to recover. Kubernetes stops attempting to restart the pod.

40
Q

What is a Pod in Kubernetes?

A

A Pod is the smallest unit of work in Kubernetes, representing a single instance of a running process in a cluster. It can contain one or more containers.

41
Q

How can you define a Pod in Kubernetes?

A

You can define a Pod in Kubernetes using a YAML file that specifies the Pod’s configuration, including container images, environment variables, labels, and more.

42
Q

What is the difference between defining a Pod declaratively and imperatively?

A

Declarative Pod definition involves creating a YAML file with the desired configuration and using kubectl create -f to create the Pod. Imperative Pod creation uses kubectl run to create a Pod directly from the command line.

43
Q

How can you run a Pod imperatively using kubectl?

A

You can run a Pod imperatively using kubectl run <pod-name> --image=<container-image> to create a Pod with the specified container image.</container-image></pod-name>

44
Q

What command can you use to see a list of running Pods in a cluster?

A

You can use the kubectl get pods command to see a list of running Pods in a cluster.

45
Q

How can you interact with the shell inside a running Pod?

A

You can interact with the shell inside a running Pod using the kubectl exec -it <pod-name> -- <command></command> command, which opens an interactive shell session within the Pod.</pod-name>

46
Q

How can you delete a Pod?

A

You can delete a Pod using the kubectl delete pod <pod-name> command.</pod-name>

47
Q

What is an Init Container in Kubernetes?

A

An Init Container is a special type of container in a Pod that runs before the main application container starts. It is used to perform initialization tasks or checks before the application container begins.

48
Q

Why are Init Containers useful?

A

Init Containers are useful for performing tasks such as waiting for a database to be ready, downloading configuration files, or performing pre-launch checks. They ensure that prerequisites are met before the main application container starts.

49
Q

Can a Pod have multiple Init Containers?

A

Yes, a Pod can have multiple Init Containers. They are executed in order, one after the other, and each Init Container must complete successfully before the next one starts.

50
Q

What happens if an Init Container fails to complete successfully?

A

If an Init Container fails to complete successfully (exits with a non-zero status), Kubernetes will restart it until it succeeds or until the Pod’s restart policy is exceeded.

51
Q

How do you define Init Containers in a Pod’s configuration?

A

Init Containers are defined within the spec section of a Pod’s YAML configuration file, similar to regular containers. They are listed under the initContainers field.

52
Q

What are some common use cases for Init Containers?

A

Common use cases for Init Containers include database schema migrations, downloading application dependencies, running pre-launch checks, and waiting for external services to be ready.

53
Q

How can you define a Pod in Kubernetes declaratively?

A

You can define a Pod declaratively by creating a YAML file that specifies the Pod’s configuration, including container images, environment variables, and volumes.

54
Q

What is the difference between defining a Pod declaratively and running a Pod imperatively?

A

Defining a Pod declaratively involves creating a YAML file with the Pod’s configuration, while running a Pod imperatively involves using a command like kubectl run to create a Pod directly.

55
Q

What is an Init Container in Kubernetes?

A

An Init Container is a special container that runs before the main application containers in a Pod, primarily used for tasks like initialization, pre-processing, or waiting for dependencies.

56
Q

How can you define an Init Container in a Pod’s configuration?

A

Init Containers are defined within the initContainers section of a Pod’s YAML configuration, each with its image and commands.

57
Q

Why would you use an Init Container in a Pod?

A

Init Containers are useful when you need to perform tasks like setting up configuration files, waiting for a database to be ready, or any initialization step required before the main application starts.

58
Q

What happens if an Init Container fails to run?

A

If an Init Container fails to run (exits with an error status), Kubernetes will restart it until it succeeds or reaches the specified restart policy.

59
Q

Can multiple Init Containers be defined in a single Pod?

A

Yes, you can define multiple Init Containers in a single Pod, and they will run in the order they are defined, one after the other, before the main application container starts.

60
Q

How can you check the status and logs of Init Containers in a Pod?

A

You can use the kubectl describe pod <pod-name> command to view the status and logs of Init Containers within a Pod.</pod-name>