Main Flashcards

1
Q

Imperative Command for Creating a Pod

A

kubectl run nginx –image=nginx

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

Imperative Command for Creating a Deployment

A

kubectl create deployment –image=nginx nginx

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

How do commands and arguments in Kubernetes overwrite what’s written in the DockerFile?

A

The attribute, “command:[“sleep2.0”]” inside the containers attribute overwrites the Docker command: ENTRYPOINT[“sleep”]. Same thing with args:[“10”] overwriting CMD[“5”]

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

Create a command defined in Kubernetes that will execute once a container has launched

A

containers:

  • name: ubuntu
    image: ubuntu
    command: [“sleep”]
    args: [“10”]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does one use ConfigMaps/Secrets?

A
  1. Create ConfigMap Object

2. Attach ConfigMap Object to Pod

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

How do you define environment variables in a pod (No configmap)?

A

env:

  • name: APP_COLOR
    value: PINK
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you attach a ConfigMap object to a pod?

A
containers:
-  name: simple-webapp
   image: simple-webapp
   envFrom:
      -  configMapRef:
            name: {NameOfConfigMap}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you add a pod/deployment/replicaset to a namespace (2 methods)?

A
  1. Using imperative command: –namespace={namespace}

2. Adding namespace dictionary value to metadata attribute in yaml config

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

What has the –dry-run command changed to?

A

–dry-run=client

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

How do you format secret object values (2 methods)?

A
  1. Imperative commands: kubectl create secret –from-literal=key:value –from-literal=key2:value2
  2. a. Linux commands: echo -n ‘{secret}’ | base64 –decode
    b. kubectl create -f
    c.
    data:
    secret: decodedvalue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you attach a Secret object to a container?

A
containers:
-  name: simple-webapp
   image: simple-webapp
   envFrom:
      -  secretRef:
            name: {nameOfSecretObject}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you attach a Secret to a pod (in pod definition)?

A
env:
  -  name: {secretName}
     valueFrom:
       secretKeyRef:
         name: app-secret
         key: {secretValue}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you attach a Secret to a pod (using volumes)?

A

volumes:
- name: app-secret-volume
secret:
secretName: app-secret

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

How do you check who’s listed as the security context for running a particular container?

A
  1. kubectl exec ubuntu-sleeper – whoami

2. Do an -o yaml and see security context

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

How do you format a security context for a pod?

A

spec:
securityContext:
runAsUser: 1000
runAsGroup: 2000

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

How do you format a security context object for a container?

A
spec:
  containers:
    - name: ubuntu
      image: ubuntu
      command ["sleep", "23"]
      securityContext:
        runAsUser: 1000
        runAsGroup: 2000
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Does a security context on a pod or container take precedence?

A

Pod security contexts overwrite container security contexts.

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

How do you create a service account?

A

kubectl create serviceaccount {serviceAccountName}

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

How do you get a service account token?

A
  1. Find the secret ID: kubectl describe serviceaccount {serviceAccountName}
  2. Describe secret with secret ID: kubectl describe secret {secretID}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you make a call to the kubernetes api endpoint using a service account?

A
  1. Get Service Account token (see question 20)

2. curl {endpont url} –insecure –header “Authorization: Bearer {token}”

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

At what level do you set resource requirements in a pod definition file?

A

The container level. Example:

containers:
- name: simplewebapp
  image: simple-webapp
  resources:
    requests:
      memory: "1Gi"
      cpu: 1
    limits: 
      memory: "2Gi"
      cpu: 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Can a container use more than its resource limit for cpu and memory?

A

If a container reaches its limit for cpu, the node will throttle the cpu. If a container reaches its limit for memory, it can go above its limit, but if it keeps doing this, the pod will be destroyed.

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

How do you taint a node?

A

kubectl taint nodes {nodeName} key:value:taintEffect

Example: kubectl taint nodes node1 app=blue:NoSchedule

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

What is the difference between taints and tolerations?

A

Taints are applied to nodes while tolerations are applied to pods. A pod needs to have x toleration in order to land on x taint.

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

What is the taint effect, NoSchedule?

A

Pods will not be scheduled on the node

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

What is the taint effect, PreferNoSchedule?

A

Pods will have a preference to not be scheduled on the node.

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

What is the taint effect, NoExecute?

A

New pods will not be scheduled on the node, existing pods will be evicted from the node.

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

How do you label nodes?

A

kubectl label nodes {nodeName} {labelKey}:{labelValue}

example: kubectl label nodes node-1 size=Large

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

How do you format a node selector inside a pod definition file?

A

spec:
nodeSelector:
size: Large

30
Q

When would you use a node affinity over a node selector?

A

When the labels require conditional statements. For example, you want pods to go on small OR Large nodes. Or any node that is NOT small.

31
Q

How do you format a Node Affinity inside a pod definition file?

A
spec:
  affiniity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
            - key: size
              operator: NotIn | In | Exists
              values:
              - Small
32
Q

Node Affinity Types (3)

A

requiredDuringSchedulingIgnoredDuringExecution
preferredDuringSchedulingIgnoredDuringExecution
requiredDuringSchedulingRequiredDuringExecution

33
Q

In multi-container pods, there are three design patterns. What are those three main design patterns?

A
  1. Sidecar
  2. Adapter
  3. Ambassador
34
Q

What is the difference between Sidecar and Adapter design patterns?

A

Sidecar extends the functionality of the main container, Adapter transforms/modifies the output of the main container.

35
Q

Briefly describe the Ambassador design pattern

A

The ambassador design pattern has a small container that essentially acts as a proxy for the main container. An example of this would be connecting to different databases based on current environment.

36
Q

At what level do you specify a readiness probe in a configuration file?

A

The container level. Example:

containers:
  -  image: nginx-webapp
     name: nginx-webapp
     readinessProbe:
       httpGet: /* | tcpSocket:\n\t port  | exec:\n\t command: ["command"]*/
         path: /api/ready
         port: 8080
       initialDelaySeconds: 10*
       periodSeconds: 5*
       failureThreshold: 8*
* = for httpGet probes only
37
Q

What is the difference between a readiness probe and a liveness probe?

A

Readiness probe is executed on creation while liveness probe is executed periodically to see if the website/webservice is healthy

38
Q

At what level do you specify a liveness probe in a configuration file?

A

The container level. Example:

containers:
  -  image: nginx-webapp
     name: nginx-webapp
     livenessProbe:
       httpGet: /* | tcpSocket:\n\t port  | exec:\n\t command: ["command"]*/
         path: /api/ready
         port: 8080
      initialDelaySeconds: 10*
      periodSeconds: 5*
      failureThreshold: 8*
* = for httpGet probes only
39
Q

How do you view logs for a pod?

A

kubectl logs -f {podId} {podId2}

40
Q

What commands do you use to do basic monitoring of nodes and pods?

A

kubectl top node

kubectl top pod

41
Q

How do you get all Kubernetes objects with labels x and y under category a and b, respectively?

A

kubectl get all –selector a=x, b=y

42
Q

When using a pod selector, how do you mark each pod to label?

A

metadata:
labels:
category: labelName

43
Q

What should you watch out for when using labels in ReplicaSets with regard to ReplicaSets having two defined areas for labels?

A

Because ReplicaSets dynamically generate pods, the pod labels also need to be defined. This can be done in the template attribute under the specs attribute in the configuration file. To define labels for the replicaset specifically, this needs to be done in the metadata: labels section.

44
Q

What is the difference between the “recreate” and “rolling update” deployment strategies?

A
Recreate = All pods go down, then all pods go back up.
Rolling = One pod goes down, then new pod goes up until all of them have been updated.
45
Q

How do you create and update a deployment in Kubernetes?

A

kubectl apply -f deployment-def.yaml
You can also use:
1. kubectl create -f dep-def.yaml
2. kubectl set image deployment/newimage

46
Q

How do you check the status of a deployment?

A

kubectl rollout status deployment/myapp-deployment

kubectl rollout history deployment/myapp-deployment

47
Q

How do you roll back a deployment in Kubernetes?

A

kubectl rollout undo deployment/myapp-deployment

48
Q

What is the imperative command to create a deployment with 4 replicas?

A

kubectl create deployment nginx –image=nginx –replicas=4 -o yaml –dry-run=client

49
Q

What is the imperative command to scale a deployment to use a different number of replicasets?

A

kubectl scale deployment nginx –replicasets=4

50
Q

What is a job object?

A

A short term pod. Runs and terminates. Example:

apiVersion: batch/v1
kind: Job
metadata:
  name: math-add-job
spec:
  template:
    spec:
      containers:
        - name: math-add
          image: ubuntu
          command: ["sleep", "5"]
      restartPolicy: Never
51
Q

How to create 3 of the exact same jobs with the same object?

A

Specify the “completions” attribute. Specify the parallelism attribute to have these jobs run at the same time.

52
Q

What is a cron job?

A

A reoccurring job on a schedule.

53
Q

What is the cronjob time format? (* for each time slot)

A

“minute(0-60)* hour(0-60)* day of the month(0-31)* month(1-12)* day of the week(0-6)*”

54
Q

What is the difference between persistent volume and persistent volume claims?

A

Persistent volume claim is essentially, “What do you want?” while persistent volume is essentially, “How do you want it implemented?”. For example PVC will NOT have any information regarding HOW the storage will be stored, it just goes through the list of requirements and tries to best match to the PV defined.

55
Q

What 3 things need to be defined in a persistent volume?

A

Access type, capacity, and location. Example file:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-voll
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 1Gi
  hostPath: /* This can vary between AWS, Azure, etc, look it up for the appropriate settings */
    path: /tm
56
Q

How is storage referenced from Pod to PV? (High-level)

A

The pod has a volume ‘dns’ that directly references a PVC which references a Persistent Volume.

57
Q

In a pod/replicaset/deployment config file, how do you reference a PVC?

A
spec:
  volumes:
    - name: persistent-storage-name
      persistentVolumeClaim:
        claimName: {PVCName}
58
Q

What 2 things should you specify in a persistent volume claim configuration file?

A

Access type and storage requirements.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Mi
59
Q

NodePort IP Address Range

A

30000-32767

60
Q

What 4 things need to be specified in a service configuration object file?

A

Type (NodePort or ClusterIp), port, target port, and selector (for which object the service will communicate with)

apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  type: NodePort | ClusterIP *default*
  ports:
    - port: 80
      targetPort: 80 /* optional, by default it's same as 'port' */
      nodePort: 30008 /* optional, by default it's randomly assigned */
    selector:
      app: myapp
      type: front-end
61
Q

Differentiate Port, Target Port, and Node Port

A

Port is the port of the Service, target port is the port of the object(s) the service is communicating with, and Node Port is the port exposed outside of the network

62
Q

True or False: When running Kubernetes on multiple nodes, when you create a service, this same service can automatically be applied to all the nodes.

A

True

63
Q

What are the major components of setting up ingress networking (High-Level)?

A

You need two items:

  1. Ingress Controller (essentially a separate Pod/Deployment along with a Service that can be used to utilize routing and proxying. Based on nginx container for example);
  2. Ingress rules(a separate Kubernetes resourse with kind: Ingress. Will only take effect if Ingress Controller is already deployed)
64
Q

What 3 critical things do ingress rule objects need using a configuration file?

A

Annotations, what will be re-routed (path, host), and where should it go (ie selectors)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: ingress-pay
  namespace: critical-space
spec:
  rules:
  - http:
      paths:
      - host: *
        path: /pay
        pathType: Prefix
        backend:
          service:
            name: pay-service
            port:
              number: 8282
65
Q

Imperative command to create a service

A

kubectl create service nodeport {serviceName} –tcp=80

kubectl create service clusterip my-svc –clusterip=”None”

66
Q

Imperative command to create a configmap

A

kubectl create configmap {name} –from-literal=key1=config1 –from-literal=key2=config2

67
Q

Imperative command to create a namespace

A

kubectl create namespace {name}

68
Q

Ingress vs Egress traffic

A

Ingress is incoming, Egress is outgoing traffic. This excludes responses (i.e. 200 response with content)

69
Q

What major thing is specified in a networking policy object?

A

What Egress/ingress rules need specification.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: db-policy
spec:
  podSelector:
    matchLabels:
      role: db
  policyTypes:
  - Ingress
  - Egress
  ingress:
  - from:
    - podSelector:
      matchLabels:
        name: app
    ports:
    - protocol: TCP
      port: 3306
   egress:
   - to:
      - ipBlock:
          cidr: 192.168.5.10/32
     ports:
      -  protocol: TCP
         port: 80
70
Q

What is ingress traffic?

A

Traffic that originates outside the network that is heading inside the network.

71
Q

What is egress networking?

A

Traffic heading from inside the network to outside the network.