Prompt:
Complete this text code:

# List all revisions for the StatefulSet
kubectl get controllerrevisions -l app.kubernetes.io/name=webapp

Response:
# View detailed configuration of a specific revision
kubectl get controllerrevision/webapp-3 -o yaml

Context: 2.3 - StatefulSets | Regularly check revisions with:


Prompt:
Explain this text code:

# List all revisions for the StatefulSet
kubectl get controllerrevisions -l app.kubernetes.io/name=webapp

# View detailed configuration of a specific revision
kubectl get controllerrevision/webapp-3 -o yaml

Response: This text code 2.3 - StatefulSets | Regularly check revisions with:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: StatefulSet
...
spec:

Response:
  persistentVolumeClaimRetentionPolicy:
    whenDeleted: Retain
    whenScaled: Delete
...

Context: 2.3 - StatefulSets | The StatefulSet controller adds owner references to its PVCs, which are then deleted by the garbage collector after the Pod is terminated. This enables the Pod to cleanly unmount all volumes before th


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: StatefulSet
...
spec:
  persistentVolumeClaimRetentionPolicy:
    whenDeleted: Retain
    whenScaled: Delete
...

Response: This yaml code 2.3 - StatefulSets | The StatefulSet controller adds owner references to its PVCs, which are then deleted by the garbage collector after the Pod is terminated. This enables the Pod to cleanly unmount all volumes before th


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd-elasticsearch
  namespace: kube-system
  labels:
    k8s-app: fluentd-logging
spec:
  selector:
    matchLabels:
      name: fluentd-elasticsearch
  template:
    metadata:
      labels:
        name: fluentd-elasticsearch
    spec:
      tolerations:
      # these tolerations are to have the daemonset runnable on control plane nodes
      # remove them if your control plane nodes should not run pods
      - key: node-role.kubernetes.io/control-plane
        operator: Exists
        effect: NoSchedule

Response:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      containers:
      - name: fluentd-elasticsearch
        image: quay.io/fluentd_elasticsearch/fluentd:v5.0.1
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: varlog
          mountPath: /var/log
      # it may be desirable to set a high priority class to ensure that a DaemonSet Pod
      # preempts running Pods
      # priorityClassName: important
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log

Context: 2.4 - DaemonSet | Create a DaemonSet based on the YAML file:


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd-elasticsearch
  namespace: kube-system
  labels:
    k8s-app: fluentd-logging
spec:
  selector:
    matchLabels:
      name: fluentd-elasticsearch
  template:
    metadata:
      labels:
        name: fluentd-elasticsearch
    spec:
      tolerations:
      # these tolerations are to have the daemonset runnable on control plane nodes
      # remove them if your control plane nodes should not run pods
      - key: node-role.kubernetes.io/control-plane
        operator: Exists
        effect: NoSchedule
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      containers:
      - name: fluentd-elasticsearch
        image: quay.io/fluentd_elasticsearch/fluentd:v5.0.1
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: varlog
          mountPath: /var/log
      # it may be desirable to set a high priority class to ensure that a DaemonSet Pod
      # preempts running Pods
      # priorityClassName: important
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log

Response: This yaml code 2.4 - DaemonSet | Create a DaemonSet based on the YAML file:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/controllers/daemonset.yaml

Response: This bash code 2.4 - DaemonSet | As with all other Kubernetes config, a DaemonSet needs apiVersion, kind, and metadata fields. For general information about working with config files, see running stateless applications and object man

Context: 2.4 - DaemonSet | As with all other Kubernetes config, a DaemonSet needs apiVersion, kind, and metadata fields. For general information about working with config files, see running stateless applications and object man


Prompt:
Complete this text code:

nodeAffinity:
  requiredDuringSchedulingIgnoredDuringExecution:
    nodeSelectorTerms:
    - matchFields:

Response:
      - key: metadata.name
        operator: In
        values:
        - target-host-name

Context: 2.4 - DaemonSet | The DaemonSet controller automatically adds a set of tolerations to DaemonSet Pods:


Prompt:
Explain this text code:

nodeAffinity:
  requiredDuringSchedulingIgnoredDuringExecution:
    nodeSelectorTerms:
    - matchFields:
      - key: metadata.name
        operator: In
        values:
        - target-host-name

Response: This text code 2.4 - DaemonSet | The DaemonSet controller automatically adds a set of tolerations to DaemonSet Pods:


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:

Response:
    spec:
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
  backoffLimit: 4

Context: 2.5 - Jobs | You can run the example with this command:


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
  backoffLimit: 4

Response: This yaml code 2.5 - Jobs | You can run the example with this command:


Prompt:
Explain this bash code:

kubectl apply -f https://kubernetes.io/examples/controllers/job.yaml

Response: This bash code 2.5 - Jobs | The output is similar to this:

Context: 2.5 - Jobs | The output is similar to this:


Prompt:
Complete this text code:

Name:           pi
Namespace:      default
Selector:       batch.kubernetes.io/controller-uid=c9948307-e56d-4b5d-8302-ae2d7b7da67c
Labels:         batch.kubernetes.io/controller-uid=c9948307-e56d-4b5d-8302-ae2d7b7da67c
                batch.kubernetes.io/job-name=pi
                ...
Annotations:    batch.kubernetes.io/job-tracking: ""
Parallelism:    1
Completions:    1
Start Time:     Mon, 02 Dec 2019 15:20:11 +0200
Completed At:   Mon, 02 Dec 2019 15:21:16 +0200
Duration:       65s
Pods Statuses:  0 Running / 1 Succeeded / 0 Failed
Pod Template:
  Labels:  batch.kubernetes.io/controller-uid=c9948307-e56d-4b5d-8302-ae2d7b7da67c
           batch.kubernetes.io/job-name=pi
  Containers:

Response:
   pi:
    Image:      perl:5.34.0
    Port:       <none>
    Host Port:  <none>
    Command:
      perl
      -Mbignum=bpi
      -wle
      print bpi(2000)
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From            Message
  ----    ------            ----  ----            -------
  Normal  SuccessfulCreate  21s   job-controller  Created pod: pi-xf9p4
  Normal  Completed         18s   job-controller  Job completed

Context: 2.5 - Jobs | apiVersion: batch/v1 kind: Job metadata: annotations: batch.kubernetes.io/job-tracking: "" ... creationTimestamp: "2022-11-10T17:53:53Z" generation: 1 labels: batch.kubernet


Prompt:
Explain this text code:

Name:           pi
Namespace:      default
Selector:       batch.kubernetes.io/controller-uid=c9948307-e56d-4b5d-8302-ae2d7b7da67c
Labels:         batch.kubernetes.io/controller-uid=c9948307-e56d-4b5d-8302-ae2d7b7da67c
                batch.kubernetes.io/job-name=pi
                ...
Annotations:    batch.kubernetes.io/job-tracking: ""
Parallelism:    1
Completions:    1
Start Time:     Mon, 02 Dec 2019 15:20:11 +0200
Completed At:   Mon, 02 Dec 2019 15:21:16 +0200
Duration:       65s
Pods Statuses:  0 Running / 1 Succeeded / 0 Failed
Pod Template:
  Labels:  batch.kubernetes.io/controller-uid=c9948307-e56d-4b5d-8302-ae2d7b7da67c
           batch.kubernetes.io/job-name=pi
  Containers:
   pi:
    Image:      perl:5.34.0
    Port:       <none>
    Host Port:  <none>
    Command:
      perl
      -Mbignum=bpi
      -wle
      print bpi(2000)
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From            Message
  ----    ------            ----  ----            -------
  Normal  SuccessfulCreate  21s   job-controller  Created pod: pi-xf9p4
  Normal  Completed         18s   job-controller  Job completed

Response: This text code 2.5 - Jobs | apiVersion: batch/v1 kind: Job metadata: annotations: batch.kubernetes.io/job-tracking: "" ... creationTimestamp: "2022-11-10T17:53:53Z" generation: 1 labels: batch.kubernet


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  annotations: batch.kubernetes.io/job-tracking: ""
             ...
  creationTimestamp: "2022-11-10T17:53:53Z"
  generation: 1
  labels:
    batch.kubernetes.io/controller-uid: 863452e6-270d-420e-9b94-53a54146c223
    batch.kubernetes.io/job-name: pi
  name: pi
  namespace: default
  resourceVersion: "4751"
  uid: 204fb678-040b-497f-9266-35ffa8716d14
spec:
  backoffLimit: 4
  completionMode: NonIndexed
  completions: 1
  parallelism: 1
  selector:
    matchLabels:
      batch.kubernetes.io/controller-uid: 863452e6-270d-420e-9b94-53a54146c223
  suspend: false
  template:
    metadata:
      creationTimestamp: null

Response:
      labels:
        batch.kubernetes.io/controller-uid: 863452e6-270d-420e-9b94-53a54146c223
        batch.kubernetes.io/job-name: pi
    spec:
      containers:
      - command:
        - perl
        - -Mbignum=bpi
        - -wle
        - print bpi(2000)
        image: perl:5.34.0
        imagePullPolicy: IfNotPresent
        name: pi
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Never
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  active: 1
  ready: 0
  startTime: "2022-11-10T17:53:57Z"
  uncountedTerminatedPods: {}

Context: 2.5 - Jobs | To view completed Pods of a Job, use kubectl get pods.


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  annotations: batch.kubernetes.io/job-tracking: ""
             ...
  creationTimestamp: "2022-11-10T17:53:53Z"
  generation: 1
  labels:
    batch.kubernetes.io/controller-uid: 863452e6-270d-420e-9b94-53a54146c223
    batch.kubernetes.io/job-name: pi
  name: pi
  namespace: default
  resourceVersion: "4751"
  uid: 204fb678-040b-497f-9266-35ffa8716d14
spec:
  backoffLimit: 4
  completionMode: NonIndexed
  completions: 1
  parallelism: 1
  selector:
    matchLabels:
      batch.kubernetes.io/controller-uid: 863452e6-270d-420e-9b94-53a54146c223
  suspend: false
  template:
    metadata:
      creationTimestamp: null
      labels:
        batch.kubernetes.io/controller-uid: 863452e6-270d-420e-9b94-53a54146c223
        batch.kubernetes.io/job-name: pi
    spec:
      containers:
      - command:
        - perl
        - -Mbignum=bpi
        - -wle
        - print bpi(2000)
        image: perl:5.34.0
        imagePullPolicy: IfNotPresent
        name: pi
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Never
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  active: 1
  ready: 0
  startTime: "2022-11-10T17:53:57Z"
  uncountedTerminatedPods: {}

Response: This yaml code 2.5 - Jobs | To view completed Pods of a Job, use kubectl get pods.


Prompt:
Explain this text code:

pods=$(kubectl get pods --selector=batch.kubernetes.io/job-name=pi --output=jsonpath='{.items[*].metadata.name}')
echo $pods

Response: This text code 2.5 - Jobs | The output is similar to this:


Response: This text code 2.5 - Jobs | As with all other Kubernetes config, a Job needs apiVersion, kind, and metadata fields.

Context: 2.5 - Jobs | As with all other Kubernetes config, a Job needs apiVersion, kind, and metadata fields.


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: job-backoff-limit-per-index-example
spec:
  completions: 10
  parallelism: 3
  completionMode: Indexed  # required for the feature
  backoffLimitPerIndex: 1  # maximal number of failures per index
  maxFailedIndexes: 5      # maximal number of failed indexes before terminating the Job execution
  template:
    spec:
      restartPolicy: Never # required for the feature

Response:
      containers:
      - name: example
        image: python
        command:           # The jobs fails as there is at least one failed index
                           # (all even indexes fail in here), yet all indexes
                           # are executed as maxFailedIndexes is not exceeded.
        - python3
        - -c
        - |
          import os, sys
          print("Hello world")
          if int(os.environ.get("JOB_COMPLETION_INDEX")) % 2 == 0:
            sys.exit(1)

Context: 2.5 - Jobs | In the example above, the Job controller allows for one restart for each of the indexes. When the total number of failed indexes exceeds 5, then the entire Job is terminated.


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: job-backoff-limit-per-index-example
spec:
  completions: 10
  parallelism: 3
  completionMode: Indexed  # required for the feature
  backoffLimitPerIndex: 1  # maximal number of failures per index
  maxFailedIndexes: 5      # maximal number of failed indexes before terminating the Job execution
  template:
    spec:
      restartPolicy: Never # required for the feature
      containers:
      - name: example
        image: python
        command:           # The jobs fails as there is at least one failed index
                           # (all even indexes fail in here), yet all indexes
                           # are executed as maxFailedIndexes is not exceeded.
        - python3
        - -c
        - |
          import os, sys
          print("Hello world")
          if int(os.environ.get("JOB_COMPLETION_INDEX")) % 2 == 0:
            sys.exit(1)

Response: This yaml code 2.5 - Jobs | In the example above, the Job controller allows for one restart for each of the indexes. When the total number of failed indexes exceeds 5, then the entire Job is terminated.


Prompt:
Explain this bash code:

kubectl get -o yaml job job-backoff-limit-per-index-example

Response: This bash code 2.5 - Jobs | The Job controller adds the FailureTarget Job condition to trigger Job termination and cleanup. When all of the Job Pods are terminated, the Job controller adds the Failed condition with the same valu

Context: 2.5 - Jobs | The Job controller adds the FailureTarget Job condition to trigger Job termination and cleanup. When all of the Job Pods are terminated, the Job controller adds the Failed condition with the same valu


Prompt:
Complete this text code:

status:
    completedIndexes: 1,3,5,7,9
    failedIndexes: 0,2,4,6,8
    succeeded: 5          # 1 succeeded pod for each of 5 succeeded indexes
    failed: 10            # 2 failed pods (1 retry) for each of 5 failed indexes
    conditions:
    - message: Job has failed indexes

Response:
      reason: FailedIndexes
      status: "True"
      type: FailureTarget
    - message: Job has failed indexes
      reason: FailedIndexes
      status: "True"
      type: Failed


Prompt:
Explain this text code:

status:
    completedIndexes: 1,3,5,7,9
    failedIndexes: 0,2,4,6,8
    succeeded: 5          # 1 succeeded pod for each of 5 succeeded indexes
    failed: 10            # 2 failed pods (1 retry) for each of 5 failed indexes
    conditions:
    - message: Job has failed indexes
      reason: FailedIndexes
      status: "True"
      type: FailureTarget
    - message: Job has failed indexes
      reason: FailedIndexes
      status: "True"
      type: Failed

Response: This text code 2.5 - Jobs | The Job controller adds the FailureTarget Job condition to trigger Job termination and cleanup. When all of the Job Pods are terminated, the Job controller adds the Failed condition with the same valu


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: job-pod-failure-policy-example
spec:
  completions: 12
  parallelism: 3
  template:
    spec:
      restartPolicy: Never
      containers:
      - name: main
        image: docker.io/library/bash:5
        command: ["bash"]        # example command simulating a bug which triggers the FailJob action

Response:
        args:
        - -c
        - echo "Hello world!" && sleep 5 && exit 42
  backoffLimit: 6
  podFailurePolicy:
    rules:
    - action: FailJob
      onExitCodes:
        containerName: main      # optional
        operator: In             # one of: In, NotIn
        values: [42]
    - action: Ignore             # one of: Ignore, FailJob, Count
      onPodConditions:
      - type: DisruptionTarget   # indicates Pod disruption

Context: 2.5 - Jobs | In the example above, the first rule of the Pod failure policy specifies that the Job should be marked failed if the main container fails with the 42 exit code. The following are the rules for the mai


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: job-pod-failure-policy-example
spec:
  completions: 12
  parallelism: 3
  template:
    spec:
      restartPolicy: Never
      containers:
      - name: main
        image: docker.io/library/bash:5
        command: ["bash"]        # example command simulating a bug which triggers the FailJob action
        args:
        - -c
        - echo "Hello world!" && sleep 5 && exit 42
  backoffLimit: 6
  podFailurePolicy:
    rules:
    - action: FailJob
      onExitCodes:
        containerName: main      # optional
        operator: In             # one of: In, NotIn
        values: [42]
    - action: Ignore             # one of: Ignore, FailJob, Count
      onPodConditions:
      - type: DisruptionTarget   # indicates Pod disruption

Response: This yaml code 2.5 - Jobs | In the example above, the first rule of the Pod failure policy specifies that the Job should be marked failed if the main container fails with the 42 exit code. The following are the rules for the mai


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: job-success
spec:
  parallelism: 10
  completions: 10
  completionMode: Indexed # Required for the success policy
  successPolicy:
    rules:
      - succeededIndexes: 0,2-3
        succeededCount: 1
  template:
    spec:

Response:
      containers:
      - name: main
        image: python
        command:          # Provided that at least one of the Pods with 0, 2, and 3 indexes has succeeded,
                          # the overall Job is a success.
          - python3
          - -c
          - |
            import os, sys
            if os.environ.get("JOB_COMPLETION_INDEX") == "2":
              sys.exit(0)
            else:
              sys.exit(1)
      restartPolicy: Never

Context: 2.5 - Jobs | In the example above, both succeededIndexes and succeededCount have been specified. Therefore, the job controller will mark the Job as succeeded and terminate the lingering Pods when either of the spe


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: job-success
spec:
  parallelism: 10
  completions: 10
  completionMode: Indexed # Required for the success policy
  successPolicy:
    rules:
      - succeededIndexes: 0,2-3
        succeededCount: 1
  template:
    spec:
      containers:
      - name: main
        image: python
        command:          # Provided that at least one of the Pods with 0, 2, and 3 indexes has succeeded,
                          # the overall Job is a success.
          - python3
          - -c
          - |
            import os, sys
            if os.environ.get("JOB_COMPLETION_INDEX") == "2":
              sys.exit(0)
            else:
              sys.exit(1)
      restartPolicy: Never

Response: This yaml code 2.5 - Jobs | In the example above, both succeededIndexes and succeededCount have been specified. Therefore, the job controller will mark the Job as succeeded and terminate the lingering Pods when either of the spe


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-timeout
spec:
  backoffLimit: 5
  activeDeadlineSeconds: 100

Response:
  template:
    spec:
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never

Context: 2.5 - Jobs | Note that both the Job spec and the Pod template spec within the Job have an activeDeadlineSeconds field. Ensure that you set this field at the proper level.


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-timeout
spec:
  backoffLimit: 5
  activeDeadlineSeconds: 100
  template:
    spec:
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never

Response: This yaml code 2.5 - Jobs | Note that both the Job spec and the Pod template spec within the Job have an activeDeadlineSeconds field. Ensure that you set this field at the proper level.


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-ttl
spec:
  ttlSecondsAfterFinished: 100

Response:
  template:
    spec:
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never

Context: 2.5 - Jobs | The Job pi-with-ttl will be eligible to be automatically deleted, 100 seconds after it finishes.


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-ttl
spec:
  ttlSecondsAfterFinished: 100
  template:
    spec:
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never

Response: This yaml code 2.5 - Jobs | The Job pi-with-ttl will be eligible to be automatically deleted, 100 seconds after it finishes.


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: myjob
spec:

Response:
  suspend: true
  parallelism: 1
  completions: 5
  template:
    spec:
      ...

Context: 2.5 - Jobs | You can also toggle Job suspension by patching the Job using the command line.


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: myjob
spec:
  suspend: true
  parallelism: 1
  completions: 5
  template:
    spec:
      ...

Response: This yaml code 2.5 - Jobs | You can also toggle Job suspension by patching the Job using the command line.


Prompt:
Explain this bash code:

kubectl patch job/myjob --type=strategic --patch '{"spec":{"suspend":true}}'

Response: This bash code 2.5 - Jobs | Resume a suspended Job:

Context: 2.5 - Jobs | Resume a suspended Job:


Prompt:
Explain this bash code:

kubectl patch job/myjob --type=strategic --patch '{"spec":{"suspend":false}}'

Response: This bash code 2.5 - Jobs | The Job's status can be used to determine if a Job is suspended or has been suspended in the past:

Context: 2.5 - Jobs | The Job's status can be used to determine if a Job is suspended or has been suspended in the past:


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
# .metadata and .spec omitted
status:
  conditions:

Response:
  - lastProbeTime: "2021-02-05T13:14:33Z"
    lastTransitionTime: "2021-02-05T13:14:33Z"
    status: "True"
    type: Suspended
  startTime: "2021-02-05T13:13:48Z"

Context: 2.5 - Jobs | The Job condition of type "Suspended" with status "True" means the Job is suspended; the lastTransitionTime field can be used to determine how long the Job has been suspended for. If the status of tha


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
# .metadata and .spec omitted
status:
  conditions:
  - lastProbeTime: "2021-02-05T13:14:33Z"
    lastTransitionTime: "2021-02-05T13:14:33Z"
    status: "True"
    type: Suspended
  startTime: "2021-02-05T13:13:48Z"

Response: This yaml code 2.5 - Jobs | The Job condition of type "Suspended" with status "True" means the Job is suspended; the lastTransitionTime field can be used to determine how long the Job has been suspended for. If the status of tha


Prompt:
Complete this text code:

Name:           myjob
...
Events:
  Type    Reason            Age   From            Message
  ----    ------            ----  ----            -------

Response:
  Normal  SuccessfulCreate  12m   job-controller  Created pod: myjob-hlrpl
  Normal  SuccessfulDelete  11m   job-controller  Deleted pod: myjob-hlrpl
  Normal  Suspended         11m   job-controller  Job suspended
  Normal  SuccessfulCreate  3s    job-controller  Created pod: myjob-jvb44
  Normal  Resumed           3s    job-controller  Job resumed

Context: 2.5 - Jobs | The last four events, particularly the "Suspended" and "Resumed" events, are directly a result of toggling the .spec.suspend field. In the time between these two events, we see that no Pods were creat


Prompt:
Explain this text code:

Name:           myjob
...
Events:
  Type    Reason            Age   From            Message
  ----    ------            ----  ----            -------
  Normal  SuccessfulCreate  12m   job-controller  Created pod: myjob-hlrpl
  Normal  SuccessfulDelete  11m   job-controller  Deleted pod: myjob-hlrpl
  Normal  Suspended         11m   job-controller  Job suspended
  Normal  SuccessfulCreate  3s    job-controller  Created pod: myjob-jvb44
  Normal  Resumed           3s    job-controller  Job resumed

Response: This text code 2.5 - Jobs | The last four events, particularly the "Suspended" and "Resumed" events, are directly a result of toggling the .spec.suspend field. In the time between these two events, we see that no Pods were creat


Prompt:
Complete this yaml code:

kind: Job
metadata:
  name: old
  ...

Response:
spec:
  selector:
    matchLabels:
      batch.kubernetes.io/controller-uid: a8f3d00d-c6d2-11e5-9f87-42010af00002
  ...

Context: 2.5 - Jobs | Then you create a new Job with name new and you explicitly specify the same selector. Since the existing Pods have label batch.kubernetes.io/controller-uid=a8f3d00d-c6d2-11e5-9f87-42010af00002, they a


Prompt:
Explain this yaml code:

kind: Job
metadata:
  name: old
  ...
spec:
  selector:
    matchLabels:
      batch.kubernetes.io/controller-uid: a8f3d00d-c6d2-11e5-9f87-42010af00002
  ...

Response: This yaml code 2.5 - Jobs | Then you create a new Job with name new and you explicitly specify the same selector. Since the existing Pods have label batch.kubernetes.io/controller-uid=a8f3d00d-c6d2-11e5-9f87-42010af00002, they a


Prompt:
Complete this yaml code:

kind: Job
metadata:
  name: new
  ...
spec:

Response:
  manualSelector: true
  selector:
    matchLabels:
      batch.kubernetes.io/controller-uid: a8f3d00d-c6d2-11e5-9f87-42010af00002
  ...

Context: 2.5 - Jobs | The new Job itself will have a different uid from a8f3d00d-c6d2-11e5-9f87-42010af00002. Setting manualSelector: true tells the system that you know what you are doing and to allow this mismatch.


Prompt:
Explain this yaml code:

kind: Job
metadata:
  name: new
  ...
spec:
  manualSelector: true
  selector:
    matchLabels:
      batch.kubernetes.io/controller-uid: a8f3d00d-c6d2-11e5-9f87-42010af00002
  ...

Response: This yaml code 2.5 - Jobs | The new Job itself will have a different uid from a8f3d00d-c6d2-11e5-9f87-42010af00002. Setting manualSelector: true tells the system that you know what you are doing and to allow this mismatch.


Prompt:
Complete this yaml code:

kind: Job
metadata:
  name: new

Response:
  ...
spec:
  podReplacementPolicy: Failed
  ...

Context: 2.5 - Jobs | Provided your cluster has the feature gate enabled, you can inspect the .status.terminating field of a Job. The value of the field is the number of Pods owned by the Job that are currently terminating


Prompt:
Explain this yaml code:

kind: Job
metadata:
  name: new
  ...
spec:
  podReplacementPolicy: Failed
  ...

Response: This yaml code 2.5 - Jobs | Provided your cluster has the feature gate enabled, you can inspect the .status.terminating field of a Job. The value of the field is the number of Pods owned by the Job that are currently terminating


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job

Response:
# .metadata and .spec omitted
status:
  terminating: 3 # three Pods are terminating and have not yet reached the Failed phase

Context: 2.5 - Jobs | This feature allows you to disable the built-in Job controller, for a specific Job, and delegate reconciliation of the Job to an external controller.


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
# .metadata and .spec omitted
status:
  terminating: 3 # three Pods are terminating and have not yet reached the Failed phase

Response: This yaml code 2.5 - Jobs | This feature allows you to disable the built-in Job controller, for a specific Job, and delegate reconciliation of the Job to an external controller.


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:

Response:
        spec:
          containers:
          - name: hello
            image: busybox:1.28
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure

Context: 2.7 - CronJob | (Running Automated Tasks with a CronJob takes you through this example in more detail).


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox:1.28
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure

Response: This yaml code 2.7 - CronJob | (Running Automated Tasks with a CronJob takes you through this example in more detail).


Prompt:
Complete this text code:

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)

Response:
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
# │ │ │ │ │                                   OR sun, mon, tue, wed, thu, fri, sat
# │ │ │ │ │
# │ │ │ │ │
# * * * * *

Context: 2.7 - CronJob | For example, 0 3 * * 1 means this task is scheduled to run weekly on a Monday at 3 AM.


Prompt:
Explain this text code:

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
# │ │ │ │ │                                   OR sun, mon, tue, wed, thu, fri, sat
# │ │ │ │ │
# │ │ │ │ │
# * * * * *

Response: This text code 2.7 - CronJob | For example, 0 3 * * 1 means this task is scheduled to run weekly on a Monday at 3 AM.


Prompt:
Explain this text code:

Cannot determine if job needs to be started. Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.

Response: This text code 2.7 - CronJob | It is important to note that if the startingDeadlineSeconds field is set (not nil), the controller counts how many missed Jobs occurred from the value of startingDeadlineSeconds until now rather than

Context: 2.7 - CronJob | It is important to note that if the startingDeadlineSeconds field is set (not nil), the controller counts how many missed Jobs occurred from the value of startingDeadlineSeconds until now rather than


Prompt:
Complete this yaml code:

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    app: nginx
  template:

Response:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

Context: 2.8 - ReplicationController | Run the example job by downloading the example file and then running this command:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    app: nginx
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

Response: This yaml code 2.8 - ReplicationController | Run the example job by downloading the example file and then running this command:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/controllers/replication.yaml

Response: This bash code 2.8 - ReplicationController | The output is similar to this:

Context: 2.8 - ReplicationController | The output is similar to this:


Prompt:
Complete this text code:

Name:        nginx
Namespace:   default
Selector:    app=nginx
Labels:      app=nginx
Annotations:    <none>
Replicas:    3 current / 3 desired
Pods Status: 0 Running / 3 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:       app=nginx
  Containers:
   nginx:

Response:
    Image:              nginx
    Port:               80/TCP
    Environment:        <none>
    Mounts:             <none>
  Volumes:              <none>
Events:
  FirstSeen       LastSeen     Count    From                        SubobjectPath    Type      Reason              Message
  ---------       --------     -----    ----                        -------------    ----      ------              -------
  20s             20s          1        {replication-controller }                    Normal    SuccessfulCreate    Created pod: nginx-qrm3m
  20s             20s          1        {replication-controller }                    Normal    SuccessfulCreate    Created pod: nginx-3ntk0
  20s             20s          1        {replication-controller }                    Normal    SuccessfulCreate    Created pod: nginx-4ok8v

Context: 2.8 - ReplicationController | Here, three pods are created, but none is running yet, perhaps because the image is being pulled. A little later, the same command may show:


Prompt:
Explain this text code:

Name:        nginx
Namespace:   default
Selector:    app=nginx
Labels:      app=nginx
Annotations:    <none>
Replicas:    3 current / 3 desired
Pods Status: 0 Running / 3 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:       app=nginx
  Containers:
   nginx:
    Image:              nginx
    Port:               80/TCP
    Environment:        <none>
    Mounts:             <none>
  Volumes:              <none>
Events:
  FirstSeen       LastSeen     Count    From                        SubobjectPath    Type      Reason              Message
  ---------       --------     -----    ----                        -------------    ----      ------              -------
  20s             20s          1        {replication-controller }                    Normal    SuccessfulCreate    Created pod: nginx-qrm3m
  20s             20s          1        {replication-controller }                    Normal    SuccessfulCreate    Created pod: nginx-3ntk0
  20s             20s          1        {replication-controller }                    Normal    SuccessfulCreate    Created pod: nginx-4ok8v

Response: This text code 2.8 - ReplicationController | Here, three pods are created, but none is running yet, perhaps because the image is being pulled. A little later, the same command may show:


Prompt:
Explain this text code:

Pods Status:    3 Running / 0 Waiting / 0 Succeeded / 0 Failed

Response: This text code 2.8 - ReplicationController | To list all the pods that belong to the ReplicationController in a machine readable form, you can use a command like this:

Context: 2.8 - ReplicationController | To list all the pods that belong to the ReplicationController in a machine readable form, you can use a command like this:


Prompt:
Explain this text code:

pods=$(kubectl get pods --selector=app=nginx --output=jsonpath={.items..metadata.name})
echo $pods

Response: This text code 2.8 - ReplicationController | The output is similar to this:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Service
metadata:
  name: my-nginx-svc
  labels:
    app: nginx
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx

Response:
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Context: 4 - Managing Workloads | Multiple resources can be created the same way as a single resource:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  name: my-nginx-svc
  labels:
    app: nginx
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Response: This yaml code 4 - Managing Workloads | Multiple resources can be created the same way as a single resource:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/application/nginx-app.yaml

Response: This bash code 4 - Managing Workloads | The resources will be created in the order they appear in the manifest. Therefore, it's best to specify the Service first, since that will ensure the scheduler can spread the pods associated with the

Context: 4 - Managing Workloads | The resources will be created in the order they appear in the manifest. Therefore, it's best to specify the Service first, since that will ensure the scheduler can spread the pods associated with the


Prompt:
Explain this text code:

service/my-nginx-svc created
deployment.apps/my-nginx created

Response: This text code 4 - Managing Workloads | The resources will be created in the order they appear in the manifest. Therefore, it's best to specify the Service first, since that will ensure the scheduler can spread the pods associated with the


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/application/nginx/nginx-svc.yaml \
  -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml

Response: This bash code 4 - Managing Workloads | It is a recommended practice to put resources related to the same microservice or application tier into the same file, and to group all of the files associated with your application in the same direct

Context: 4 - Managing Workloads | It is a recommended practice to put resources related to the same microservice or application tier into the same file, and to group all of the files associated with your application in the same direct


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml

Response: This bash code 4 - Managing Workloads | If you need to define more manifests, such as adding a ConfigMap, you can do that too.

Context: 4 - Managing Workloads | If you need to define more manifests, such as adding a ConfigMap, you can do that too.


Prompt:
Explain this bash code:

kubectl delete -f https://k8s.io/examples/application/nginx-app.yaml

Response: This bash code 4 - Managing Workloads | In the case of two resources, you can specify both resources on the command line using the resource/name syntax:

Context: 4 - Managing Workloads | In the case of two resources, you can specify both resources on the command line using the resource/name syntax:


Prompt:
Explain this text code:

deployment.apps "my-nginx" deleted
service "my-nginx-svc" deleted

Response: This text code 4 - Managing Workloads | In the case of two resources, you can specify both resources on the command line using the resource/name syntax:


Prompt:
Explain this bash code:

kubectl delete deployments/my-nginx services/my-nginx-svc

Response: This bash code 4 - Managing Workloads | For larger numbers of resources, you'll find it easier to specify the selector (label query) specified using -l or --selector, to filter resources by their labels:

Context: 4 - Managing Workloads | For larger numbers of resources, you'll find it easier to specify the selector (label query) specified using -l or --selector, to filter resources by their labels:


Prompt:
Explain this text code:

deployment.apps "my-nginx" deleted
service "my-nginx-svc" deleted

Response: This text code 4 - Managing Workloads | Because kubectl outputs resource names in the same syntax it accepts, you can chain operations using $() or xargs:

Context: 4 - Managing Workloads | Because kubectl outputs resource names in the same syntax it accepts, you can chain operations using $() or xargs:


Prompt:
Explain this bash code:

kubectl get $(kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service/ )
kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service/ | xargs -i kubectl get '{}'

Response: This bash code 4 - Managing Workloads | The output might be similar to:

Context: 4 - Managing Workloads | The output might be similar to:


Prompt:
Explain this text code:

NAME           TYPE           CLUSTER-IP   EXTERNAL-IP   PORT(S)      AGE
my-nginx-svc   LoadBalancer   10.0.0.208   <pending>     80/TCP       0s

Response: This text code 4 - Managing Workloads | With the above commands, first you create resources under examples/application/nginx/ and print the resources created with -o name output format (print each resource as resource/name). Then you grep o

Context: 4 - Managing Workloads | With the above commands, first you create resources under examples/application/nginx/ and print the resources created with -o name output format (print each resource as resource/name). Then you grep o


Prompt:
Complete this text code:

project/k8s/development
├── configmap
│   └── my-configmap.yaml

Response:
├── deployment
│   └── my-deployment.yaml
└── pvc
    └── my-pvc.yaml

Context: 4 - Managing Workloads | By default, performing a bulk operation on project/k8s/development will stop at the first level of the directory, not processing any subdirectories. If you had tried to create the resources in this di


Prompt:
Explain this text code:

project/k8s/development
├── configmap
│   └── my-configmap.yaml
├── deployment
│   └── my-deployment.yaml
└── pvc
    └── my-pvc.yaml

Response: This text code 4 - Managing Workloads | By default, performing a bulk operation on project/k8s/development will stop at the first level of the directory, not processing any subdirectories. If you had tried to create the resources in this di


Prompt:
Explain this text code:

error: you must provide one or more resources by argument or filename (.json|.yaml|.yml|stdin)

Response: This text code 4 - Managing Workloads | Instead, specify the --recursive or -R command line argument along with the --filename/-f argument:

Context: 4 - Managing Workloads | Instead, specify the --recursive or -R command line argument along with the --filename/-f argument:


Prompt:
Explain this bash code:

kubectl apply -f project/k8s/development --recursive

Response: This bash code 4 - Managing Workloads | The --recursive argument works with any operation that accepts the --filename/-f argument such as: kubectl create, kubectl get, kubectl delete, kubectl describe, or even kubectl rollout.

Context: 4 - Managing Workloads | The --recursive argument works with any operation that accepts the --filename/-f argument such as: kubectl create, kubectl get, kubectl delete, kubectl describe, or even kubectl rollout.


Prompt:
Explain this text code:

configmap/my-config created
deployment.apps/my-deployment created
persistentvolumeclaim/my-pvc created

Response: This text code 4 - Managing Workloads | The --recursive argument works with any operation that accepts the --filename/-f argument such as: kubectl create, kubectl get, kubectl delete, kubectl describe, or even kubectl rollout.


Prompt:
Explain this bash code:

kubectl apply -f project/k8s/namespaces -f project/k8s/development --recursive

Response: This bash code 4 - Managing Workloads | If you're interested in learning more about kubectl, go ahead and read Command line tool (kubectl).

Context: 4 - Managing Workloads | If you're interested in learning more about kubectl, go ahead and read Command line tool (kubectl).


Prompt:
Complete this text code:

namespace/development created
namespace/staging created

Response:
configmap/my-config created
deployment.apps/my-deployment created
persistentvolumeclaim/my-pvc created


Prompt:
Explain this text code:

namespace/development created
namespace/staging created
configmap/my-config created
deployment.apps/my-deployment created
persistentvolumeclaim/my-pvc created

Response: This text code 4 - Managing Workloads | If you're interested in learning more about kubectl, go ahead and read Command line tool (kubectl).


Prompt:
Explain this bash code:

kubectl create deployment my-nginx --image=nginx:1.14.2

Response: This bash code 4 - Managing Workloads | Ensure that there is 1 replica:

Context: 4 - Managing Workloads | Ensure that there is 1 replica:


Prompt:
Explain this bash code:

kubectl scale --replicas 1 deployments/my-nginx --subresource='scale' --type='merge' -p '{"spec":{"replicas": 1}}'

Response: This bash code 4 - Managing Workloads | and allow Kubernetes to add more temporary replicas during a rollout, by setting a surge maximum of 100%:

Context: 4 - Managing Workloads | and allow Kubernetes to add more temporary replicas during a rollout, by setting a surge maximum of 100%:


Prompt:
Explain this bash code:

kubectl patch --type='merge' -p '{"spec":{"strategy":{"rollingUpdate":{"maxSurge": "100%" }}}}'

Response: This bash code 4 - Managing Workloads | To update to version 1.16.1, change .spec.template.spec.containers[0].image from nginx:1.14.2 to nginx:1.16.1 using kubectl edit:

Context: 4 - Managing Workloads | To update to version 1.16.1, change .spec.template.spec.containers[0].image from nginx:1.14.2 to nginx:1.16.1 using kubectl edit:


Prompt:
Explain this bash code:

kubectl edit deployment/my-nginx
# Change the manifest to use the newer container image, then save your changes

Response: This bash code 4 - Managing Workloads | That's it! The Deployment will declaratively update the deployed nginx application progressively behind the scene. It ensures that only a certain number of old replicas may be down while they are bein

Context: 4 - Managing Workloads | That's it! The Deployment will declaratively update the deployed nginx application progressively behind the scene. It ensures that only a certain number of old replicas may be down while they are bein


Prompt:
Complete this bash code:

kubectl apply -f my-deployment.yaml

Response:
# wait for rollout to finish
kubectl rollout status deployment/my-deployment --timeout 10m # 10 minute timeout

Context: 4 - Managing Workloads | or


Prompt:
Explain this bash code:

kubectl apply -f my-deployment.yaml

# wait for rollout to finish
kubectl rollout status deployment/my-deployment --timeout 10m # 10 minute timeout

Response: This bash code 4 - Managing Workloads | or

Context: 4 - Managing Workloads | or


Prompt:
Complete this bash code:

kubectl apply -f backing-stateful-component.yaml

Response:
# don't wait for rollout to finish, just check the status
kubectl rollout status statefulsets/backing-stateful-component --watch=false

Context: 4 - Managing Workloads | You can also pause, resume or cancel a rollout. Visit kubectl rollout to learn more.


Prompt:
Explain this bash code:

kubectl apply -f backing-stateful-component.yaml

# don't wait for rollout to finish, just check the status
kubectl rollout status statefulsets/backing-stateful-component --watch=false

Response: This bash code 4 - Managing Workloads | You can also pause, resume or cancel a rollout. Visit kubectl rollout to learn more.


Prompt:
Complete this text code:

name: frontend
replicas: 3
...
labels:

Response:
   app: guestbook
   tier: frontend
   track: stable
...
image: gb-frontend:v3

Context: 4 - Managing Workloads | and then you can create a new release of the guestbook frontend that carries the track label with different value (i.e. canary), so that two sets of pods would not overlap:


Prompt:
Explain this text code:

name: frontend
replicas: 3
...
labels:
   app: guestbook
   tier: frontend
   track: stable
...
image: gb-frontend:v3

Response: This text code 4 - Managing Workloads | and then you can create a new release of the guestbook frontend that carries the track label with different value (i.e. canary), so that two sets of pods would not overlap:


Prompt:
Complete this text code:

name: frontend-canary
replicas: 1
...
labels:

Response:
   app: guestbook
   tier: frontend
   track: canary
...
image: gb-frontend:v4

Context: 4 - Managing Workloads | The frontend service would span both sets of replicas by selecting the common subset of their labels (i.e. omitting the track label), so that the traffic will be redirected to both applications:


Prompt:
Explain this text code:

name: frontend-canary
replicas: 1
...
labels:
   app: guestbook
   tier: frontend
   track: canary
...
image: gb-frontend:v4

Response: This text code 4 - Managing Workloads | The frontend service would span both sets of replicas by selecting the common subset of their labels (i.e. omitting the track label), so that the traffic will be redirected to both applications:


Prompt:
Explain this bash code:

kubectl annotate pods my-nginx-v4-9gw19 description='my frontend running nginx'
kubectl get pods my-nginx-v4-9gw19 -o yaml

Response: This bash code 4 - Managing Workloads | For more information, see annotations and kubectl annotate.

Context: 4 - Managing Workloads | For more information, see annotations and kubectl annotate.


Prompt:
Complete this yaml code:

apiVersion: v1
kind: pod
metadata:

Response:
  annotations:
    description: my frontend running nginx
...


Prompt:
Explain this yaml code:

apiVersion: v1
kind: pod
metadata:
  annotations:
    description: my frontend running nginx
...

Response: This yaml code 4 - Managing Workloads | For more information, see annotations and kubectl annotate.


Prompt:
Explain this text code:

NAME                        READY     STATUS    RESTARTS   AGE
my-nginx-2035384211-j5fhi   1/1       Running   0          30m

Response: This text code 4 - Managing Workloads | To have the system automatically choose the number of nginx replicas as needed, ranging from 1 to 3, do:

Context: 4 - Managing Workloads | To have the system automatically choose the number of nginx replicas as needed, ranging from 1 to 3, do:


Prompt:
Explain this text code:

# This requires an existing source of container and Pod metrics
kubectl autoscale deployment/my-nginx --min=1 --max=3

Response: This text code 4 - Managing Workloads | Now your nginx replicas will be scaled up and down as needed, automatically.

Context: 4 - Managing Workloads | Now your nginx replicas will be scaled up and down as needed, automatically.


Prompt:
Explain this text code:

horizontalpodautoscaler.autoscaling/my-nginx autoscaled

Response: This text code 4 - Managing Workloads | Now your nginx replicas will be scaled up and down as needed, automatically.


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml

Response: This bash code 4 - Managing Workloads | To learn more about the underlying mechanism, read server-side apply.

Context: 4 - Managing Workloads | To learn more about the underlying mechanism, read server-side apply.


Prompt:
Complete this bash code:

kubectl get deployment my-nginx -o yaml > /tmp/nginx.yaml
vi /tmp/nginx.yaml
# do some edit, and then save the file

Response:
kubectl apply -f /tmp/nginx.yaml
deployment.apps/my-nginx configured

rm /tmp/nginx.yaml

Context: 4 - Managing Workloads | This allows you to do more significant changes more easily. Note that you can specify the editor with your EDITOR or KUBE_EDITOR environment variables.


Prompt:
Explain this bash code:

kubectl get deployment my-nginx -o yaml > /tmp/nginx.yaml
vi /tmp/nginx.yaml
# do some edit, and then save the file

kubectl apply -f /tmp/nginx.yaml
deployment.apps/my-nginx configured

rm /tmp/nginx.yaml

Response: This bash code 4 - Managing Workloads | This allows you to do more significant changes more easily. Note that you can specify the editor with your EDITOR or KUBE_EDITOR environment variables.


Prompt:
Explain this bash code:

kubectl replace -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml --force

Response: This bash code 4 - Managing Workloads | © 2025 The Kubernetes Authors | Documentation Distributed under CC BY 4.0

Context: 4 - Managing Workloads | © 2025 The Kubernetes Authors | Documentation Distributed under CC BY 4.0


Prompt:
Explain this text code:

deployment.apps/my-nginx deleted
deployment.apps/my-nginx replaced

Response: This text code 4 - Managing Workloads | © 2025 The Kubernetes Authors | Documentation Distributed under CC BY 4.0


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:

Response:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

Context: 1 - Pods | To create the Pod shown above, run the following command:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

Response: This yaml code 1 - Pods | To create the Pod shown above, run the following command:


Prompt:
Explain this shell code:

kubectl apply -f https://k8s.io/examples/pods/simple-pod.yaml

Response: This shell code 1 - Pods | Pods are generally not created directly and are created using workload resources. See Working with Pods for more information on how Pods are used with workload resources.

Context: 1 - Pods | Pods are generally not created directly and are created using workload resources. See Working with Pods for more information on how Pods are used with workload resources.


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: hello
spec:
  template:
    # This is the pod template

Response:
    spec:
      containers:
      - name: hello
        image: busybox:1.28
        command: ['sh', '-c', 'echo "Hello, Kubernetes!" && sleep 3600']
      restartPolicy: OnFailure
    # The pod template ends here

Context: 1 - Pods | Modifying the pod template or switching to a new pod template has no direct effect on the Pods that already exist. If you change the pod template for a workload resource, that resource needs to create


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: hello
spec:
  template:
    # This is the pod template
    spec:
      containers:
      - name: hello
        image: busybox:1.28
        command: ['sh', '-c', 'echo "Hello, Kubernetes!" && sleep 3600']
      restartPolicy: OnFailure
    # The pod template ends here

Response: This yaml code 1 - Pods | Modifying the pod template or switching to a new pod template has no direct effect on the Pods that already exist. If you change the pod template for a workload resource, that resource needs to create


Prompt:
Explain this text code:

NAMESPACE               NAME               READY   STATUS             RESTARTS   AGE
  alessandras-namespace   alessandras-pod    0/1     CrashLoopBackOff   200        2d9h

Response: This text code 1.1 - Pod Lifecycle | A Pod is granted a term to terminate gracefully, which defaults to 30 seconds. You can use the flag --force to terminate a Pod by force.

Context: 1.1 - Pod Lifecycle | A Pod is granted a term to terminate gracefully, which defaults to 30 seconds. You can use the flag --force to terminate a Pod by force.


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: on-failure-pod
spec:
  restartPolicy: OnFailure
  containers:

Response:
  - name: try-once-container    # This container will run only once because the restartPolicy is Never.
    image: docker.io/library/busybox:1.28
    command: ['sh', '-c', 'echo "Only running once" && sleep 10 && exit 1']
    restartPolicy: Never
  - name: on-failure-container  # This container will be restarted on failure.
    image: docker.io/library/busybox:1.28
    command: ['sh', '-c', 'echo "Keep restarting" && sleep 1800 && exit 1']

Context: 1.1 - Pod Lifecycle | A Pod with Always restart policy with an init container that only execute once. If the init container fails, the Pod fails. This allows the Pod to fail if the initialization failed, but also keep runn


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: on-failure-pod
spec:
  restartPolicy: OnFailure
  containers:
  - name: try-once-container    # This container will run only once because the restartPolicy is Never.
    image: docker.io/library/busybox:1.28
    command: ['sh', '-c', 'echo "Only running once" && sleep 10 && exit 1']
    restartPolicy: Never
  - name: on-failure-container  # This container will be restarted on failure.
    image: docker.io/library/busybox:1.28
    command: ['sh', '-c', 'echo "Keep restarting" && sleep 1800 && exit 1']

Response: This yaml code 1.1 - Pod Lifecycle | A Pod with Always restart policy with an init container that only execute once. If the init container fails, the Pod fails. This allows the Pod to fail if the initialization failed, but also keep runn


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: fail-pod-if-init-fails
spec:
  restartPolicy: Always
  initContainers:

Response:
  - name: init-once      # This init container will only try once. If it fails, the pod will fail.
    image: docker.io/library/busybox:1.28
    command: ['sh', '-c', 'echo "Failing initialization" && sleep 10 && exit 1']
    restartPolicy: Never
  containers:
  - name: main-container # This container will always be restarted once initialization succeeds.
    image: docker.io/library/busybox:1.28
    command: ['sh', '-c', 'sleep 1800 && exit 0']

Context: 1.1 - Pod Lifecycle | A Pod with Never restart policy with a container that ignores and restarts on specific exit codes. This is useful to differentiate between restartable errors and non-restartable errors:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: fail-pod-if-init-fails
spec:
  restartPolicy: Always
  initContainers:
  - name: init-once      # This init container will only try once. If it fails, the pod will fail.
    image: docker.io/library/busybox:1.28
    command: ['sh', '-c', 'echo "Failing initialization" && sleep 10 && exit 1']
    restartPolicy: Never
  containers:
  - name: main-container # This container will always be restarted once initialization succeeds.
    image: docker.io/library/busybox:1.28
    command: ['sh', '-c', 'sleep 1800 && exit 0']

Response: This yaml code 1.1 - Pod Lifecycle | A Pod with Never restart policy with a container that ignores and restarts on specific exit codes. This is useful to differentiate between restartable errors and non-restartable errors:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: restart-on-exit-codes
spec:
  restartPolicy: Never
  containers:
  - name: restart-on-exit-codes

Response:
    image: docker.io/library/busybox:1.28
    command: ['sh', '-c', 'sleep 60 && exit 0']
    restartPolicy: Never     # Container restart policy must be specified if rules are specified
    restartPolicyRules:      # Only restart the container if it exits with code 42
    - action: Restart
      exitCodes:
        operator: In
        values: [42]

Context: 1.1 - Pod Lifecycle | Restart rules can be used for many more advanced lifecycle management scenarios. Note, restart rules are affected by the same inconsistencies as the regular restart policy. Kubelet restarts, container


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: restart-on-exit-codes
spec:
  restartPolicy: Never
  containers:
  - name: restart-on-exit-codes
    image: docker.io/library/busybox:1.28
    command: ['sh', '-c', 'sleep 60 && exit 0']
    restartPolicy: Never     # Container restart policy must be specified if rules are specified
    restartPolicyRules:      # Only restart the container if it exits with code 42
    - action: Restart
      exitCodes:
        operator: In
        values: [42]

Response: This yaml code 1.1 - Pod Lifecycle | Restart rules can be used for many more advanced lifecycle management scenarios. Note, restart rules are affected by the same inconsistencies as the regular restart policy. Kubelet restarts, container


Prompt:
Complete this yaml code:

# container restart delays will start at 10s, increasing
# 2x each time they are restarted, to a maximum of 100s

Response:
kind: KubeletConfiguration
crashLoopBackOff:
    maxContainerRestartPeriod: "100s"

Context: 1.1 - Pod Lifecycle | If you use this feature along with the alpha feature ReduceDefaultCrashLoopBackOffDecay (described above), your cluster defaults for initial backoff and maximum backoff will no longer be 10s and 300s,


Prompt:
Explain this yaml code:

# container restart delays will start at 10s, increasing
# 2x each time they are restarted, to a maximum of 100s
kind: KubeletConfiguration
crashLoopBackOff:
    maxContainerRestartPeriod: "100s"

Response: This yaml code 1.1 - Pod Lifecycle | If you use this feature along with the alpha feature ReduceDefaultCrashLoopBackOffDecay (described above), your cluster defaults for initial backoff and maximum backoff will no longer be 10s and 300s,


Prompt:
Complete this yaml code:

# delays between container restarts will always be 2s
kind: KubeletConfiguration

Response:
crashLoopBackOff:
    maxContainerRestartPeriod: "2s"


Prompt:
Explain this yaml code:

# delays between container restarts will always be 2s
kind: KubeletConfiguration
crashLoopBackOff:
    maxContainerRestartPeriod: "2s"

Response: This yaml code 1.1 - Pod Lifecycle | If you use this feature along with the alpha feature ReduceDefaultCrashLoopBackOffDecay (described above), your cluster defaults for initial backoff and maximum backoff will no longer be 10s and 300s,


Prompt:
Complete this yaml code:

kind: Pod
...
spec:
  readinessGates:
    - conditionType: "www.example.com/feature-1"
status:
  conditions:
    - type: Ready                              # a built-in PodCondition
      status: "False"

Response:
      lastProbeTime: null
      lastTransitionTime: 2018-01-01T00:00:00Z
    - type: "www.example.com/feature-1"        # an extra PodCondition
      status: "False"
      lastProbeTime: null
      lastTransitionTime: 2018-01-01T00:00:00Z
  containerStatuses:
    - containerID: docker://abcd...
      ready: true
...

Context: 1.1 - Pod Lifecycle | The Pod conditions you add must have names that meet the Kubernetes label key format.


Prompt:
Explain this yaml code:

kind: Pod
...
spec:
  readinessGates:
    - conditionType: "www.example.com/feature-1"
status:
  conditions:
    - type: Ready                              # a built-in PodCondition
      status: "False"
      lastProbeTime: null
      lastTransitionTime: 2018-01-01T00:00:00Z
    - type: "www.example.com/feature-1"        # an extra PodCondition
      status: "False"
      lastProbeTime: null
      lastTransitionTime: 2018-01-01T00:00:00Z
  containerStatuses:
    - containerID: docker://abcd...
      ready: true
...

Response: This yaml code 1.1 - Pod Lifecycle | The Pod conditions you add must have names that meet the Kubernetes label key format.


Prompt:
Complete this yaml code:

spec:
  os:
    name: linux
  containers:

Response:
    - name: my-container
      image: container-image:latest
      lifecycle:
        stopSignal: SIGUSR1

Context: 1.1 - Pod Lifecycle | If a stop signal is defined in the lifecycle, this will override the signal defined in the container image. If no stop signal is defined in the container spec, the container would fall back to the def


Prompt:
Explain this yaml code:

spec:
  os:
    name: linux
  containers:
    - name: my-container
      image: container-image:latest
      lifecycle:
        stopSignal: SIGUSR1

Response: This yaml code 1.1 - Pod Lifecycle | If a stop signal is defined in the lifecycle, this will override the signal defined in the container image. If no stop signal is defined in the container spec, the container would fall back to the def


Prompt:
Explain this shell code:

for i in {1..100}; do sleep 1; if nslookup myservice; then exit 0; fi; done; exit 1

Response: This shell code 1.2 - Init Containers | Register this Pod with a remote server from the downward API with a command like:

Context: 1.2 - Init Containers | Register this Pod with a remote server from the downward API with a command like:


Prompt:
Explain this shell code:

curl -X POST http://$MANAGEMENT_SERVICE_HOST:$MANAGEMENT_SERVICE_PORT/register -d 'instance=$(<POD_NAME>)&ip=$(<POD_IP>)'

Response: This shell code 1.2 - Init Containers | Wait for some time before starting the app container with a command like

Context: 1.2 - Init Containers | Wait for some time before starting the app container with a command like


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app.kubernetes.io/name: MyApp
spec:
  containers:
  - name: myapp-container

Response:
    image: busybox:1.28
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
  - name: init-mydb
    image: busybox:1.28
    command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]

Context: 1.2 - Init Containers | You can start this Pod by running:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app.kubernetes.io/name: MyApp
spec:
  containers:
  - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
  - name: init-mydb
    image: busybox:1.28
    command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]

Response: This yaml code 1.2 - Init Containers | You can start this Pod by running:


Prompt:
Explain this text code:

NAME        READY     STATUS     RESTARTS   AGE
myapp-pod   0/1       Init:0/2   0          6m

Response: This text code 1.2 - Init Containers | or for more details:

Context: 1.2 - Init Containers | or for more details:


Prompt:
Complete this text code:

Name:          myapp-pod
Namespace:     default
[...]
Labels:        app.kubernetes.io/name=MyApp
Status:        Pending
[...]
Init Containers:
  init-myservice:
[...]
    State:         Running
[...]
  init-mydb:
[...]
    State:         Waiting
      Reason:      PodInitializing
    Ready:         False

Response:
[...]
Containers:
  myapp-container:
[...]
    State:         Waiting
      Reason:      PodInitializing
    Ready:         False
[...]
Events:
  FirstSeen    LastSeen    Count    From                      SubObjectPath                           Type          Reason        Message
  ---------    --------    -----    ----                      -------------                           --------      ------        -------
  16s          16s         1        {default-scheduler }                                              Normal        Scheduled     Successfully assigned myapp-pod to 172.17.4.201
  16s          16s         1        {kubelet 172.17.4.201}    spec.initContainers{init-myservice}     Normal        Pulling       pulling image "busybox"
  13s          13s         1        {kubelet 172.17.4.201}    spec.initContainers{init-myservice}     Normal        Pulled        Successfully pulled image "busybox"
  13s          13s         1        {kubelet 172.17.4.201}    spec.initContainers{init-myservice}     Normal        Created       Created container init-myservice
  13s          13s         1        {kubelet 172.17.4.201}    spec.initContainers{init-myservice}     Normal        Started       Started container init-myservice

Context: 1.2 - Init Containers | To see logs for the init containers in this Pod, run:


Prompt:
Explain this text code:

Name:          myapp-pod
Namespace:     default
[...]
Labels:        app.kubernetes.io/name=MyApp
Status:        Pending
[...]
Init Containers:
  init-myservice:
[...]
    State:         Running
[...]
  init-mydb:
[...]
    State:         Waiting
      Reason:      PodInitializing
    Ready:         False
[...]
Containers:
  myapp-container:
[...]
    State:         Waiting
      Reason:      PodInitializing
    Ready:         False
[...]
Events:
  FirstSeen    LastSeen    Count    From                      SubObjectPath                           Type          Reason        Message
  ---------    --------    -----    ----                      -------------                           --------      ------        -------
  16s          16s         1        {default-scheduler }                                              Normal        Scheduled     Successfully assigned myapp-pod to 172.17.4.201
  16s          16s         1        {kubelet 172.17.4.201}    spec.initContainers{init-myservice}     Normal        Pulling       pulling image "busybox"
  13s          13s         1        {kubelet 172.17.4.201}    spec.initContainers{init-myservice}     Normal        Pulled        Successfully pulled image "busybox"
  13s          13s         1        {kubelet 172.17.4.201}    spec.initContainers{init-myservice}     Normal        Created       Created container init-myservice
  13s          13s         1        {kubelet 172.17.4.201}    spec.initContainers{init-myservice}     Normal        Started       Started container init-myservice

Response: This text code 1.2 - Init Containers | To see logs for the init containers in this Pod, run:


Prompt:
Explain this shell code:

kubectl logs myapp-pod -c init-myservice # Inspect the first init container
kubectl logs myapp-pod -c init-mydb      # Inspect the second init container

Response: This shell code 1.2 - Init Containers | At this point, those init containers will be waiting to discover Services named mydb and myservice.

Context: 1.2 - Init Containers | At this point, those init containers will be waiting to discover Services named mydb and myservice.


Prompt:
Complete this yaml code:

---
apiVersion: v1
kind: Service
metadata:
  name: myservice
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 9376

Response:
---
apiVersion: v1
kind: Service
metadata:
  name: mydb
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 9377

Context: 1.2 - Init Containers | To create the mydb and myservice services:


Prompt:
Explain this yaml code:

---
apiVersion: v1
kind: Service
metadata:
  name: myservice
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 9376
---
apiVersion: v1
kind: Service
metadata:
  name: mydb
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 9377

Response: This yaml code 1.2 - Init Containers | To create the mydb and myservice services:


Prompt:
Explain this text code:

NAME        READY     STATUS    RESTARTS   AGE
myapp-pod   1/1       Running   0          9m

Response: This text code 1.2 - Init Containers | This simple example should provide some inspiration for you to create your own init containers. What's next contains a link to a more detailed example.

Context: 1.2 - Init Containers | This simple example should provide some inspiration for you to create your own init containers. What's next contains a link to a more detailed example.


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:

Response:
        - name: myapp
          image: alpine:latest
          command: ['sh', '-c', 'while true; do echo "logging" >> /opt/logs.txt; sleep 1; done']
          volumeMounts:
            - name: data
              mountPath: /opt
      initContainers:
        - name: logshipper
          image: alpine:latest
          restartPolicy: Always
          command: ['sh', '-c', 'tail -F /opt/logs.txt']
          volumeMounts:
            - name: data
              mountPath: /opt
      volumes:
        - name: data
          emptyDir: {}

Context: 1.3 - Sidecar Containers | If an init container is created with its restartPolicy set to Always, it will start and remain running during the entire life of the Pod. This can be helpful for running supporting services separated


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: alpine:latest
          command: ['sh', '-c', 'while true; do echo "logging" >> /opt/logs.txt; sleep 1; done']
          volumeMounts:
            - name: data
              mountPath: /opt
      initContainers:
        - name: logshipper
          image: alpine:latest
          restartPolicy: Always
          command: ['sh', '-c', 'tail -F /opt/logs.txt']
          volumeMounts:
            - name: data
              mountPath: /opt
      volumes:
        - name: data
          emptyDir: {}

Response: This yaml code 1.3 - Sidecar Containers | If an init container is created with its restartPolicy set to Always, it will start and remain running during the entire life of the Pod. This can be helpful for running supporting services separated


Prompt:
Complete this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: myjob
spec:
  template:
    spec:
      containers:
        - name: myjob
          image: alpine:latest
          command: ['sh', '-c', 'echo "logging" > /opt/logs.txt']
          volumeMounts:
            - name: data

Response:
              mountPath: /opt
      initContainers:
        - name: logshipper
          image: alpine:latest
          restartPolicy: Always
          command: ['sh', '-c', 'tail -F /opt/logs.txt']
          volumeMounts:
            - name: data
              mountPath: /opt
      restartPolicy: Never
      volumes:
        - name: data
          emptyDir: {}

Context: 1.3 - Sidecar Containers | Sidecar containers run alongside app containers in the same pod. However, they do not execute the primary application logic; instead, they provide supporting functionality to the main application.


Prompt:
Explain this yaml code:

apiVersion: batch/v1
kind: Job
metadata:
  name: myjob
spec:
  template:
    spec:
      containers:
        - name: myjob
          image: alpine:latest
          command: ['sh', '-c', 'echo "logging" > /opt/logs.txt']
          volumeMounts:
            - name: data
              mountPath: /opt
      initContainers:
        - name: logshipper
          image: alpine:latest
          restartPolicy: Always
          command: ['sh', '-c', 'tail -F /opt/logs.txt']
          volumeMounts:
            - name: data
              mountPath: /opt
      restartPolicy: Never
      volumes:
        - name: data
          emptyDir: {}

Response: This yaml code 1.3 - Sidecar Containers | Sidecar containers run alongside app containers in the same pod. However, they do not execute the primary application logic; instead, they provide supporting functionality to the main application.


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: busybox-1
spec:

Response:
  containers:
  - image: busybox:1.28
    command:
      - sleep
      - "3600"
    name: busybox

Context: 1.6 - Pod Hostname | The Pod created by this manifest will have its hostname and fully qualified domain name (FQDN) set to busybox-1.


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: busybox-1
spec:
  containers:
  - image: busybox:1.28
    command:
      - sleep
      - "3600"
    name: busybox

Response: This yaml code 1.6 - Pod Hostname | The Pod created by this manifest will have its hostname and fully qualified domain name (FQDN) set to busybox-1.


Prompt:
Explain this text code:

busybox-1.busybox-subdomain.my-namespace.svc.cluster-domain.example

Response: This text code 1.6 - Pod Hostname | When both setHostnameAsFQDN: true and the subdomain field is set in the Pod spec, the kubelet writes the Pod's FQDN into the hostname for that Pod's namespace. In this case, both hostname and hostname

Context: 1.6 - Pod Hostname | When both setHostnameAsFQDN: true and the subdomain field is set in the Pod spec, the kubelet writes the Pod's FQDN into the hostname for that Pod's namespace. In this case, both hostname and hostname


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: busybox-2-busybox-example-domain
spec:
  hostnameOverride: busybox-2.busybox.example.domain

Response:
  containers:
  - image: busybox:1.28
    command:
      - sleep
      - "3600"
    name: busybox

Context: 1.6 - Pod Hostname | If hostnameOverride is set alongside hostname and subdomain fields:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: busybox-2-busybox-example-domain
spec:
  hostnameOverride: busybox-2.busybox.example.domain
  containers:
  - image: busybox:1.28
    command:
      - sleep
      - "3600"
    name: busybox

Response: This yaml code 1.6 - Pod Hostname | If hostnameOverride is set alongside hostname and subdomain fields:


Prompt:
Complete this text code:

# The format is
#   name:firstID:count of IDs
# where
# - firstID is 65536 (the minimum value possible)

Response:
# - count of IDs is 110 * 65536
#   (110 is the default limit for number of pods on the node)

kubelet:65536:7208960

Context: 1.8 - User Namespaces | Starting with Kubernetes v1.33, the ID count for each of Pods can be set in KubeletConfiguration.


Prompt:
Explain this text code:

# The format is
#   name:firstID:count of IDs
# where
# - firstID is 65536 (the minimum value possible)
# - count of IDs is 110 * 65536
#   (110 is the default limit for number of pods on the node)

kubelet:65536:7208960

Response: This text code 1.8 - User Namespaces | Starting with Kubernetes v1.33, the ID count for each of Pods can be set in KubeletConfiguration.


Prompt:
Complete this yaml code:

apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration

Response:
userNamespaces:
  idsPerPod: 1048576

Context: 1.8 - User Namespaces | The value of idsPerPod (uint32) must be a multiple of 65536. The default value is 65536. This value only applies to containers created after the kubelet was started with this KubeletConfiguration. Run


Prompt:
Explain this yaml code:

apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
userNamespaces:
  idsPerPod: 1048576

Response: This yaml code 1.8 - User Namespaces | The value of idsPerPod (uint32) must be a multiple of 65536. The default value is 65536. This value only applies to containers created after the kubelet was started with this KubeletConfiguration. Run


Prompt:
Explain this text code:

spec.initContainers[*].securityContext.runAsNonRoot

Response: This text code 1.8 - User Namespaces | When using a user namespace for the pod, it is disallowed to use other host namespaces. In particular, if you set hostUsers: false then you are not allowed to set any of:

Context: 1.8 - User Namespaces | When using a user namespace for the pod, it is disallowed to use other host namespaces. In particular, if you set hostUsers: false then you are not allowed to set any of:


Prompt:
Explain this text code:

spec.ephemeralContainers[*].securityContext.runAsNonRoot

Response: This text code 1.8 - User Namespaces | When using a user namespace for the pod, it is disallowed to use other host namespaces. In particular, if you set hostUsers: false then you are not allowed to set any of:


Prompt:
Explain this text code:

spec.ephemeralContainers[*].securityContext.runAsUser

Response: This text code 1.8 - User Namespaces | When using a user namespace for the pod, it is disallowed to use other host namespaces. In particular, if you set hostUsers: false then you are not allowed to set any of:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:

Response:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Context: 2.1 - Deployments | In this example:


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Response: This yaml code 2.1 - Deployments | In this example:

Context: 2.1 - Deployments | In this example:


Prompt:
Explain this shell code:

kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml

Response: This shell code 2.1 - Deployments | Run kubectl get deployments to check if the Deployment was created.

Context: 2.1 - Deployments | Run kubectl get deployments to check if the Deployment was created.


Prompt:
Explain this text code:

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   0/3     0            0           1s

Response: This text code 2.1 - Deployments | When you inspect the Deployments in your cluster, the following fields are displayed:

Context: 2.1 - Deployments | When you inspect the Deployments in your cluster, the following fields are displayed:


Prompt:
Explain this text code:

Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
deployment "nginx-deployment" successfully rolled out

Response: This text code 2.1 - Deployments | Run the kubectl get deployments again a few seconds later. The output is similar to this:

Context: 2.1 - Deployments | Run the kubectl get deployments again a few seconds later. The output is similar to this:


Prompt:
Explain this text code:

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           18s

Response: This text code 2.1 - Deployments | Notice that the Deployment has created all three replicas, and all replicas are up-to-date (they contain the latest Pod template) and available.

Context: 2.1 - Deployments | Notice that the Deployment has created all three replicas, and all replicas are up-to-date (they contain the latest Pod template) and available.


Prompt:
Explain this text code:

NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-75675f5897   3         3         3       18s

Response: This text code 2.1 - Deployments | ReplicaSet output shows the following fields:

Context: 2.1 - Deployments | ReplicaSet output shows the following fields:


Prompt:
Complete this text code:

NAME                                READY     STATUS    RESTARTS   AGE       LABELS
nginx-deployment-75675f5897-7ci7o   1/1       Running   0          18s       app=nginx,pod-template-hash=75675f5897

Response:
nginx-deployment-75675f5897-kzszj   1/1       Running   0          18s       app=nginx,pod-template-hash=75675f5897
nginx-deployment-75675f5897-qqcnn   1/1       Running   0          18s       app=nginx,pod-template-hash=75675f5897

Context: 2.1 - Deployments | The created ReplicaSet ensures that there are three nginx Pods.


Prompt:
Explain this text code:

NAME                                READY     STATUS    RESTARTS   AGE       LABELS
nginx-deployment-75675f5897-7ci7o   1/1       Running   0          18s       app=nginx,pod-template-hash=75675f5897
nginx-deployment-75675f5897-kzszj   1/1       Running   0          18s       app=nginx,pod-template-hash=75675f5897
nginx-deployment-75675f5897-qqcnn   1/1       Running   0          18s       app=nginx,pod-template-hash=75675f5897

Response: This text code 2.1 - Deployments | The created ReplicaSet ensures that there are three nginx Pods.


Prompt:
Explain this shell code:

kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.16.1

Response: This shell code 2.1 - Deployments | or use the following command:

Context: 2.1 - Deployments | or use the following command:


Prompt:
Explain this shell code:

kubectl set image deployment/nginx-deployment nginx=nginx:1.16.1

Response: This shell code 2.1 - Deployments | where deployment/nginx-deployment indicates the Deployment, nginx indicates the Container the update will take place and nginx:1.16.1 indicates the new image and its tag.

Context: 2.1 - Deployments | where deployment/nginx-deployment indicates the Deployment, nginx indicates the Container the update will take place and nginx:1.16.1 indicates the new image and its tag.


Prompt:
Explain this text code:

Waiting for rollout to finish: 2 out of 3 new replicas have been updated...

Response: This text code 2.1 - Deployments | or

Context: 2.1 - Deployments | or


Prompt:
Explain this text code:

deployment "nginx-deployment" successfully rolled out

Response: This text code 2.1 - Deployments | Get more details on your updated Deployment:

Context: 2.1 - Deployments | Get more details on your updated Deployment:


Prompt:
Explain this text code:

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           36s

Response: This text code 2.1 - Deployments | Run kubectl get rs to see that the Deployment updated the Pods by creating a new ReplicaSet and scaling it up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas.

Context: 2.1 - Deployments | Run kubectl get rs to see that the Deployment updated the Pods by creating a new ReplicaSet and scaling it up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas.


Prompt:
Explain this text code:

NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-1564180365   3         3         3       6s
nginx-deployment-2035384211   0         0         0       36s

Response: This text code 2.1 - Deployments | Running get pods should now show only the new Pods:

Context: 2.1 - Deployments | Running get pods should now show only the new Pods:


Prompt:
Complete this text code:

NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-1564180365-khku8   1/1       Running   0          14s

Response:
nginx-deployment-1564180365-nacti   1/1       Running   0          14s
nginx-deployment-1564180365-z9gth   1/1       Running   0          14s

Context: 2.1 - Deployments | Next time you want to update these Pods, you only need to update the Deployment's Pod template again.


Prompt:
Explain this text code:

NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-1564180365-khku8   1/1       Running   0          14s
nginx-deployment-1564180365-nacti   1/1       Running   0          14s
nginx-deployment-1564180365-z9gth   1/1       Running   0          14s

Response: This text code 2.1 - Deployments | Next time you want to update these Pods, you only need to update the Deployment's Pod template again.


Prompt:
Complete this text code:

Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Thu, 30 Nov 2017 10:56:25 +0000
Labels:                 app=nginx
Annotations:            deployment.kubernetes.io/revision=2
Selector:               app=nginx
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
   Containers:
    nginx:
      Image:        nginx:1.16.1
      Port:         80/TCP
      Environment:  <none>
      Mounts:       <none>

Response:
    Volumes:        <none>
  Conditions:
    Type           Status  Reason
    ----           ------  ------
    Available      True    MinimumReplicasAvailable
    Progressing    True    NewReplicaSetAvailable
  OldReplicaSets:  <none>
  NewReplicaSet:   nginx-deployment-1564180365 (3/3 replicas created)
  Events:
    Type    Reason             Age   From                   Message
    ----    ------             ----  ----                   -------
    Normal  ScalingReplicaSet  2m    deployment-controller  Scaled up replica set nginx-deployment-2035384211 to 3
    Normal  ScalingReplicaSet  24s   deployment-controller  Scaled up replica set nginx-deployment-1564180365 to 1
    Normal  ScalingReplicaSet  22s   deployment-controller  Scaled down replica set nginx-deployment-2035384211 to 2
    Normal  ScalingReplicaSet  22s   deployment-controller  Scaled up replica set nginx-deployment-1564180365 to 2
    Normal  ScalingReplicaSet  19s   deployment-controller  Scaled down replica set nginx-deployment-2035384211 to 1
    Normal  ScalingReplicaSet  19s   deployment-controller  Scaled up replica set nginx-deployment-1564180365 to 3
    Normal  ScalingReplicaSet  14s   deployment-controller  Scaled down replica set nginx-deployment-2035384211 to 0

Context: 2.1 - Deployments | Here you see that when you first created the Deployment, it created a ReplicaSet (nginx-deployment-2035384211) and scaled it up to 3 replicas directly. When you updated the Deployment, it created a ne


Prompt:
Explain this text code:

Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Thu, 30 Nov 2017 10:56:25 +0000
Labels:                 app=nginx
Annotations:            deployment.kubernetes.io/revision=2
Selector:               app=nginx
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
   Containers:
    nginx:
      Image:        nginx:1.16.1
      Port:         80/TCP
      Environment:  <none>
      Mounts:       <none>
    Volumes:        <none>
  Conditions:
    Type           Status  Reason
    ----           ------  ------
    Available      True    MinimumReplicasAvailable
    Progressing    True    NewReplicaSetAvailable
  OldReplicaSets:  <none>
  NewReplicaSet:   nginx-deployment-1564180365 (3/3 replicas created)
  Events:
    Type    Reason             Age   From                   Message
    ----    ------             ----  ----                   -------
    Normal  ScalingReplicaSet  2m    deployment-controller  Scaled up replica set nginx-deployment-2035384211 to 3
    Normal  ScalingReplicaSet  24s   deployment-controller  Scaled up replica set nginx-deployment-1564180365 to 1
    Normal  ScalingReplicaSet  22s   deployment-controller  Scaled down replica set nginx-deployment-2035384211 to 2
    Normal  ScalingReplicaSet  22s   deployment-controller  Scaled up replica set nginx-deployment-1564180365 to 2
    Normal  ScalingReplicaSet  19s   deployment-controller  Scaled down replica set nginx-deployment-2035384211 to 1
    Normal  ScalingReplicaSet  19s   deployment-controller  Scaled up replica set nginx-deployment-1564180365 to 3
    Normal  ScalingReplicaSet  14s   deployment-controller  Scaled down replica set nginx-deployment-2035384211 to 0

Response: This text code 2.1 - Deployments | Here you see that when you first created the Deployment, it created a ReplicaSet (nginx-deployment-2035384211) and scaled it up to 3 replicas directly. When you updated the Deployment, it created a ne


Prompt:
Explain this shell code:

kubectl set image deployment/nginx-deployment nginx=nginx:1.161

Response: This shell code 2.1 - Deployments | The output is similar to this:

Context: 2.1 - Deployments | The output is similar to this:


Prompt:
Explain this text code:

Waiting for rollout to finish: 1 out of 3 new replicas have been updated...

Response: This text code 2.1 - Deployments | Press Ctrl-C to stop the above rollout status watch. For more information on stuck rollouts, read more here.

Context: 2.1 - Deployments | Press Ctrl-C to stop the above rollout status watch. For more information on stuck rollouts, read more here.


Prompt:
Complete this text code:

NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-1564180365   3         3         3       25s

Response:
nginx-deployment-2035384211   0         0         0       36s
nginx-deployment-3066724191   1         1         0       6s

Context: 2.1 - Deployments | Looking at the Pods created, you see that 1 Pod created by new ReplicaSet is stuck in an image pull loop.


Prompt:
Explain this text code:

NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-1564180365   3         3         3       25s
nginx-deployment-2035384211   0         0         0       36s
nginx-deployment-3066724191   1         1         0       6s

Response: This text code 2.1 - Deployments | Looking at the Pods created, you see that 1 Pod created by new ReplicaSet is stuck in an image pull loop.


Prompt:
Complete this text code:

NAME                                READY     STATUS             RESTARTS   AGE
nginx-deployment-1564180365-70iae   1/1       Running            0          25s

Response:
nginx-deployment-1564180365-jbqqo   1/1       Running            0          25s
nginx-deployment-1564180365-hysrc   1/1       Running            0          25s
nginx-deployment-3066724191-08mng   0/1       ImagePullBackOff   0          6s

Context: 2.1 - Deployments | Get the description of the Deployment:


Prompt:
Explain this text code:

NAME                                READY     STATUS             RESTARTS   AGE
nginx-deployment-1564180365-70iae   1/1       Running            0          25s
nginx-deployment-1564180365-jbqqo   1/1       Running            0          25s
nginx-deployment-1564180365-hysrc   1/1       Running            0          25s
nginx-deployment-3066724191-08mng   0/1       ImagePullBackOff   0          6s

Response: This text code 2.1 - Deployments | Get the description of the Deployment:


Prompt:
Complete this text code:

Name:           nginx-deployment
Namespace:      default
CreationTimestamp:  Tue, 15 Mar 2016 14:48:04 -0700
Labels:         app=nginx
Selector:       app=nginx
Replicas:       3 desired | 1 updated | 4 total | 3 available | 1 unavailable
StrategyType:       RollingUpdate
MinReadySeconds:    0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx:1.161
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>

Response:
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    ReplicaSetUpdated
OldReplicaSets:     nginx-deployment-1564180365 (3/3 replicas created)
NewReplicaSet:      nginx-deployment-3066724191 (1/1 replicas created)
Events:
  FirstSeen LastSeen    Count   From                    SubObjectPath   Type        Reason              Message
  --------- --------    -----   ----                    -------------   --------    ------              -------
  1m        1m          1       {deployment-controller }                Normal      ScalingReplicaSet   Scaled up replica set nginx-deployment-2035384211 to 3
  22s       22s         1       {deployment-controller }                Normal      ScalingReplicaSet   Scaled up replica set nginx-deployment-1564180365 to 1
  22s       22s         1       {deployment-controller }                Normal      ScalingReplicaSet   Scaled down replica set nginx-deployment-2035384211 to 2
  22s       22s         1       {deployment-controller }                Normal      ScalingReplicaSet   Scaled up replica set nginx-deployment-1564180365 to 2
  21s       21s         1       {deployment-controller }                Normal      ScalingReplicaSet   Scaled down replica set nginx-deployment-2035384211 to 1
  21s       21s         1       {deployment-controller }                Normal      ScalingReplicaSet   Scaled up replica set nginx-deployment-1564180365 to 3
  13s       13s         1       {deployment-controller }                Normal      ScalingReplicaSet   Scaled down replica set nginx-deployment-2035384211 to 0
  13s       13s         1       {deployment-controller }                Normal      ScalingReplicaSet   Scaled up replica set nginx-deployment-3066724191 to 1

Context: 2.1 - Deployments | To fix this, you need to rollback to a previous revision of Deployment that is stable.