Configuration Flashcards

1
Q

What is the ENTRYPOINT statement of a Dockerfile?

A

Defines the command that is run at startup of the container

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

What is the CMD statement of a Dockerfile

A

an array of parameters that are passed to the container as arguments at startup

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

What Dockerfile statement is equivalent to spec.containers[].command of a kubernetes Pod specification

A

spec.containers[].command is equivalent to the ENTRYPOINT statement in a Dockerfile

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

What Dockerfile statement is equivalent to spec.containers[].args of a kubernetes Pod specification

A

spec.containers[].args is equivalent to the CMD statement in a Dockerfile

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

In Pod spec.containers[], what parameter sets the environment variables

A

spec.containers[].env is an array of name-value objects, e.g.:

spec: containers: - env: - name: FOO value: bar

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

What are three different ways of setting environment variables for a container in kubernetes

A
  1. spec.containers[].env property of Pod (or pod template in replicaset or deployment)
  2. configmap
  3. secrets
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to reference a single environment variable value from a configmap in a Pod definition file

A

spec: containers: - env: - name: FOO valueFrom: configMapKeyRef: name: config-map-name key: config-map-key-name

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

How to reference an environment variable value from a secret within a Pod definition file

(e.g. a secret key with name my-secret)

A

spec: containers: - env: - name: FOO valueFrom: secretKeyRef: my-secret

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

How to reference an entire configmap as environment variables in a Pod definition file

A

spec: containers: - envFrom: - configMapRef: name: config-map-name

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

What is the apiVersion of a configmap?

A

v1

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

In a ConfigMap definition, how is a key created?

(e.g. a config map of name my-configmap including a key with name foo and valuebar)

A

apiVersion: v1 kind: ConfigMap metadata: name: my-configmapdata: foo: bar

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

What is the imperative command for getting a list of ConfigMaps

A

kubectl get cm

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

What is the imperative command for viewing the contents of a ConfigMap cm1

A

kubectl describe cm cm1

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

What is the imperative command for viewing the contents of all ConfigMaps

A

kubectl describe cm

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

What is the purpose of a ConfigMap?

A

A ConfigMap is an API object used to store non-confidential data in key-value pairs.

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

What is the purpose of Secrets

A

Kubernetes Secrets let you store and manage sensitive information

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

What is the apiVersion of a Secret

A

v1

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

In a Secret specification, what are the four top-level keys?

A

apiVersion: v1kind: Secretmetadata: {}data: {}

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

What is the imperative command for creating a secret named FOO with sensitive data BAR

A

kubectl create secret mysecret1 --from-literal=FOO=$(echo BAR | base64)

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

How to encode a value BAR into a kubernetes secret

A

echo BAR | base64

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

How to decode a kubernetes secret

A

echo QkFSCg== | base64 -d

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

How to reference all values within a secret as environment variables within a Pod definition file

A

spec: containers: - envFrom: - secretRef: name: secret-name

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

In a Pod specification, spec.containers[], how do you run the container as user 1000?

A

spec: containers: - securityContext: runAsUser: 1000

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

In a Pod specification, spec.containers[], how do you give user 1000 MAC_ADMIN capabilities?

A

spec: containers: - securityContext: runAsUser: 1000 capabilities: add: ["MAC_ADMIN"]

25
Q

What is the purpose of a ServiceAccount?

A

A service account provides an identity for processes that run in a Pod. Processes in containers inside pods can contact the apiserver. When they do, they are authenticated as a particular Service Account.

26
Q

What is the apiVersion of ServiceAccount?

A

v1

27
Q

What is the imperative command for creating a ServiceAccount named sa1?

A

kubectl create sa sa1

28
Q

What is the imperative command for listing all ServiceAccounts?

A

kubectl get sa

29
Q

When a ServiceAccount is created, what happens and how is it connected to a pod

A

A ServiceAccount creates a Secret, which stores a token which can be used to access the ApiServer. The token is available to pods by mounting the secret as a volume.

30
Q

In a pod specification, how do we define we should use the sa1 ServiceAccount?

A

spec: containers: [] serviceAccount: sa1

31
Q

If a ServiceAccount is not specified in a pod (or pod template), what happens?

A

The default serviceAccount is mounted.

32
Q

How can you prevent the default ServiceAccount from being mounted to a pod?

A

spec: automountServiceAccountToken: false

33
Q

What is the default minimum resource request for a Pod assumed by Kubernetes?

A

0.5 CPU 256Mi memory

34
Q

In Pod definition file how do you request a minimum of 1Gi memory and 1 CPU?

A

spec: containers: - resources: requests: memory: "1Gi" cpu: 1

35
Q

What is the lowest value of CPU that can be requested for a Pod?

A

0.1 CPU. (= 100m CPU)

36
Q

What is 1 CPU equivalent to in AWS?

A

1 AWS vCPU

37
Q

In Pod definition, how do you request a limit of 2Gi memory and 2CPU?

A

spec: containers: - resources: limits: memory: "2Gi" cpu: 2

38
Q

What happens if a pod uses more CPU than its limit?

A

It is throttled

39
Q

What happens if a pod uses more memory than its limit?

A

It can temporarily use more memory, but if it is persistently using more memory then it is terminated

40
Q

On what kubernetes entity are taints applied?

A

Nodes

41
Q

On what kubernetes entity are tolerations applied?

A

Pods

42
Q

What is the imperative command to apply a taint?

A

kubectl taint nodes node-name key=value:taint-effect

43
Q

What are the different types of taint effect?

A
  • NoSchedule
  • PreferNoSchedule
  • NoExecute
44
Q

How do NoSchedule and NoExecute taints differ?

A

NoSchedule prevents new pods being scheduled and run on a node, but does not effect existing ones.

NoExecute will also apply NoSchedule and will evict existing pods which cannot tolerate the taint.

45
Q

In the Pod definition, how are tolerations applied? (e.g. for taint foo=bar with taint effect NoSchedule)

A

spec: tolerations: - key: "foo" operator: "Equal" value: "bar" effect: "NoSchedule"

NB. All values have to be quoted

46
Q

What taint is present on the master node which prevents Pods being scheduled there?

A

node-role.kubernetes.io/master:NoSchedule

47
Q

In the Pod definition file, how are Pods limited to only run on a particular node given a single label?

A

spec: nodeSelector: node-label-key: node-label-value

48
Q

What is the imperative command to label a node? (e.g. node-name with key foo and value bar)

A

kubectl label nodes node-name foo=bar

49
Q

What are the limitations of nodeSelector?

A

Only matches a single label and value, cannot match complex matching rules (e.g. OR, or NOT)

50
Q

In the Pod definition, create an affinity for nodes with label foo=bar

A

spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: foo operator: In values: - bar

51
Q

In the Pod definition, create an affinity for nodes with label foo=bar OR foo=buzz

A

spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: foo operator: In values: - bar - buzz

52
Q

In the Pod definition, create an anti-affinity for nodes with label foo=bar

A

spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: foo operator: NotIn values: - bar

53
Q

In the Pod definition, create an affinity for any node labelled with a key of foo and any value

A

spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: foo operator: Exists

54
Q

What are the two current types of node affinities?

A
  • requiredDuringSchedulingIgnoredDuringExecution
  • preferredDuringSchedulingIgnoredDuringExecution
55
Q

What is the planned type of node affinity?

A

requiredDuringSchedulingRequiredDuringExecution

56
Q

How are taints, tolerations, and affinity used together?

A

taints prevent non-tolerant pods being scheduled on a node, but they do not guarantee that a tolerant pod will be scheduled on the node. affinity ensures that a pod will be scheduled on a matching node, but does not guarantee that other pods will not also be scheduled on that node. Together, affinity ensures a pod is scheduled on a matching node and taints ensure non-tolerant pods are not scheduled on that pod.

57
Q

In the Pod definition, how do you run a shell script?

e.g. run while true; do echo hello; sleep 10;done

A

spec: containers: - command: - "/bin/sh" args: - "-c" - "while true; do echo hello; sleep 10;done"

58
Q

What is the imperative command for creating a resourcequota?

(e.g. CPU of 1, memory of 1Gi, and 2 pods)

A

kubectl create quota myrq --hard=cpu=1,memory=1G,pods=2