Prompt:
Explain this text code:

# Start a new watch
# End this watch when you've seen that the delete is finished
kubectl get pod --watch -l app=nginx

Response: This text code StatefulSet Basics | In a second terminal, use kubectl delete to delete all the Pods in the StatefulSet:

Context: StatefulSet Basics | In a second terminal, use kubectl delete to delete all the Pods in the StatefulSet:


Prompt:
Explain this text code:

# This should already be running
kubectl get pod --watch -l app=nginx

Response: This text code StatefulSet Basics | Use kubectl exec and kubectl run to view the Pods' hostnames and in-cluster DNS entries. First, view the Pods' hostnames:

Context: StatefulSet Basics | Use kubectl exec and kubectl run to view the Pods' hostnames and in-cluster DNS entries. First, view the Pods' hostnames:


Prompt:
Explain this text code:

for i in 0 1; do kubectl exec web-$i -- sh -c 'hostname'; done

Response: This text code StatefulSet Basics | then, run:

Context: StatefulSet Basics | then, run:


Prompt:
Explain this bash code:

kubectl run -i --tty --image busybox:1.28 dns-test --restart=Never --rm

Response: This bash code StatefulSet Basics | which starts a new shell.In that new shell, run:

Context: StatefulSet Basics | which starts a new shell.In that new shell, run:


Prompt:
Explain this text code:

# Run this in the dns-test container shell
nslookup web-0.nginx

Response: This text code StatefulSet Basics | The output is similar to:

Context: StatefulSet Basics | The output is similar to:


Prompt:
Explain this text code:

for i in 0 1; do kubectl exec "web-$i" -- sh -c 'echo "$(hostname)" > /usr/share/nginx/html/index.html'; done

for i in 0 1; do kubectl exec -i -t "web-$i" -- curl http://localhost/; done

Response: This text code StatefulSet Basics | If you instead see 403 Forbidden responses for the above curl command, you will need to fix the permissions of the directory mounted by the volumeMounts (due to a bug when using hostPath volumes), by

Context: StatefulSet Basics | If you instead see 403 Forbidden responses for the above curl command, you will need to fix the permissions of the directory mounted by the volumeMounts (due to a bug when using hostPath volumes), by


Prompt:
Explain this text code:

# End this watch when you've reached the end of the section.
# At the start of "Scaling a StatefulSet" you'll start a new watch.
kubectl get pod --watch -l app=nginx

Response: This text code StatefulSet Basics | In a second terminal, delete all of the StatefulSet's Pods:

Context: StatefulSet Basics | In a second terminal, delete all of the StatefulSet's Pods:


Prompt:
Explain this text code:

# This should already be running
kubectl get pod --watch -l app=nginx

Response: This text code StatefulSet Basics | Verify the web servers continue to serve their hostnames:

Context: StatefulSet Basics | Verify the web servers continue to serve their hostnames:


Prompt:
Complete this text code:

# If you already have a watch running, you can continue using that.
# Otherwise, start one.

Response:
# End this watch when there are 5 healthy Pods for the StatefulSet
kubectl get pods --watch -l app=nginx

Context: StatefulSet Basics | In another terminal window, use kubectl scale to scale the number of replicas to 5:


Prompt:
Explain this text code:

# If you already have a watch running, you can continue using that.
# Otherwise, start one.
# End this watch when there are 5 healthy Pods for the StatefulSet
kubectl get pods --watch -l app=nginx

Response: This text code StatefulSet Basics | In another terminal window, use kubectl scale to scale the number of replicas to 5:


Prompt:
Explain this text code:

# This should already be running
kubectl get pod --watch -l app=nginx

Response: This text code StatefulSet Basics | The StatefulSet controller scaled the number of replicas. As with StatefulSet creation, the StatefulSet controller created each Pod sequentially with respect to its ordinal index, and it waited for ea

Context: StatefulSet Basics | The StatefulSet controller scaled the number of replicas. As with StatefulSet creation, the StatefulSet controller created each Pod sequentially with respect to its ordinal index, and it waited for ea


Prompt:
Explain this text code:

# End this watch when there are only 3 Pods for the StatefulSet
kubectl get pod --watch -l app=nginx

Response: This text code StatefulSet Basics | In another terminal, use kubectl patch to scale the StatefulSet back down to three replicas:

Context: StatefulSet Basics | In another terminal, use kubectl patch to scale the StatefulSet back down to three replicas:


Prompt:
Explain this text code:

# This should already be running
kubectl get pods --watch -l app=nginx

Response: This text code StatefulSet Basics | The control plane deleted one Pod at a time, in reverse order with respect to its ordinal index, and it waited for each Pod to be completely shut down before deleting the next one.

Context: StatefulSet Basics | The control plane deleted one Pod at a time, in reverse order with respect to its ordinal index, and it waited for each Pod to be completely shut down before deleting the next one.


Prompt:
Explain this bash code:

kubectl patch statefulset web --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"registry.k8s.io/nginx-slim:0.24"}]'

Response: This bash code StatefulSet Basics | In another terminal, watch the Pods in the StatefulSet:

Context: StatefulSet Basics | In another terminal, watch the Pods in the StatefulSet:


Prompt:
Complete this text code:

# End this watch when the rollout is complete
#

Response:
# If you're not sure, leave it running one more minute
kubectl get pod -l app=nginx --watch


Prompt:
Explain this text code:

# End this watch when the rollout is complete
#
# If you're not sure, leave it running one more minute
kubectl get pod -l app=nginx --watch

Response: This text code StatefulSet Basics | The output is similar to:


Prompt:
Explain this text code:

for p in 0 1 2; do kubectl get pod "web-$p" --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'; echo; done

Response: This text code StatefulSet Basics | All the Pods in the StatefulSet are now running the previous container image.

Context: StatefulSet Basics | All the Pods in the StatefulSet are now running the previous container image.


Prompt:
Complete this text code:

# The value of "partition" determines which ordinals a change applies to
# Make sure to use a number bigger than the last ordinal for the

Response:
# StatefulSet
kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"partition":3}}}}'

Context: StatefulSet Basics | Patch the StatefulSet again to change the container image that this StatefulSet uses:


Prompt:
Explain this text code:

# The value of "partition" determines which ordinals a change applies to
# Make sure to use a number bigger than the last ordinal for the
# StatefulSet
kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"partition":3}}}}'

Response: This text code StatefulSet Basics | Patch the StatefulSet again to change the container image that this StatefulSet uses:


Prompt:
Explain this bash code:

kubectl patch statefulset web --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"registry.k8s.io/nginx-slim:0.21"}]'

Response: This bash code StatefulSet Basics | Delete a Pod in the StatefulSet:

Context: StatefulSet Basics | Delete a Pod in the StatefulSet:


Prompt:
Explain this text code:

# End the watch when you see that web-2 is healthy
kubectl get pod -l app=nginx --watch

Response: This text code StatefulSet Basics | Get the Pod's container image:

Context: StatefulSet Basics | Get the Pod's container image:


Prompt:
Explain this bash code:

kubectl get pod web-2 --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'

Response: This bash code StatefulSet Basics | Notice that, even though the update strategy is RollingUpdate the StatefulSet restored the Pod with the original container image. This is because the ordinal of the Pod is less than the partition spec

Context: StatefulSet Basics | Notice that, even though the update strategy is RollingUpdate the StatefulSet restored the Pod with the original container image. This is because the ordinal of the Pod is less than the partition spec


Prompt:
Explain this text code:

# The value of "partition" should match the highest existing ordinal for
# the StatefulSet
kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"partition":2}}}}'

Response: This text code StatefulSet Basics | The control plane triggers replacement for web-2 (implemented by a graceful delete followed by creating a new Pod once the deletion is complete). Wait for the new web-2 Pod to be Running and Ready.

Context: StatefulSet Basics | The control plane triggers replacement for web-2 (implemented by a graceful delete followed by creating a new Pod once the deletion is complete). Wait for the new web-2 Pod to be Running and Ready.


Prompt:
Explain this text code:

# This should already be running
kubectl get pod -l app=nginx --watch

Response: This text code StatefulSet Basics | Get the Pod's container:

Context: StatefulSet Basics | Get the Pod's container:


Prompt:
Explain this bash code:

kubectl get pod web-2 --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'

Response: This bash code StatefulSet Basics | When you changed the partition, the StatefulSet controller automatically updated the web-2 Pod because the Pod's ordinal was greater than or equal to the partition.

Context: StatefulSet Basics | When you changed the partition, the StatefulSet controller automatically updated the web-2 Pod because the Pod's ordinal was greater than or equal to the partition.


Prompt:
Explain this text code:

# This should already be running
kubectl get pod -l app=nginx --watch

Response: This text code StatefulSet Basics | The output is similar to:

Context: StatefulSet Basics | The output is similar to:


Prompt:
Explain this bash code:

kubectl get pod web-1 --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'

Response: This bash code StatefulSet Basics | web-1 was restored to its original configuration because the Pod's ordinal was less than the partition. When a partition is specified, all Pods with an ordinal that is greater than or equal to the par

Context: StatefulSet Basics | web-1 was restored to its original configuration because the Pod's ordinal was less than the partition. When a partition is specified, all Pods with an ordinal that is greater than or equal to the par


Prompt:
Explain this bash code:

kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"partition":0}}}}'

Response: This bash code StatefulSet Basics | Wait for all of the Pods in the StatefulSet to become Running and Ready.

Context: StatefulSet Basics | Wait for all of the Pods in the StatefulSet to become Running and Ready.


Prompt:
Explain this text code:

# This should already be running
kubectl get pod -l app=nginx --watch

Response: This text code StatefulSet Basics | The output is similar to:


Prompt:
Explain this text code:

for p in 0 1 2; do kubectl get pod "web-$p" --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'; echo; done

Response: This text code StatefulSet Basics | By moving the partition to 0, you allowed the StatefulSet to continue the update process.

Context: StatefulSet Basics | By moving the partition to 0, you allowed the StatefulSet to continue the update process.


Prompt:
Explain this bash code:

kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"OnDelete", "rollingUpdate": null}}}'

Response: This bash code StatefulSet Basics | When you select this update strategy, the StatefulSet controller does not automatically update Pods when a modification is made to the StatefulSet's .spec.template field. You need to manage the rollou

Context: StatefulSet Basics | When you select this update strategy, the StatefulSet controller does not automatically update Pods when a modification is made to the StatefulSet's .spec.template field. You need to manage the rollou


Prompt:
Explain this text code:

# Leave this watch running until the next time you start a watch
kubectl get pods --watch -l app=nginx

Response: This text code StatefulSet Basics | In a second terminal, recreate the StatefulSet. Note that, unless you deleted the nginx Service (which you should not have), you will see an error indicating that the Service already exists.

Context: StatefulSet Basics | In a second terminal, recreate the StatefulSet. Note that, unless you deleted the nginx Service (which you should not have), you will see an error indicating that the Service already exists.


Prompt:
Explain this bash code:

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

Response: This bash code StatefulSet Basics | Ignore the error. It only indicates that an attempt was made to create the nginx headless Service even though that Service already exists.

Context: StatefulSet Basics | Ignore the error. It only indicates that an attempt was made to create the nginx headless Service even though that Service already exists.


Prompt:
Explain this text code:

# This should already be running
kubectl get pods --watch -l app=nginx

Response: This text code StatefulSet Basics | When the web StatefulSet was recreated, it first relaunched web-0. Since web-1 was already Running and Ready, when web-0 transitioned to Running and Ready, it adopted this Pod. Since you recreated the

Context: StatefulSet Basics | When the web StatefulSet was recreated, it first relaunched web-0. Since web-1 was already Running and Ready, when web-0 transitioned to Running and Ready, it adopted this Pod. Since you recreated the


Prompt:
Explain this text code:

for i in 0 1; do kubectl exec -i -t "web-$i" -- curl http://localhost/; done

Response: This text code StatefulSet Basics | Even though you deleted both the StatefulSet and the web-0 Pod, it still serves the hostname originally entered into its index.html file. This is because the StatefulSet never deletes the PersistentVo

Context: StatefulSet Basics | Even though you deleted both the StatefulSet and the web-0 Pod, it still serves the hostname originally entered into its index.html file. This is because the StatefulSet never deletes the PersistentVo


Prompt:
Explain this text code:

# Leave this running until the next page section
kubectl get pods --watch -l app=nginx

Response: This text code StatefulSet Basics | In another terminal, delete the StatefulSet again. This time, omit the --cascade=orphan parameter.

Context: StatefulSet Basics | In another terminal, delete the StatefulSet again. This time, omit the --cascade=orphan parameter.


Prompt:
Explain this text code:

# This should already be running
kubectl get pods --watch -l app=nginx

Response: This text code StatefulSet Basics | As you saw in the Scaling Down section, the Pods are terminated one at a time, with respect to the reverse order of their ordinal indices. Before terminating a Pod, the StatefulSet controller waits fo

Context: StatefulSet Basics | As you saw in the Scaling Down section, the Pods are terminated one at a time, with respect to the reverse order of their ordinal indices. Before terminating a Pod, the StatefulSet controller waits fo


Prompt:
Explain this bash code:

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

Response: This bash code StatefulSet Basics | When all of the StatefulSet's Pods transition to Running and Ready, retrieve the contents of their index.html files:

Context: StatefulSet Basics | When all of the StatefulSet's Pods transition to Running and Ready, retrieve the contents of their index.html files:


Prompt:
Explain this text code:

for i in 0 1; do kubectl exec -i -t "web-$i" -- curl http://localhost/; done

Response: This text code StatefulSet Basics | Even though you completely deleted the StatefulSet, and all of its Pods, the Pods are recreated with their PersistentVolumes mounted, and web-0 and web-1 continue to serve their hostnames.

Context: StatefulSet Basics | Even though you completely deleted the StatefulSet, and all of its Pods, the Pods are recreated with their PersistentVolumes mounted, and web-0 and web-1 continue to serve their hostnames.


Prompt:
Complete this yaml code:

application/web/web-parallel.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  podManagementPolicy: "Parallel"
  replicas: 2
  selector:

Response:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: registry.k8s.io/nginx-slim:0.24
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi

Context: StatefulSet Basics | This manifest is identical to the one you downloaded above except that the .spec.podManagementPolicy of the web StatefulSet is set to Parallel.


Prompt:
Explain this yaml code:

application/web/web-parallel.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  podManagementPolicy: "Parallel"
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: registry.k8s.io/nginx-slim:0.24
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi

Response: This yaml code StatefulSet Basics | This manifest is identical to the one you downloaded above except that the .spec.podManagementPolicy of the web StatefulSet is set to Parallel.


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  podManagementPolicy: "Parallel"
  replicas: 2
  selector:

Response:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: registry.k8s.io/nginx-slim:0.24
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  podManagementPolicy: "Parallel"
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: registry.k8s.io/nginx-slim:0.24
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi

Response: This yaml code StatefulSet Basics | This manifest is identical to the one you downloaded above except that the .spec.podManagementPolicy of the web StatefulSet is set to Parallel.


Prompt:
Explain this text code:

# Leave this watch running until the end of the section
kubectl get pod -l app=nginx --watch

Response: This text code StatefulSet Basics | In another terminal, reconfigure the StatefulSet for Parallel Pod management:

Context: StatefulSet Basics | In another terminal, reconfigure the StatefulSet for Parallel Pod management:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/application/web/web-parallel.yaml

Response: This bash code StatefulSet Basics | Keep the terminal open where you're running the watch. In another terminal window, scale the StatefulSet:

Context: StatefulSet Basics | Keep the terminal open where you're running the watch. In another terminal window, scale the StatefulSet:


Prompt:
Explain this bash code:

kubectl delete sts web
# sts is an abbreviation for statefulset

Response: This bash code StatefulSet Basics | You can watch kubectl get to see those Pods being deleted.

Context: StatefulSet Basics | You can watch kubectl get to see those Pods being deleted.


Prompt:
Explain this text code:

# end the watch when you've seen what you need to
kubectl get pod -l app=nginx --watch

Response: This text code StatefulSet Basics | During deletion, a StatefulSet removes all Pods concurrently; it does not wait for a Pod's ordinal successor to terminate prior to deleting that Pod.

Context: StatefulSet Basics | During deletion, a StatefulSet removes all Pods concurrently; it does not wait for a Pod's ordinal successor to terminate prior to deleting that Pod.


Prompt:
Explain this bash code:

kubectl delete pvc www-web-0 www-web-1 www-web-2 www-web-3 www-web-4

Response: This bash code StatefulSet Basics |

Context: StatefulSet Basics |


Prompt:
Complete this text code:

spec:
  containers:

Response:
  - name: nginx
    image: nginx

Context: Node Resource Managers | The pod above runs in the BestEffort QoS class because no resource requests or limits are specified. It runs in the shared pool.


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx

Response: This text code Node Resource Managers | The pod above runs in the BestEffort QoS class because no resource requests or limits are specified. It runs in the shared pool.


Prompt:
Complete this text code:

spec:
  containers:
  - name: nginx
    image: nginx

Response:
    resources:
      limits:
        memory: "200Mi"
      requests:
        memory: "100Mi"

Context: Node Resource Managers | The pod above runs in the Burstable QoS class because resource requests do not equal limits and the cpu quantity is not specified. It runs in the shared pool.


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
      requests:
        memory: "100Mi"

Response: This text code Node Resource Managers | The pod above runs in the Burstable QoS class because resource requests do not equal limits and the cpu quantity is not specified. It runs in the shared pool.


Prompt:
Complete this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:

Response:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "100Mi"
        cpu: "1"

Context: Node Resource Managers | The pod above runs in the Burstable QoS class because resource requests do not equal limits. It runs in the shared pool.


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "100Mi"
        cpu: "1"

Response: This text code Node Resource Managers | The pod above runs in the Burstable QoS class because resource requests do not equal limits. It runs in the shared pool.


Prompt:
Complete this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:

Response:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "200Mi"
        cpu: "2"

Context: Node Resource Managers | The pod above runs in the Guaranteed QoS class because requests are equal to limits. And the container's resource limit for the CPU resource is an integer greater than or equal to one. The nginx conta


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "200Mi"
        cpu: "2"

Response: This text code Node Resource Managers | The pod above runs in the Guaranteed QoS class because requests are equal to limits. And the container's resource limit for the CPU resource is an integer greater than or equal to one. The nginx conta


Prompt:
Complete this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:

Response:
      limits:
        memory: "200Mi"
        cpu: "1.5"
      requests:
        memory: "200Mi"
        cpu: "1.5"

Context: Node Resource Managers | The pod above runs in the Guaranteed QoS class because requests are equal to limits. But the container's resource limit for the CPU resource is a fraction. It runs in the shared pool.


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "1.5"
      requests:
        memory: "200Mi"
        cpu: "1.5"

Response: This text code Node Resource Managers | The pod above runs in the Guaranteed QoS class because requests are equal to limits. But the container's resource limit for the CPU resource is a fraction. It runs in the shared pool.


Prompt:
Complete this text code:

spec:
  containers:
  - name: nginx
    image: nginx

Response:
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"

Context: Node Resource Managers | The pod above runs in the Guaranteed QoS class because only limits are specified and requests are set equal to limits when not explicitly specified. And the container's resource limit for the CPU reso


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"

Response: This text code Node Resource Managers | The pod above runs in the Guaranteed QoS class because only limits are specified and requests are set equal to limits when not explicitly specified. And the container's resource limit for the CPU reso


Prompt:
Complete this yaml code:

spec:
  containers:

Response:
  - name: nginx
    image: nginx


Prompt:
Explain this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx

Response: This yaml code Node Resource Managers | The pod above runs in the BestEffort QoS class because no resource requests or limits are specified. It runs in the shared pool.


Prompt:
Complete this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx

Response:
    resources:
      limits:
        memory: "200Mi"
      requests:
        memory: "100Mi"


Prompt:
Explain this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
      requests:
        memory: "100Mi"

Response: This yaml code Node Resource Managers | The pod above runs in the Burstable QoS class because resource requests do not equal limits and the cpu quantity is not specified. It runs in the shared pool.


Prompt:
Complete this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:

Response:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "100Mi"
        cpu: "1"


Prompt:
Explain this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "100Mi"
        cpu: "1"

Response: This yaml code Node Resource Managers | The pod above runs in the Burstable QoS class because resource requests do not equal limits. It runs in the shared pool.


Prompt:
Complete this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:

Response:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "200Mi"
        cpu: "2"


Prompt:
Explain this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "200Mi"
        cpu: "2"

Response: This yaml code Node Resource Managers | The pod above runs in the Guaranteed QoS class because requests are equal to limits. And the container's resource limit for the CPU resource is an integer greater than or equal to one. The nginx conta


Prompt:
Complete this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:

Response:
      limits:
        memory: "200Mi"
        cpu: "1.5"
      requests:
        memory: "200Mi"
        cpu: "1.5"


Prompt:
Explain this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "1.5"
      requests:
        memory: "200Mi"
        cpu: "1.5"

Response: This yaml code Node Resource Managers | The pod above runs in the Guaranteed QoS class because requests are equal to limits. But the container's resource limit for the CPU resource is a fraction. It runs in the shared pool.


Prompt:
Complete this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx

Response:
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"


Prompt:
Explain this yaml code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"

Response: This yaml code Node Resource Managers | The pod above runs in the Guaranteed QoS class because only limits are specified and requests are set equal to limits when not explicitly specified. And the container's resource limit for the CPU reso


Prompt:
Complete this text code:

spec:
  containers:

Response:
  - name: nginx
    image: nginx


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx

Response: This text code Node Resource Managers | The pod above runs in the BestEffort QoS class because no resource requests or limits are specified. It runs in the shared pool.


Prompt:
Complete this text code:

spec:
  containers:
  - name: nginx
    image: nginx

Response:
    resources:
      limits:
        memory: "200Mi"
      requests:
        memory: "100Mi"


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
      requests:
        memory: "100Mi"

Response: This text code Node Resource Managers | The pod above runs in the Burstable QoS class because resource requests do not equal limits and the cpu quantity is not specified. It runs in the shared pool.


Prompt:
Complete this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:

Response:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "100Mi"
        cpu: "1"


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "100Mi"
        cpu: "1"

Response: This text code Node Resource Managers | The pod above runs in the Burstable QoS class because resource requests do not equal limits. It runs in the shared pool.


Prompt:
Complete this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:

Response:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "200Mi"
        cpu: "2"


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"
      requests:
        memory: "200Mi"
        cpu: "2"

Response: This text code Node Resource Managers | The pod above runs in the Guaranteed QoS class because requests are equal to limits. And the container's resource limit for the CPU resource is an integer greater than or equal to one. The nginx conta


Prompt:
Complete this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:

Response:
      limits:
        memory: "200Mi"
        cpu: "1.5"
      requests:
        memory: "200Mi"
        cpu: "1.5"


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "1.5"
      requests:
        memory: "200Mi"
        cpu: "1.5"

Response: This text code Node Resource Managers | The pod above runs in the Guaranteed QoS class because requests are equal to limits. But the container's resource limit for the CPU resource is a fraction. It runs in the shared pool.


Prompt:
Complete this text code:

spec:
  containers:
  - name: nginx
    image: nginx

Response:
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"


Prompt:
Explain this text code:

spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      limits:
        memory: "200Mi"
        cpu: "2"

Response: This text code Node Resource Managers | The pod above runs in the Guaranteed QoS class because only limits are specified and requests are set equal to limits when not explicitly specified. And the container's resource limit for the CPU reso


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template

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

Context: 2 - Objects In Kubernetes | One way to create a Deployment using a manifest file like the one above is to use the kubectl apply command in the kubectl command-line interface, passing the .yaml file as an argument. Here's an exam


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Response: This yaml code 2 - Objects In Kubernetes | One way to create a Deployment using a manifest file like the one above is to use the kubectl apply command in the kubectl command-line interface, passing the .yaml file as an argument. Here's an exam


Prompt:
Explain this bash code:

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

Response: This bash code 2 - Objects In Kubernetes | The output is similar to this:

Context: 2 - Objects In Kubernetes | The output is similar to this:


Prompt:
Explain this bash code:

kubectl diff -R -f configs/
kubectl apply -R -f configs/

Response: This bash code 2.1 - Kubernetes Object Management | Advantages compared to imperative object configuration:

Context: 2.1 - Kubernetes Object Management | Advantages compared to imperative object configuration:


Prompt:
Complete this yaml code:

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

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

Context: 2.2 - Object Names and IDs | A Kubernetes systems-generated string to uniquely identify objects.


Prompt:
Explain this yaml code:

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

Response: This yaml code 2.2 - Object Names and IDs | A Kubernetes systems-generated string to uniquely identify objects.


Prompt:
Complete this text code:

"metadata": {
  "labels": {
    "key1" : "value1",

Response:
    "key2" : "value2"
  }
}

Context: 2.3 - Labels and Selectors | Labels allow for efficient queries and watches and are ideal for use in UIs and CLIs. Non-identifying information should be recorded using annotations.


Prompt:
Explain this text code:

"metadata": {
  "labels": {
    "key1" : "value1",
    "key2" : "value2"
  }
}

Response: This text code 2.3 - Labels and Selectors | Labels allow for efficient queries and watches and are ideal for use in UIs and CLIs. Non-identifying information should be recorded using annotations.


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: label-demo
  labels:
    environment: production

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

Context: 2.3 - Labels and Selectors | Unlike names and UIDs, labels do not provide uniqueness. In general, we expect many objects to carry the same label(s).


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: label-demo
  labels:
    environment: production
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

Response: This yaml code 2.3 - Labels and Selectors | Unlike names and UIDs, labels do not provide uniqueness. In general, we expect many objects to carry the same label(s).


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: cuda-test
spec:
  containers:

Response:
    - name: cuda-test
      image: "registry.k8s.io/cuda-vector-add:v0.1"
      resources:
        limits:
          nvidia.com/gpu: 1
  nodeSelector:
    accelerator: nvidia-tesla-p100

Context: 2.3 - Labels and Selectors | Set-based label requirements allow filtering keys according to a set of values. Three kinds of operators are supported: in,notin and exists (only the key identifier). For example:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: cuda-test
spec:
  containers:
    - name: cuda-test
      image: "registry.k8s.io/cuda-vector-add:v0.1"
      resources:
        limits:
          nvidia.com/gpu: 1
  nodeSelector:
    accelerator: nvidia-tesla-p100

Response: This yaml code 2.3 - Labels and Selectors | Set-based label requirements allow filtering keys according to a set of values. Three kinds of operators are supported: in,notin and exists (only the key identifier). For example:


Prompt:
Complete this text code:

environment in (production, qa)
tier notin (frontend, backend)

Response:
partition
!partition

Context: 2.3 - Labels and Selectors | Similarly the comma separator acts as an AND operator. So filtering resources with a partition key (no matter the value) and with environment different than qa can be achieved using partition,environm


Prompt:
Explain this text code:

environment in (production, qa)
tier notin (frontend, backend)
partition
!partition

Response: This text code 2.3 - Labels and Selectors | Similarly the comma separator acts as an AND operator. So filtering resources with a partition key (no matter the value) and with environment different than qa can be achieved using partition,environm


Prompt:
Explain this bash code:

kubectl get pods -l environment=production,tier=frontend

Response: This bash code 2.3 - Labels and Selectors | or using set-based requirements:

Context: 2.3 - Labels and Selectors | or using set-based requirements:


Prompt:
Explain this bash code:

kubectl get pods -l 'environment in (production),tier in (frontend)'

Response: This bash code 2.3 - Labels and Selectors | As already mentioned set-based requirements are more expressive. For instance, they can implement the OR operator on values:

Context: 2.3 - Labels and Selectors | As already mentioned set-based requirements are more expressive. For instance, they can implement the OR operator on values:


Prompt:
Explain this bash code:

kubectl get pods -l 'environment in (production, qa)'

Response: This bash code 2.3 - Labels and Selectors | or restricting negative matching via notin operator:

Context: 2.3 - Labels and Selectors | or restricting negative matching via notin operator:


Prompt:
Explain this bash code:

kubectl get pods -l 'environment,environment notin (frontend)'

Response: This bash code 2.3 - Labels and Selectors | Some Kubernetes objects, such as services and replicationcontrollers, also use label selectors to specify sets of other resources, such as pods.

Context: 2.3 - Labels and Selectors | Some Kubernetes objects, such as services and replicationcontrollers, also use label selectors to specify sets of other resources, such as pods.


Prompt:
Complete this text code:

selector:
  matchLabels:
    component: redis

Response:
  matchExpressions:
    - { key: tier, operator: In, values: [cache] }
    - { key: environment, operator: NotIn, values: [dev] }

Context: 2.3 - Labels and Selectors | matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values a


Prompt:
Explain this text code:

selector:
  matchLabels:
    component: redis
  matchExpressions:
    - { key: tier, operator: In, values: [cache] }
    - { key: environment, operator: NotIn, values: [dev] }

Response: This text code 2.3 - Labels and Selectors | matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values a


Prompt:
Complete this text code:

labels:
  app: guestbook

Response:
  tier: backend
  role: master

Context: 2.3 - Labels and Selectors | and


Prompt:
Explain this text code:

labels:
  app: guestbook
  tier: backend
  role: master

Response: This text code 2.3 - Labels and Selectors | and

Context: 2.3 - Labels and Selectors | and


Prompt:
Complete this text code:

labels:
  app: guestbook

Response:
  tier: backend
  role: replica

Context: 2.3 - Labels and Selectors | The labels allow for slicing and dicing the resources along any dimension specified by a label:


Prompt:
Explain this text code:

labels:
  app: guestbook
  tier: backend
  role: replica

Response: This text code 2.3 - Labels and Selectors | The labels allow for slicing and dicing the resources along any dimension specified by a label:


Prompt:
Explain this bash code:

kubectl apply -f examples/guestbook/all-in-one/guestbook-all-in-one.yaml
kubectl get pods -Lapp -Ltier -Lrole

Response: This bash code 2.3 - Labels and Selectors | Sometimes you may want to relabel existing pods and other resources before creating new resources. This can be done with kubectl label. For example, if you want to label all your NGINX Pods as fronten

Context: 2.3 - Labels and Selectors | Sometimes you may want to relabel existing pods and other resources before creating new resources. This can be done with kubectl label. For example, if you want to label all your NGINX Pods as fronten


Prompt:
Complete this text code:

NAME                           READY  STATUS    RESTARTS   AGE   APP         TIER       ROLE
guestbook-fe-4nlpb             1/1    Running   0          1m    guestbook   frontend   <none>
guestbook-fe-ght6d             1/1    Running   0          1m    guestbook   frontend   <none>
guestbook-fe-jpy62             1/1    Running   0          1m    guestbook   frontend   <none>

Response:
guestbook-redis-master-5pg3b   1/1    Running   0          1m    guestbook   backend    master
guestbook-redis-replica-2q2yf  1/1    Running   0          1m    guestbook   backend    replica
guestbook-redis-replica-qgazl  1/1    Running   0          1m    guestbook   backend    replica
my-nginx-divi2                 1/1    Running   0          29m   nginx       <none>     <none>
my-nginx-o0ef1                 1/1    Running   0          29m   nginx       <none>     <none>


Prompt:
Explain this text code:

NAME                           READY  STATUS    RESTARTS   AGE   APP         TIER       ROLE
guestbook-fe-4nlpb             1/1    Running   0          1m    guestbook   frontend   <none>
guestbook-fe-ght6d             1/1    Running   0          1m    guestbook   frontend   <none>
guestbook-fe-jpy62             1/1    Running   0          1m    guestbook   frontend   <none>
guestbook-redis-master-5pg3b   1/1    Running   0          1m    guestbook   backend    master
guestbook-redis-replica-2q2yf  1/1    Running   0          1m    guestbook   backend    replica
guestbook-redis-replica-qgazl  1/1    Running   0          1m    guestbook   backend    replica
my-nginx-divi2                 1/1    Running   0          29m   nginx       <none>     <none>
my-nginx-o0ef1                 1/1    Running   0          29m   nginx       <none>     <none>

Response: This text code 2.3 - Labels and Selectors | Sometimes you may want to relabel existing pods and other resources before creating new resources. This can be done with kubectl label. For example, if you want to label all your NGINX Pods as fronten


Prompt:
Explain this text code:

NAME                           READY  STATUS   RESTARTS  AGE
guestbook-redis-replica-2q2yf  1/1    Running  0         3m
guestbook-redis-replica-qgazl  1/1    Running  0         3m

Response: This text code 2.3 - Labels and Selectors | Sometimes you may want to relabel existing pods and other resources before creating new resources. This can be done with kubectl label. For example, if you want to label all your NGINX Pods as fronten


Prompt:
Explain this text code:

pod/my-nginx-2035384211-j5fhi labeled
pod/my-nginx-2035384211-u2c7e labeled
pod/my-nginx-2035384211-u3t6x labeled

Response: This text code 2.3 - Labels and Selectors | This first filters all pods with the label "app=nginx", and then labels them with the "tier=fe". To see the pods you labeled, run:

Context: 2.3 - Labels and Selectors | This first filters all pods with the label "app=nginx", and then labels them with the "tier=fe". To see the pods you labeled, run:


Prompt:
Complete this text code:

NAME                        READY     STATUS    RESTARTS   AGE       TIER
my-nginx-2035384211-j5fhi   1/1       Running   0          23m       fe

Response:
my-nginx-2035384211-u2c7e   1/1       Running   0          23m       fe
my-nginx-2035384211-u3t6x   1/1       Running   0          23m       fe

Context: 2.3 - Labels and Selectors | This outputs all "app=nginx" pods, with an additional label column of pods' tier (specified with -L or --label-columns).


Prompt:
Explain this text code:

NAME                        READY     STATUS    RESTARTS   AGE       TIER
my-nginx-2035384211-j5fhi   1/1       Running   0          23m       fe
my-nginx-2035384211-u2c7e   1/1       Running   0          23m       fe
my-nginx-2035384211-u3t6x   1/1       Running   0          23m       fe

Response: This text code 2.3 - Labels and Selectors | This outputs all "app=nginx" pods, with an additional label column of pods' tier (specified with -L or --label-columns).


Prompt:
Complete this text code:

NAME              STATUS   AGE
default           Active   1d

Response:
kube-node-lease   Active   1d
kube-public       Active   1d
kube-system       Active   1d

Context: 2.4 - Namespaces | To set the namespace for a current request, use the --namespace flag.


Prompt:
Explain this text code:

NAME              STATUS   AGE
default           Active   1d
kube-node-lease   Active   1d
kube-public       Active   1d
kube-system       Active   1d

Response: This text code 2.4 - Namespaces | To set the namespace for a current request, use the --namespace flag.


Prompt:
Explain this bash code:

kubectl run nginx --image=nginx --namespace=<insert-namespace-name-here>
kubectl get pods --namespace=<insert-namespace-name-here>

Response: This bash code 2.4 - Namespaces | You can permanently save the namespace for all subsequent kubectl commands in that context.

Context: 2.4 - Namespaces | You can permanently save the namespace for all subsequent kubectl commands in that context.


Prompt:
Explain this bash code:

kubectl config set-context --current --namespace=<insert-namespace-name-here>
# Validate it
kubectl config view --minify | grep namespace:

Response: This bash code 2.4 - Namespaces | When you create a Service, it creates a corresponding DNS entry. This entry is of the form <service-name>.<namespace-name>.svc.cluster.local, which means that if a container only uses <service-name>,

Context: 2.4 - Namespaces | When you create a Service, it creates a corresponding DNS entry. This entry is of the form <service-name>.<namespace-name>.svc.cluster.local, which means that if a container only uses <service-name>,


Prompt:
Complete this text code:

# In a namespace
kubectl api-resources --namespaced=true

Response:
# Not in a namespace
kubectl api-resources --namespaced=false

Context: 2.4 - Namespaces | The Kubernetes control plane sets an immutable label kubernetes.io/metadata.name on all namespaces. The value of the label is the namespace name.


Prompt:
Explain this text code:

# In a namespace
kubectl api-resources --namespaced=true

# Not in a namespace
kubectl api-resources --namespaced=false

Response: This text code 2.4 - Namespaces | The Kubernetes control plane sets an immutable label kubernetes.io/metadata.name on all namespaces. The value of the label is the namespace name.


Prompt:
Complete this text code:

"metadata": {
  "annotations": {
    "key1" : "value1",

Response:
    "key2" : "value2"
  }
}

Context: 2.5 - Annotations | Here are some examples of information that could be recorded in annotations:


Prompt:
Explain this text code:

"metadata": {
  "annotations": {
    "key1" : "value1",
    "key2" : "value2"
  }
}

Response: This text code 2.5 - Annotations | Here are some examples of information that could be recorded in annotations:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: annotations-demo
  annotations:
    imageregistry: "https://hub.docker.com/"

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

Context: 2.5 - Annotations | Field selectors let you select Kubernetes objects based on the value of one or more resource fields. Here are some examples of field selector queries:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: annotations-demo
  annotations:
    imageregistry: "https://hub.docker.com/"
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

Response: This yaml code 2.5 - Annotations | Field selectors let you select Kubernetes objects based on the value of one or more resource fields. Here are some examples of field selector queries:


Prompt:
Explain this bash code:

kubectl get pods --field-selector status.phase=Running

Response: This bash code 2.6 - Field Selectors | Supported field selectors vary by Kubernetes resource type. All resource types support the metadata.name and metadata.namespace fields. Using unsupported field selectors produces an error. For example

Context: 2.6 - Field Selectors | Supported field selectors vary by Kubernetes resource type. All resource types support the metadata.name and metadata.namespace fields. Using unsupported field selectors produces an error. For example


Prompt:
Explain this text code:

Error from server (BadRequest): Unable to find "ingresses" that match label selector "", field selector "foo.bar=baz": "foo.bar" is not a known field selector: only "metadata.name", "metadata.namespace"

Response: This text code 2.6 - Field Selectors | All custom resource types support the metadata.name and metadata.namespace fields.

Context: 2.6 - Field Selectors | All custom resource types support the metadata.name and metadata.namespace fields.


Prompt:
Explain this bash code:

kubectl get services  --all-namespaces --field-selector metadata.namespace!=default

Response: This bash code 2.6 - Field Selectors | As with label and other selectors, field selectors can be chained together as a comma-separated list. This kubectl command selects all Pods for which the status.phase does not equal Running and the sp

Context: 2.6 - Field Selectors | As with label and other selectors, field selectors can be chained together as a comma-separated list. This kubectl command selects all Pods for which the status.phase does not equal Running and the sp


Prompt:
Explain this bash code:

kubectl get pods --field-selector=status.phase!=Running,spec.restartPolicy=Always

Response: This bash code 2.6 - Field Selectors | You can use field selectors across multiple resource types. This kubectl command selects all Statefulsets and Services that are not in the default namespace:

Context: 2.6 - Field Selectors | You can use field selectors across multiple resource types. This kubectl command selects all Statefulsets and Services that are not in the default namespace:


Prompt:
Explain this bash code:

kubectl get statefulsets,services --all-namespaces --field-selector metadata.namespace!=default

Response: This bash code 2.6 - Field Selectors | Finalizers are namespaced keys that tell Kubernetes to wait until specific conditions are met before it fully deletes resources that are marked for deletion. Finalizers alert controllers to clean up r

Context: 2.6 - Field Selectors | Finalizers are namespaced keys that tell Kubernetes to wait until specific conditions are met before it fully deletes resources that are marked for deletion. Finalizers alert controllers to clean up r


Prompt:
Complete this yaml code:

# This is an excerpt
apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:

Response:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
    app.kubernetes.io/managed-by: Helm

Context: 2.9 - Recommended Labels | An application can be installed one or more times into a Kubernetes cluster and, in some cases, the same namespace. For example, WordPress can be installed more than once where different websites are


Prompt:
Explain this yaml code:

# This is an excerpt
apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
    app.kubernetes.io/managed-by: Helm

Response: This yaml code 2.9 - Recommended Labels | An application can be installed one or more times into a Kubernetes cluster and, in some cases, the same namespace. For example, WordPress can be installed more than once where different websites are


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:

Response:
  labels:
    app.kubernetes.io/name: myservice
    app.kubernetes.io/instance: myservice-abcxyz
...

Context: 2.9 - Recommended Labels | The Service is used to expose the application.


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: myservice
    app.kubernetes.io/instance: myservice-abcxyz
...

Response: This yaml code 2.9 - Recommended Labels | The Service is used to expose the application.


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Service
metadata:

Response:
  labels:
    app.kubernetes.io/name: myservice
    app.kubernetes.io/instance: myservice-abcxyz
...

Context: 2.9 - Recommended Labels | Consider a slightly more complicated application: a web application (WordPress) using a database (MySQL), installed using Helm. The following snippets illustrate the start of objects used to deploy th


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: myservice
    app.kubernetes.io/instance: myservice-abcxyz
...

Response: This yaml code 2.9 - Recommended Labels | Consider a slightly more complicated application: a web application (WordPress) using a database (MySQL), installed using Helm. The following snippets illustrate the start of objects used to deploy th


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: wordpress

Response:
    app.kubernetes.io/instance: wordpress-abcxyz
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
...

Context: 2.9 - Recommended Labels | The Service is used to expose WordPress:


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: wordpress
    app.kubernetes.io/instance: wordpress-abcxyz
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
...

Response: This yaml code 2.9 - Recommended Labels | The Service is used to expose WordPress:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: wordpress

Response:
    app.kubernetes.io/instance: wordpress-abcxyz
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
...

Context: 2.9 - Recommended Labels | MySQL is exposed as a StatefulSet with metadata for both it and the larger application it belongs to:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: wordpress
    app.kubernetes.io/instance: wordpress-abcxyz
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
...

Response: This yaml code 2.9 - Recommended Labels | MySQL is exposed as a StatefulSet with metadata for both it and the larger application it belongs to:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app.kubernetes.io/name: mysql

Response:
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
...

Context: 2.9 - Recommended Labels | The Service is used to expose MySQL as part of WordPress:


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
...

Response: This yaml code 2.9 - Recommended Labels | The Service is used to expose MySQL as part of WordPress:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: mysql

Response:
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
...

Context: 2.9 - Recommended Labels | With the MySQL StatefulSet and Service you'll notice information about both MySQL and WordPress, the broader application, are included.


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
...

Response: This yaml code 2.9 - Recommended Labels | With the MySQL StatefulSet and Service you'll notice information about both MySQL and WordPress, the broader application, are included.


Prompt:
Complete this json code:

{
  "kind": "APIGroupList",
  "apiVersion": "v1",
  "groups": [
    {
      "name": "apiregistration.k8s.io",
      "versions": [
        {
          "groupVersion": "apiregistration.k8s.io/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "apiregistration.k8s.io/v1",
        "version": "v1"
      }

Response:
    },
    {
      "name": "apps",
      "versions": [
        {
          "groupVersion": "apps/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "apps/v1",
        "version": "v1"
      }
    },
    ...
}

Context: 3 - The Kubernetes API | Additional requests are needed to obtain the discovery document for each group version at /apis/<group>/<version> (for example: /apis/rbac.authorization.k8s.io/v1alpha1), which advertises the list of


Prompt:
Explain this json code:

{
  "kind": "APIGroupList",
  "apiVersion": "v1",
  "groups": [
    {
      "name": "apiregistration.k8s.io",
      "versions": [
        {
          "groupVersion": "apiregistration.k8s.io/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "apiregistration.k8s.io/v1",
        "version": "v1"
      }
    },
    {
      "name": "apps",
      "versions": [
        {
          "groupVersion": "apps/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "apps/v1",
        "version": "v1"
      }
    },
    ...
}

Response: This json code 3 - The Kubernetes API | Additional requests are needed to obtain the discovery document for each group version at /apis/<group>/<version> (for example: /apis/rbac.authorization.k8s.io/v1alpha1), which advertises the list of


Prompt:
Complete this json code:

{
    "paths": {
        ...,
        "api/v1": {
            "serverRelativeURL": "/openapi/v3/api/v1?hash=CC0E9BFD992D8C59AEC98A1E2336F899E8318D3CF4C68944C3DEC640AF5AB52D864AC50DAA8D145B3494F75FA3CFF939FCBDDA431DAD3CA79738B297795818CF"
        },

Response:
        "apis/admissionregistration.k8s.io/v1": {
            "serverRelativeURL": "/openapi/v3/apis/admissionregistration.k8s.io/v1?hash=E19CC93A116982CE5422FC42B590A8AFAD92CDE9AE4D59B5CAAD568F083AD07946E6CB5817531680BCE6E215C16973CD39003B0425F3477CFD854E89A9DB6597"
        },
        ....
    }
}

Context: 3 - The Kubernetes API | The relative URLs are pointing to immutable OpenAPI descriptions, in order to improve client-side caching. The proper HTTP caching headers are also set by the API server for that purpose (Expires to 1


Prompt:
Explain this json code:

{
    "paths": {
        ...,
        "api/v1": {
            "serverRelativeURL": "/openapi/v3/api/v1?hash=CC0E9BFD992D8C59AEC98A1E2336F899E8318D3CF4C68944C3DEC640AF5AB52D864AC50DAA8D145B3494F75FA3CFF939FCBDDA431DAD3CA79738B297795818CF"
        },
        "apis/admissionregistration.k8s.io/v1": {
            "serverRelativeURL": "/openapi/v3/apis/admissionregistration.k8s.io/v1?hash=E19CC93A116982CE5422FC42B590A8AFAD92CDE9AE4D59B5CAAD568F083AD07946E6CB5817531680BCE6E215C16973CD39003B0425F3477CFD854E89A9DB6597"
        },
        ....
    }
}

Response: This json code 3 - The Kubernetes API | The relative URLs are pointing to immutable OpenAPI descriptions, in order to improve client-side caching. The proper HTTP caching headers are also set by the API server for that purpose (Expires to 1


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template

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

Context: 2 - Objects In Kubernetes | One way to create a Deployment using a manifest file like the one above is to use the kubectl apply command in the kubectl command-line interface, passing the .yaml file as an argument. Here's an exam


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Response: This yaml code 2 - Objects In Kubernetes | One way to create a Deployment using a manifest file like the one above is to use the kubectl apply command in the kubectl command-line interface, passing the .yaml file as an argument. Here's an exam


Prompt:
Explain this shell code:

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

Response: This shell code 2 - Objects In Kubernetes | The output is similar to this:

Context: 2 - Objects In Kubernetes | The output is similar to this:


Prompt:
Explain this sh code:

kubectl diff -R -f configs/
kubectl apply -R -f configs/

Response: This sh code 2.1 - Kubernetes Object Management | Advantages compared to imperative object configuration:

Context: 2.1 - Kubernetes Object Management | Advantages compared to imperative object configuration:


Prompt:
Complete this yaml code:

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

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

Context: 2.2 - Object Names and IDs | A Kubernetes systems-generated string to uniquely identify objects.


Prompt:
Explain this yaml code:

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

Response: This yaml code 2.2 - Object Names and IDs | A Kubernetes systems-generated string to uniquely identify objects.


Prompt:
Complete this json code:

"metadata": {
  "labels": {
    "key1" : "value1",

Response:
    "key2" : "value2"
  }
}

Context: 2.3 - Labels and Selectors | Labels allow for efficient queries and watches and are ideal for use in UIs and CLIs. Non-identifying information should be recorded using annotations.


Prompt:
Explain this json code:

"metadata": {
  "labels": {
    "key1" : "value1",
    "key2" : "value2"
  }
}

Response: This json code 2.3 - Labels and Selectors | Labels allow for efficient queries and watches and are ideal for use in UIs and CLIs. Non-identifying information should be recorded using annotations.


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: label-demo
  labels:
    environment: production

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

Context: 2.3 - Labels and Selectors | Unlike names and UIDs, labels do not provide uniqueness. In general, we expect many objects to carry the same label(s).


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: label-demo
  labels:
    environment: production
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

Response: This yaml code 2.3 - Labels and Selectors | Unlike names and UIDs, labels do not provide uniqueness. In general, we expect many objects to carry the same label(s).


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: cuda-test
spec:
  containers:

Response:
    - name: cuda-test
      image: "registry.k8s.io/cuda-vector-add:v0.1"
      resources:
        limits:
          nvidia.com/gpu: 1
  nodeSelector:
    accelerator: nvidia-tesla-p100

Context: 2.3 - Labels and Selectors | Set-based label requirements allow filtering keys according to a set of values. Three kinds of operators are supported: in,notin and exists (only the key identifier). For example:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: cuda-test
spec:
  containers:
    - name: cuda-test
      image: "registry.k8s.io/cuda-vector-add:v0.1"
      resources:
        limits:
          nvidia.com/gpu: 1
  nodeSelector:
    accelerator: nvidia-tesla-p100

Response: This yaml code 2.3 - Labels and Selectors | Set-based label requirements allow filtering keys according to a set of values. Three kinds of operators are supported: in,notin and exists (only the key identifier). For example:


Prompt:
Complete this text code:

environment in (production, qa)
tier notin (frontend, backend)

Response:
partition
!partition

Context: 2.3 - Labels and Selectors | Similarly the comma separator acts as an AND operator. So filtering resources with a partition key (no matter the value) and with environment different than qa can be achieved using partition,environm


Prompt:
Explain this text code:

environment in (production, qa)
tier notin (frontend, backend)
partition
!partition

Response: This text code 2.3 - Labels and Selectors | Similarly the comma separator acts as an AND operator. So filtering resources with a partition key (no matter the value) and with environment different than qa can be achieved using partition,environm


Prompt:
Explain this text code:

partition in (customerA, customerB),environment!=qa

Response: This text code 2.3 - Labels and Selectors | For list and watch operations, you can specify label selectors to filter the sets of objects returned; you specify the filter using a query parameter. (To learn in detail about watches in Kubernetes,

Context: 2.3 - Labels and Selectors | For list and watch operations, you can specify label selectors to filter the sets of objects returned; you specify the filter using a query parameter. (To learn in detail about watches in Kubernetes,


Prompt:
Explain this text code:

?labelSelector=environment%3Dproduction,tier%3Dfrontend

Response: This text code 2.3 - Labels and Selectors | Both label selector styles can be used to list or watch resources via a REST client. For example, targeting apiserver with kubectl and using equality-based one may write:

Context: 2.3 - Labels and Selectors | Both label selector styles can be used to list or watch resources via a REST client. For example, targeting apiserver with kubectl and using equality-based one may write:


Prompt:
Explain this text code:

?labelSelector=environment+in+%28production%2Cqa%29%2Ctier+in+%28frontend%29

Response: This text code 2.3 - Labels and Selectors | Both label selector styles can be used to list or watch resources via a REST client. For example, targeting apiserver with kubectl and using equality-based one may write:


Prompt:
Explain this shell code:

kubectl get pods -l environment=production,tier=frontend

Response: This shell code 2.3 - Labels and Selectors | or using set-based requirements:

Context: 2.3 - Labels and Selectors | or using set-based requirements:


Prompt:
Explain this shell code:

kubectl get pods -l 'environment in (production),tier in (frontend)'

Response: This shell code 2.3 - Labels and Selectors | As already mentioned set-based requirements are more expressive. For instance, they can implement the OR operator on values:

Context: 2.3 - Labels and Selectors | As already mentioned set-based requirements are more expressive. For instance, they can implement the OR operator on values:


Prompt:
Explain this shell code:

kubectl get pods -l 'environment in (production, qa)'

Response: This shell code 2.3 - Labels and Selectors | or restricting negative matching via notin operator:

Context: 2.3 - Labels and Selectors | or restricting negative matching via notin operator:


Prompt:
Explain this shell code:

kubectl get pods -l 'environment,environment notin (frontend)'

Response: This shell code 2.3 - Labels and Selectors | Some Kubernetes objects, such as services and replicationcontrollers, also use label selectors to specify sets of other resources, such as pods.

Context: 2.3 - Labels and Selectors | Some Kubernetes objects, such as services and replicationcontrollers, also use label selectors to specify sets of other resources, such as pods.


Prompt:
Complete this yaml code:

selector:
  matchLabels:
    component: redis

Response:
  matchExpressions:
    - { key: tier, operator: In, values: [cache] }
    - { key: environment, operator: NotIn, values: [dev] }

Context: 2.3 - Labels and Selectors | matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values a


Prompt:
Explain this yaml code:

selector:
  matchLabels:
    component: redis
  matchExpressions:
    - { key: tier, operator: In, values: [cache] }
    - { key: environment, operator: NotIn, values: [dev] }

Response: This yaml code 2.3 - Labels and Selectors | matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values a


Prompt:
Complete this yaml code:

labels:
  app: guestbook

Response:
  tier: backend
  role: master

Context: 2.3 - Labels and Selectors | and


Prompt:
Explain this yaml code:

labels:
  app: guestbook
  tier: backend
  role: master

Response: This yaml code 2.3 - Labels and Selectors | and

Context: 2.3 - Labels and Selectors | and


Prompt:
Complete this yaml code:

labels:
  app: guestbook

Response:
  tier: backend
  role: replica

Context: 2.3 - Labels and Selectors | The labels allow for slicing and dicing the resources along any dimension specified by a label:


Prompt:
Explain this yaml code:

labels:
  app: guestbook
  tier: backend
  role: replica

Response: This yaml code 2.3 - Labels and Selectors | The labels allow for slicing and dicing the resources along any dimension specified by a label:


Prompt:
Explain this shell code:

kubectl apply -f examples/guestbook/all-in-one/guestbook-all-in-one.yaml
kubectl get pods -Lapp -Ltier -Lrole

Response: This shell code 2.3 - Labels and Selectors | Sometimes you may want to relabel existing pods and other resources before creating new resources. This can be done with kubectl label. For example, if you want to label all your NGINX Pods as fronten

Context: 2.3 - Labels and Selectors | Sometimes you may want to relabel existing pods and other resources before creating new resources. This can be done with kubectl label. For example, if you want to label all your NGINX Pods as fronten


Prompt:
Complete this none code:

NAME                           READY  STATUS    RESTARTS   AGE   APP         TIER       ROLE
guestbook-fe-4nlpb             1/1    Running   0          1m    guestbook   frontend   <none>
guestbook-fe-ght6d             1/1    Running   0          1m    guestbook   frontend   <none>
guestbook-fe-jpy62             1/1    Running   0          1m    guestbook   frontend   <none>

Response:
guestbook-redis-master-5pg3b   1/1    Running   0          1m    guestbook   backend    master
guestbook-redis-replica-2q2yf  1/1    Running   0          1m    guestbook   backend    replica
guestbook-redis-replica-qgazl  1/1    Running   0          1m    guestbook   backend    replica
my-nginx-divi2                 1/1    Running   0          29m   nginx       <none>     <none>
my-nginx-o0ef1                 1/1    Running   0          29m   nginx       <none>     <none>


Prompt:
Explain this none code:

NAME                           READY  STATUS    RESTARTS   AGE   APP         TIER       ROLE
guestbook-fe-4nlpb             1/1    Running   0          1m    guestbook   frontend   <none>
guestbook-fe-ght6d             1/1    Running   0          1m    guestbook   frontend   <none>
guestbook-fe-jpy62             1/1    Running   0          1m    guestbook   frontend   <none>
guestbook-redis-master-5pg3b   1/1    Running   0          1m    guestbook   backend    master
guestbook-redis-replica-2q2yf  1/1    Running   0          1m    guestbook   backend    replica
guestbook-redis-replica-qgazl  1/1    Running   0          1m    guestbook   backend    replica
my-nginx-divi2                 1/1    Running   0          29m   nginx       <none>     <none>
my-nginx-o0ef1                 1/1    Running   0          29m   nginx       <none>     <none>

Response: This none code 2.3 - Labels and Selectors | Sometimes you may want to relabel existing pods and other resources before creating new resources. This can be done with kubectl label. For example, if you want to label all your NGINX Pods as fronten


Prompt:
Explain this none code:

NAME                           READY  STATUS   RESTARTS  AGE
guestbook-redis-replica-2q2yf  1/1    Running  0         3m
guestbook-redis-replica-qgazl  1/1    Running  0         3m

Response: This none code 2.3 - Labels and Selectors | Sometimes you may want to relabel existing pods and other resources before creating new resources. This can be done with kubectl label. For example, if you want to label all your NGINX Pods as fronten


Prompt:
Explain this none code:

pod/my-nginx-2035384211-j5fhi labeled
pod/my-nginx-2035384211-u2c7e labeled
pod/my-nginx-2035384211-u3t6x labeled

Response: This none code 2.3 - Labels and Selectors | This first filters all pods with the label "app=nginx", and then labels them with the "tier=fe". To see the pods you labeled, run:

Context: 2.3 - Labels and Selectors | This first filters all pods with the label "app=nginx", and then labels them with the "tier=fe". To see the pods you labeled, run:


Prompt:
Complete this none code:

NAME                        READY     STATUS    RESTARTS   AGE       TIER
my-nginx-2035384211-j5fhi   1/1       Running   0          23m       fe

Response:
my-nginx-2035384211-u2c7e   1/1       Running   0          23m       fe
my-nginx-2035384211-u3t6x   1/1       Running   0          23m       fe

Context: 2.3 - Labels and Selectors | This outputs all "app=nginx" pods, with an additional label column of pods' tier (specified with -L or --label-columns).


Prompt:
Explain this none code:

NAME                        READY     STATUS    RESTARTS   AGE       TIER
my-nginx-2035384211-j5fhi   1/1       Running   0          23m       fe
my-nginx-2035384211-u2c7e   1/1       Running   0          23m       fe
my-nginx-2035384211-u3t6x   1/1       Running   0          23m       fe

Response: This none code 2.3 - Labels and Selectors | This outputs all "app=nginx" pods, with an additional label column of pods' tier (specified with -L or --label-columns).


Prompt:
Complete this text code:

NAME              STATUS   AGE
default           Active   1d

Response:
kube-node-lease   Active   1d
kube-public       Active   1d
kube-system       Active   1d

Context: 2.4 - Namespaces | To set the namespace for a current request, use the --namespace flag.


Prompt:
Explain this text code:

NAME              STATUS   AGE
default           Active   1d
kube-node-lease   Active   1d
kube-public       Active   1d
kube-system       Active   1d

Response: This text code 2.4 - Namespaces | To set the namespace for a current request, use the --namespace flag.


Prompt:
Explain this shell code:

kubectl run nginx --image=nginx --namespace=<insert-namespace-name-here>
kubectl get pods --namespace=<insert-namespace-name-here>

Response: This shell code 2.4 - Namespaces | You can permanently save the namespace for all subsequent kubectl commands in that context.

Context: 2.4 - Namespaces | You can permanently save the namespace for all subsequent kubectl commands in that context.


Prompt:
Explain this shell code:

kubectl config set-context --current --namespace=<insert-namespace-name-here>
# Validate it
kubectl config view --minify | grep namespace:

Response: This shell code 2.4 - Namespaces | When you create a Service, it creates a corresponding DNS entry. This entry is of the form <service-name>.<namespace-name>.svc.cluster.local, which means that if a container only uses <service-name>,

Context: 2.4 - Namespaces | When you create a Service, it creates a corresponding DNS entry. This entry is of the form <service-name>.<namespace-name>.svc.cluster.local, which means that if a container only uses <service-name>,


Prompt:
Complete this shell code:

# In a namespace
kubectl api-resources --namespaced=true

Response:
# Not in a namespace
kubectl api-resources --namespaced=false

Context: 2.4 - Namespaces | The Kubernetes control plane sets an immutable label kubernetes.io/metadata.name on all namespaces. The value of the label is the namespace name.


Prompt:
Explain this shell code:

# In a namespace
kubectl api-resources --namespaced=true

# Not in a namespace
kubectl api-resources --namespaced=false

Response: This shell code 2.4 - Namespaces | The Kubernetes control plane sets an immutable label kubernetes.io/metadata.name on all namespaces. The value of the label is the namespace name.


Prompt:
Complete this json code:

"metadata": {
  "annotations": {
    "key1" : "value1",

Response:
    "key2" : "value2"
  }
}

Context: 2.5 - Annotations | Here are some examples of information that could be recorded in annotations:


Prompt:
Explain this json code:

"metadata": {
  "annotations": {
    "key1" : "value1",
    "key2" : "value2"
  }
}

Response: This json code 2.5 - Annotations | Here are some examples of information that could be recorded in annotations:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: annotations-demo
  annotations:
    imageregistry: "https://hub.docker.com/"

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

Context: 2.5 - Annotations | Field selectors let you select Kubernetes objects based on the value of one or more resource fields. Here are some examples of field selector queries:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: annotations-demo
  annotations:
    imageregistry: "https://hub.docker.com/"
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

Response: This yaml code 2.5 - Annotations | Field selectors let you select Kubernetes objects based on the value of one or more resource fields. Here are some examples of field selector queries:


Prompt:
Explain this shell code:

kubectl get pods --field-selector status.phase=Running

Response: This shell code 2.6 - Field Selectors | Supported field selectors vary by Kubernetes resource type. All resource types support the metadata.name and metadata.namespace fields. Using unsupported field selectors produces an error. For example

Context: 2.6 - Field Selectors | Supported field selectors vary by Kubernetes resource type. All resource types support the metadata.name and metadata.namespace fields. Using unsupported field selectors produces an error. For example


Prompt:
Explain this text code:

Error from server (BadRequest): Unable to find "ingresses" that match label selector "", field selector "foo.bar=baz": "foo.bar" is not a known field selector: only "metadata.name", "metadata.namespace"

Response: This text code 2.6 - Field Selectors | All custom resource types support the metadata.name and metadata.namespace fields.

Context: 2.6 - Field Selectors | All custom resource types support the metadata.name and metadata.namespace fields.


Prompt:
Explain this shell code:

kubectl get services  --all-namespaces --field-selector metadata.namespace!=default

Response: This shell code 2.6 - Field Selectors | As with label and other selectors, field selectors can be chained together as a comma-separated list. This kubectl command selects all Pods for which the status.phase does not equal Running and the sp

Context: 2.6 - Field Selectors | As with label and other selectors, field selectors can be chained together as a comma-separated list. This kubectl command selects all Pods for which the status.phase does not equal Running and the sp


Prompt:
Explain this shell code:

kubectl get pods --field-selector=status.phase!=Running,spec.restartPolicy=Always

Response: This shell code 2.6 - Field Selectors | You can use field selectors across multiple resource types. This kubectl command selects all Statefulsets and Services that are not in the default namespace:

Context: 2.6 - Field Selectors | You can use field selectors across multiple resource types. This kubectl command selects all Statefulsets and Services that are not in the default namespace:


Prompt:
Explain this shell code:

kubectl get statefulsets,services --all-namespaces --field-selector metadata.namespace!=default

Response: This shell code 2.6 - Field Selectors | Finalizers are namespaced keys that tell Kubernetes to wait until specific conditions are met before it fully deletes resources that are marked for deletion. Finalizers alert controllers to clean up r

Context: 2.6 - Field Selectors | Finalizers are namespaced keys that tell Kubernetes to wait until specific conditions are met before it fully deletes resources that are marked for deletion. Finalizers alert controllers to clean up r


Prompt:
Explain this bash code:

kubectl get events -A --field-selector=reason=OwnerRefInvalidNamespace

Response: This bash code 2.8 - Owners and Dependents | When you tell Kubernetes to delete a resource, the API server allows the managing controller to process any finalizer rules for the resource. Finalizers prevent accidental deletion of resources your c

Context: 2.8 - Owners and Dependents | When you tell Kubernetes to delete a resource, the API server allows the managing controller to process any finalizer rules for the resource. Finalizers prevent accidental deletion of resources your c


Prompt:
Complete this yaml code:

# This is an excerpt
apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:

Response:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
    app.kubernetes.io/managed-by: Helm

Context: 2.9 - Recommended Labels | An application can be installed one or more times into a Kubernetes cluster and, in some cases, the same namespace. For example, WordPress can be installed more than once where different websites are


Prompt:
Explain this yaml code:

# This is an excerpt
apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
    app.kubernetes.io/managed-by: Helm

Response: This yaml code 2.9 - Recommended Labels | An application can be installed one or more times into a Kubernetes cluster and, in some cases, the same namespace. For example, WordPress can be installed more than once where different websites are


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:

Response:
  labels:
    app.kubernetes.io/name: myservice
    app.kubernetes.io/instance: myservice-abcxyz
...

Context: 2.9 - Recommended Labels | The Service is used to expose the application.


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: myservice
    app.kubernetes.io/instance: myservice-abcxyz
...

Response: This yaml code 2.9 - Recommended Labels | The Service is used to expose the application.


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Service
metadata:

Response:
  labels:
    app.kubernetes.io/name: myservice
    app.kubernetes.io/instance: myservice-abcxyz
...

Context: 2.9 - Recommended Labels | Consider a slightly more complicated application: a web application (WordPress) using a database (MySQL), installed using Helm. The following snippets illustrate the start of objects used to deploy th


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: myservice
    app.kubernetes.io/instance: myservice-abcxyz
...

Response: This yaml code 2.9 - Recommended Labels | Consider a slightly more complicated application: a web application (WordPress) using a database (MySQL), installed using Helm. The following snippets illustrate the start of objects used to deploy th


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: wordpress

Response:
    app.kubernetes.io/instance: wordpress-abcxyz
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
...

Context: 2.9 - Recommended Labels | The Service is used to expose WordPress:


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: wordpress
    app.kubernetes.io/instance: wordpress-abcxyz
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
...

Response: This yaml code 2.9 - Recommended Labels | The Service is used to expose WordPress:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: wordpress

Response:
    app.kubernetes.io/instance: wordpress-abcxyz
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
...

Context: 2.9 - Recommended Labels | MySQL is exposed as a StatefulSet with metadata for both it and the larger application it belongs to:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: wordpress
    app.kubernetes.io/instance: wordpress-abcxyz
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
...

Response: This yaml code 2.9 - Recommended Labels | MySQL is exposed as a StatefulSet with metadata for both it and the larger application it belongs to:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app.kubernetes.io/name: mysql

Response:
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
...

Context: 2.9 - Recommended Labels | The Service is used to expose MySQL as part of WordPress:


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
...

Response: This yaml code 2.9 - Recommended Labels | The Service is used to expose MySQL as part of WordPress:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: mysql

Response:
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
...

Context: 2.9 - Recommended Labels | With the MySQL StatefulSet and Service you'll notice information about both MySQL and WordPress, the broader application, are included.


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxyz
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
...

Response: This yaml code 2.9 - Recommended Labels | With the MySQL StatefulSet and Service you'll notice information about both MySQL and WordPress, the broader application, are included.


Prompt:
Explain this text code:

Accept: application/json;v=v2;g=apidiscovery.k8s.io;as=APIGroupDiscoveryList

Response: This text code 3 - The Kubernetes API | Without indicating the resource type using the Accept header, the default response for the /api and /apis endpoint is an unaggregated discovery document.

Context: 3 - The Kubernetes API | Without indicating the resource type using the Accept header, the default response for the /api and /apis endpoint is an unaggregated discovery document.


Prompt:
Complete this json code:

{
  "kind": "APIGroupList",
  "apiVersion": "v1",
  "groups": [
    {
      "name": "apiregistration.k8s.io",
      "versions": [
        {
          "groupVersion": "apiregistration.k8s.io/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "apiregistration.k8s.io/v1",
        "version": "v1"
      }

Response:
    },
    {
      "name": "apps",
      "versions": [
        {
          "groupVersion": "apps/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "apps/v1",
        "version": "v1"
      }
    },
    ...
}

Context: 3 - The Kubernetes API | Additional requests are needed to obtain the discovery document for each group version at /apis/<group>/<version> (for example: /apis/rbac.authorization.k8s.io/v1alpha1), which advertises the list of


Prompt:
Explain this json code:

{
  "kind": "APIGroupList",
  "apiVersion": "v1",
  "groups": [
    {
      "name": "apiregistration.k8s.io",
      "versions": [
        {
          "groupVersion": "apiregistration.k8s.io/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "apiregistration.k8s.io/v1",
        "version": "v1"
      }
    },
    {
      "name": "apps",
      "versions": [
        {
          "groupVersion": "apps/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "apps/v1",
        "version": "v1"
      }
    },
    ...
}

Response: This json code 3 - The Kubernetes API | Additional requests are needed to obtain the discovery document for each group version at /apis/<group>/<version> (for example: /apis/rbac.authorization.k8s.io/v1alpha1), which advertises the list of


Prompt:
Explain this text code:

application/com.github.proto-openapi.spec.v2@v1.0+protobuf

Response: This text code 3 - The Kubernetes API | Kubernetes supports publishing a description of its APIs as OpenAPI v3.

Context: 3 - The Kubernetes API | Kubernetes supports publishing a description of its APIs as OpenAPI v3.


Prompt:
Complete this yaml code:

{
    "paths": {
        ...,
        "api/v1": {
            "serverRelativeURL": "/openapi/v3/api/v1?hash=CC0E9BFD992D8C59AEC98A1E2336F899E8318D3CF4C68944C3DEC640AF5AB52D864AC50DAA8D145B3494F75FA3CFF939FCBDDA431DAD3CA79738B297795818CF"
        },

Response:
        "apis/admissionregistration.k8s.io/v1": {
            "serverRelativeURL": "/openapi/v3/apis/admissionregistration.k8s.io/v1?hash=E19CC93A116982CE5422FC42B590A8AFAD92CDE9AE4D59B5CAAD568F083AD07946E6CB5817531680BCE6E215C16973CD39003B0425F3477CFD854E89A9DB6597"
        },
        ....
    }
}

Context: 3 - The Kubernetes API | The relative URLs are pointing to immutable OpenAPI descriptions, in order to improve client-side caching. The proper HTTP caching headers are also set by the API server for that purpose (Expires to 1


Prompt:
Explain this yaml code:

{
    "paths": {
        ...,
        "api/v1": {
            "serverRelativeURL": "/openapi/v3/api/v1?hash=CC0E9BFD992D8C59AEC98A1E2336F899E8318D3CF4C68944C3DEC640AF5AB52D864AC50DAA8D145B3494F75FA3CFF939FCBDDA431DAD3CA79738B297795818CF"
        },
        "apis/admissionregistration.k8s.io/v1": {
            "serverRelativeURL": "/openapi/v3/apis/admissionregistration.k8s.io/v1?hash=E19CC93A116982CE5422FC42B590A8AFAD92CDE9AE4D59B5CAAD568F083AD07946E6CB5817531680BCE6E215C16973CD39003B0425F3477CFD854E89A9DB6597"
        },
        ....
    }
}

Response: This yaml code 3 - The Kubernetes API | The relative URLs are pointing to immutable OpenAPI descriptions, in order to improve client-side caching. The proper HTTP caching headers are also set by the API server for that purpose (Expires to 1


Prompt:
Explain this text code:

application/com.github.proto-openapi.spec.v3@v1.0+protobuf

Response: This text code 3 - The Kubernetes API | A Golang implementation to fetch the OpenAPI V3 is provided in the package k8s.io/client-go/openapi3.

Context: 3 - The Kubernetes API | A Golang implementation to fetch the OpenAPI V3 is provided in the package k8s.io/client-go/openapi3.


Prompt:
Complete this yaml code:

application/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template

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

Context: 2 - Objects In Kubernetes | One way to create a Deployment using a manifest file like the one above is to use the kubectl apply command in the kubectl command-line interface, passing the .yaml file as an argument. Here's an exam


Prompt:
Explain this yaml code:

application/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Response: This yaml code 2 - Objects In Kubernetes | One way to create a Deployment using a manifest file like the one above is to use the kubectl apply command in the kubectl command-line interface, passing the .yaml file as an argument. Here's an exam


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template

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


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Response: This yaml code 2 - Objects In Kubernetes | One way to create a Deployment using a manifest file like the one above is to use the kubectl apply command in the kubectl command-line interface, passing the .yaml file as an argument. Here's an exam