Prompt:
Explain this yaml code:

apiVersion: v1
data:
  fruits: mangoes
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-04T16:04:19Z"
  name: fruits
  namespace: default
  resourceVersion: "1749472"

Response: This yaml code Updating Configuration via a ConfigMap | You should see the following output:


Prompt:
Explain this text code:

# As the text explains, the output does NOT change
kubectl logs deployments/configmap-env-var --follow

Response: This text code Updating Configuration via a ConfigMap | Notice that the output remains unchanged, even though you edited the ConfigMap:

Context: Updating Configuration via a ConfigMap | Notice that the output remains unchanged, even though you edited the ConfigMap:


Prompt:
Complete this text code:

Thu Jan  4 16:12:56 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:06 UTC 2024 The basket is full of apples

Response:
Thu Jan  4 16:13:16 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:26 UTC 2024 The basket is full of apples

Context: Updating Configuration via a ConfigMap | You can trigger that replacement. Perform a rollout for the Deployment, using kubectl rollout:


Prompt:
Explain this text code:

Thu Jan  4 16:12:56 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:06 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:16 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:26 UTC 2024 The basket is full of apples

Response: This text code Updating Configuration via a ConfigMap | You can trigger that replacement. Perform a rollout for the Deployment, using kubectl rollout:


Prompt:
Complete this text code:

# Trigger the rollout
kubectl rollout restart deployment configmap-env-var

Response:
# Wait for the rollout to complete
kubectl rollout status deployment configmap-env-var --watch=true

Context: Updating Configuration via a ConfigMap | Next, check the Deployment:


Prompt:
Explain this text code:

# Trigger the rollout
kubectl rollout restart deployment configmap-env-var

# Wait for the rollout to complete
kubectl rollout status deployment configmap-env-var --watch=true

Response: This text code Updating Configuration via a ConfigMap | Next, check the Deployment:


Prompt:
Explain this text code:

NAME                READY   UP-TO-DATE   AVAILABLE   AGE
configmap-env-var   3/3     3            3           12m

Response: This text code Updating Configuration via a ConfigMap | Check the Pods:

Context: Updating Configuration via a ConfigMap | Check the Pods:


Prompt:
Explain this bash code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-env-var

Response: This bash code Updating Configuration via a ConfigMap | The rollout causes Kubernetes to make a new ReplicaSet for the Deployment; that means the existing Pods eventually terminate, and new ones are created. After few seconds, you should see an output simi

Context: Updating Configuration via a ConfigMap | The rollout causes Kubernetes to make a new ReplicaSet for the Deployment; that means the existing Pods eventually terminate, and new ones are created. After few seconds, you should see an output simi


Prompt:
Complete this text code:

NAME                                 READY   STATUS        RESTARTS   AGE
configmap-env-var-6d94d89bf5-2ph2l   1/1     Running       0          13s

Response:
configmap-env-var-6d94d89bf5-74twx   1/1     Running       0          8s
configmap-env-var-6d94d89bf5-d5vx8   1/1     Running       0          11s

Context: Updating Configuration via a ConfigMap | View the logs for a Pod in this Deployment:


Prompt:
Explain this text code:

NAME                                 READY   STATUS        RESTARTS   AGE
configmap-env-var-6d94d89bf5-2ph2l   1/1     Running       0          13s
configmap-env-var-6d94d89bf5-74twx   1/1     Running       0          8s
configmap-env-var-6d94d89bf5-d5vx8   1/1     Running       0          11s

Response: This text code Updating Configuration via a ConfigMap | View the logs for a Pod in this Deployment:


Prompt:
Explain this text code:

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployment/configmap-env-var

Response: This text code Updating Configuration via a ConfigMap | You should see an output similar to the below:

Context: Updating Configuration via a ConfigMap | You should see an output similar to the below:


Prompt:
Complete this text code:

Found 3 pods, using pod/configmap-env-var-6d9ff89fb6-bzcf6
Thu Jan  4 16:30:35 UTC 2024 The basket is full of mangoes

Response:
Thu Jan  4 16:30:45 UTC 2024 The basket is full of mangoes
Thu Jan  4 16:30:55 UTC 2024 The basket is full of mangoes

Context: Updating Configuration via a ConfigMap | This demonstrates the scenario of updating environment variables in a Pod that are derived from a ConfigMap. Changes to the ConfigMap values are applied to the Pod during the subsequent rollout. If Po


Prompt:
Explain this text code:

Found 3 pods, using pod/configmap-env-var-6d9ff89fb6-bzcf6
Thu Jan  4 16:30:35 UTC 2024 The basket is full of mangoes
Thu Jan  4 16:30:45 UTC 2024 The basket is full of mangoes
Thu Jan  4 16:30:55 UTC 2024 The basket is full of mangoes

Response: This text code Updating Configuration via a ConfigMap | This demonstrates the scenario of updating environment variables in a Pod that are derived from a ConfigMap. Changes to the ConfigMap values are applied to the Pod during the subsequent rollout. If Po


Prompt:
Explain this bash code:

kubectl create configmap color --from-literal=color=red

Response: This bash code Updating Configuration via a ConfigMap | Below is an example manifest for a Deployment that manages a set of Pods, each with two containers. The two containers share an emptyDir volume that they use to communicate. The first container runs a

Context: Updating Configuration via a ConfigMap | Below is an example manifest for a Deployment that manages a set of Pods, each with two containers. The two containers share an emptyDir volume that they use to communicate. The first container runs a


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-two-containers
  labels:
    app.kubernetes.io/name: configmap-two-containers
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-two-containers
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-two-containers
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume

Response:
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
        - name: alpine
          image: alpine:3
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;

Context: Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-two-containers
  labels:
    app.kubernetes.io/name: configmap-two-containers
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-two-containers
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-two-containers
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
        - name: alpine
          image: alpine:3
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-two-containers.yaml

Response: This bash code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):

Context: Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this bash code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-two-containers

Response: This bash code Updating Configuration via a ConfigMap | You should see an output similar to:

Context: Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

NAME                                        READY   STATUS    RESTARTS   AGE
configmap-two-containers-565fb6d4f4-2xhxf   2/2     Running   0          20s

Response:
configmap-two-containers-565fb6d4f4-g5v4j   2/2     Running   0          20s
configmap-two-containers-565fb6d4f4-mzsmf   2/2     Running   0          20s

Context: Updating Configuration via a ConfigMap | Expose the Deployment (the kubectl tool creates a Service for you):


Prompt:
Explain this text code:

NAME                                        READY   STATUS    RESTARTS   AGE
configmap-two-containers-565fb6d4f4-2xhxf   2/2     Running   0          20s
configmap-two-containers-565fb6d4f4-g5v4j   2/2     Running   0          20s
configmap-two-containers-565fb6d4f4-mzsmf   2/2     Running   0          20s

Response: This text code Updating Configuration via a ConfigMap | Expose the Deployment (the kubectl tool creates a Service for you):


Prompt:
Explain this bash code:

kubectl expose deployment configmap-two-containers --name=configmap-service --port=8080 --target-port=80

Response: This bash code Updating Configuration via a ConfigMap | Use kubectl to forward the port:

Context: Updating Configuration via a ConfigMap | Use kubectl to forward the port:


Prompt:
Explain this text code:

# this stays running in the background
kubectl port-forward service/configmap-service 8080:8080 &

Response: This text code Updating Configuration via a ConfigMap | Access the service.

Context: Updating Configuration via a ConfigMap | Access the service.


Prompt:
Explain this text code:

Fri Jan  5 08:08:22 UTC 2024 My preferred color is red

Response: This text code Updating Configuration via a ConfigMap | Edit the ConfigMap:

Context: Updating Configuration via a ConfigMap | Edit the ConfigMap:


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  color: blue
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.

Response:
metadata:
  creationTimestamp: "2024-01-05T08:12:05Z"
  name: color
  namespace: configmap
  resourceVersion: "1801272"
  uid: 80d33e4a-cbb4-4bc9-ba8c-544c68e425d6

Context: Updating Configuration via a ConfigMap | Loop over the service URL for few seconds.


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  color: blue
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-05T08:12:05Z"
  name: color
  namespace: configmap
  resourceVersion: "1801272"
  uid: 80d33e4a-cbb4-4bc9-ba8c-544c68e425d6

Response: This yaml code Updating Configuration via a ConfigMap | Loop over the service URL for few seconds.


Prompt:
Explain this text code:

# Cancel this when you're happy with it (Ctrl-C)
while true; do curl --connect-timeout 7.5 http://localhost:8080; sleep 10; done

Response: This text code Updating Configuration via a ConfigMap | You should see the output change as follows:

Context: Updating Configuration via a ConfigMap | You should see the output change as follows:


Prompt:
Complete this text code:

Fri Jan  5 08:14:00 UTC 2024 My preferred color is red
Fri Jan  5 08:14:02 UTC 2024 My preferred color is red
Fri Jan  5 08:14:20 UTC 2024 My preferred color is red

Response:
Fri Jan  5 08:14:22 UTC 2024 My preferred color is red
Fri Jan  5 08:14:32 UTC 2024 My preferred color is blue
Fri Jan  5 08:14:43 UTC 2024 My preferred color is blue
Fri Jan  5 08:15:00 UTC 2024 My preferred color is blue

Context: Updating Configuration via a ConfigMap | The above scenario can be replicated by using a Sidecar Container as a helper container to write the HTML file.As a Sidecar Container is conceptually an Init Container, it is guaranteed to start befor


Prompt:
Explain this text code:

Fri Jan  5 08:14:00 UTC 2024 My preferred color is red
Fri Jan  5 08:14:02 UTC 2024 My preferred color is red
Fri Jan  5 08:14:20 UTC 2024 My preferred color is red
Fri Jan  5 08:14:22 UTC 2024 My preferred color is red
Fri Jan  5 08:14:32 UTC 2024 My preferred color is blue
Fri Jan  5 08:14:43 UTC 2024 My preferred color is blue
Fri Jan  5 08:15:00 UTC 2024 My preferred color is blue

Response: This text code Updating Configuration via a ConfigMap | The above scenario can be replicated by using a Sidecar Container as a helper container to write the HTML file.As a Sidecar Container is conceptually an Init Container, it is guaranteed to start befor


Prompt:
Explain this bash code:

kubectl create configmap color --from-literal=color=blue

Response: This bash code Updating Configuration via a ConfigMap | Below is an example manifest for a Deployment that manages a set of Pods, each with a main container and a sidecar container. The two containers share an emptyDir volume that they use to communicate.

Context: Updating Configuration via a ConfigMap | Below is an example manifest for a Deployment that manages a set of Pods, each with a main container and a sidecar container. The two containers share an emptyDir volume that they use to communicate.


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-sidecar-container
  labels:
    app.kubernetes.io/name: configmap-sidecar-container
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-sidecar-container
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-sidecar-container
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume
          configMap:

Response:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
      initContainers:
        - name: alpine
          image: alpine:3
          restartPolicy: Always
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-sidecar-container
  labels:
    app.kubernetes.io/name: configmap-sidecar-container
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-sidecar-container
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-sidecar-container
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
      initContainers:
        - name: alpine
          image: alpine:3
          restartPolicy: Always
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-and-sidecar-container.yaml

Response: This bash code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this bash code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-sidecar-container

Response: This bash code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

NAME                                           READY   STATUS    RESTARTS   AGE
configmap-sidecar-container-5fb59f558b-87rp7   2/2     Running   0          94s

Response:
configmap-sidecar-container-5fb59f558b-ccs7s   2/2     Running   0          94s
configmap-sidecar-container-5fb59f558b-wnmgk   2/2     Running   0          94s


Prompt:
Explain this text code:

NAME                                           READY   STATUS    RESTARTS   AGE
configmap-sidecar-container-5fb59f558b-87rp7   2/2     Running   0          94s
configmap-sidecar-container-5fb59f558b-ccs7s   2/2     Running   0          94s
configmap-sidecar-container-5fb59f558b-wnmgk   2/2     Running   0          94s

Response: This text code Updating Configuration via a ConfigMap | Expose the Deployment (the kubectl tool creates a Service for you):


Prompt:
Explain this bash code:

kubectl expose deployment configmap-sidecar-container --name=configmap-sidecar-service --port=8081 --target-port=80

Response: This bash code Updating Configuration via a ConfigMap | Use kubectl to forward the port:


Prompt:
Explain this text code:

# this stays running in the background
kubectl port-forward service/configmap-sidecar-service 8081:8081 &

Response: This text code Updating Configuration via a ConfigMap | Access the service.


Prompt:
Explain this text code:

Sat Feb 17 13:09:05 UTC 2024 My preferred color is blue

Response: This text code Updating Configuration via a ConfigMap | Edit the ConfigMap:


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  color: green
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.

Response:
metadata:
  creationTimestamp: "2024-02-17T12:20:30Z"
  name: color
  namespace: default
  resourceVersion: "1054"
  uid: e40bb34c-58df-4280-8bea-6ed16edccfaa


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  color: green
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-02-17T12:20:30Z"
  name: color
  namespace: default
  resourceVersion: "1054"
  uid: e40bb34c-58df-4280-8bea-6ed16edccfaa

Response: This yaml code Updating Configuration via a ConfigMap | Loop over the service URL for few seconds.


Prompt:
Explain this text code:

# Cancel this when you're happy with it (Ctrl-C)
while true; do curl --connect-timeout 7.5 http://localhost:8081; sleep 10; done

Response: This text code Updating Configuration via a ConfigMap | You should see the output change as follows:


Prompt:
Complete this text code:

Sat Feb 17 13:12:35 UTC 2024 My preferred color is blue
Sat Feb 17 13:12:45 UTC 2024 My preferred color is blue
Sat Feb 17 13:12:55 UTC 2024 My preferred color is blue

Response:
Sat Feb 17 13:13:05 UTC 2024 My preferred color is blue
Sat Feb 17 13:13:15 UTC 2024 My preferred color is green
Sat Feb 17 13:13:25 UTC 2024 My preferred color is green
Sat Feb 17 13:13:35 UTC 2024 My preferred color is green

Context: Updating Configuration via a ConfigMap | Immutable ConfigMaps are especially used for configuration that is constant and is not expected to change over time. Marking a ConfigMap as immutable allows a performance improvement where the kubelet


Prompt:
Explain this text code:

Sat Feb 17 13:12:35 UTC 2024 My preferred color is blue
Sat Feb 17 13:12:45 UTC 2024 My preferred color is blue
Sat Feb 17 13:12:55 UTC 2024 My preferred color is blue
Sat Feb 17 13:13:05 UTC 2024 My preferred color is blue
Sat Feb 17 13:13:15 UTC 2024 My preferred color is green
Sat Feb 17 13:13:25 UTC 2024 My preferred color is green
Sat Feb 17 13:13:35 UTC 2024 My preferred color is green

Response: This text code Updating Configuration via a ConfigMap | Immutable ConfigMaps are especially used for configuration that is constant and is not expected to change over time. Marking a ConfigMap as immutable allows a performance improvement where the kubelet


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  company_name: "ACME, Inc." # existing fictional company name

Response:
kind: ConfigMap
immutable: true
metadata:
  name: company-name-20150801

Context: Updating Configuration via a ConfigMap | Create the Immutable ConfigMap:


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  company_name: "ACME, Inc." # existing fictional company name
kind: ConfigMap
immutable: true
metadata:
  name: company-name-20150801

Response: This yaml code Updating Configuration via a ConfigMap | Create the Immutable ConfigMap:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/configmap/immutable-configmap.yaml

Response: This bash code Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with the Immutable ConfigMap company-name-20150801 mounted as a volume into the Pod's only container.

Context: Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with the Immutable ConfigMap company-name-20150801 mounted as a volume into the Pod's only container.


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: immutable-configmap-volume
  labels:
    app.kubernetes.io/name: immutable-configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: immutable-configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: immutable-configmap-volume
    spec:

Response:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The name of the company is $(cat /etc/config/company_name)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: company-name-20150801


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: immutable-configmap-volume
  labels:
    app.kubernetes.io/name: immutable-configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: immutable-configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: immutable-configmap-volume
    spec:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The name of the company is $(cat /etc/config/company_name)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: company-name-20150801

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-immutable-configmap-as-volume.yaml

Response: This bash code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this bash code:

kubectl get pods --selector=app.kubernetes.io/name=immutable-configmap-volume

Response: This bash code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

NAME                                          READY   STATUS    RESTARTS   AGE
immutable-configmap-volume-78b6fbff95-5gsfh   1/1     Running   0          62s

Response:
immutable-configmap-volume-78b6fbff95-7vcj4   1/1     Running   0          62s
immutable-configmap-volume-78b6fbff95-vdslm   1/1     Running   0          62s

Context: Updating Configuration via a ConfigMap | The Pod's container refers to the data defined in the ConfigMap and uses it to print a report to stdout. You can check this report by viewing the logs for one of the Pods in that Deployment:


Prompt:
Explain this text code:

NAME                                          READY   STATUS    RESTARTS   AGE
immutable-configmap-volume-78b6fbff95-5gsfh   1/1     Running   0          62s
immutable-configmap-volume-78b6fbff95-7vcj4   1/1     Running   0          62s
immutable-configmap-volume-78b6fbff95-vdslm   1/1     Running   0          62s

Response: This text code Updating Configuration via a ConfigMap | The Pod's container refers to the data defined in the ConfigMap and uses it to print a report to stdout. You can check this report by viewing the logs for one of the Pods in that Deployment:


Prompt:
Explain this text code:

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployments/immutable-configmap-volume

Response: This text code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

Found 3 pods, using pod/immutable-configmap-volume-78b6fbff95-5gsfh
Wed Mar 20 03:52:34 UTC 2024 The name of the company is ACME, Inc.

Response:
Wed Mar 20 03:52:44 UTC 2024 The name of the company is ACME, Inc.
Wed Mar 20 03:52:54 UTC 2024 The name of the company is ACME, Inc.

Context: Updating Configuration via a ConfigMap | Create a new immutable ConfigMap by using the manifest shown below:


Prompt:
Explain this text code:

Found 3 pods, using pod/immutable-configmap-volume-78b6fbff95-5gsfh
Wed Mar 20 03:52:34 UTC 2024 The name of the company is ACME, Inc.
Wed Mar 20 03:52:44 UTC 2024 The name of the company is ACME, Inc.
Wed Mar 20 03:52:54 UTC 2024 The name of the company is ACME, Inc.

Response: This text code Updating Configuration via a ConfigMap | Create a new immutable ConfigMap by using the manifest shown below:


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  company_name: "Fiktivesunternehmen GmbH" # new fictional company name

Response:
kind: ConfigMap
immutable: true
metadata:
  name: company-name-20240312


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  company_name: "Fiktivesunternehmen GmbH" # new fictional company name
kind: ConfigMap
immutable: true
metadata:
  name: company-name-20240312

Response: This yaml code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/configmap/new-immutable-configmap.yaml

Response: This bash code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Explain this text code:

NAME                    DATA   AGE
company-name-20150801   1      22m
company-name-20240312   1      24s

Response: This text code Updating Configuration via a ConfigMap | Modify the Deployment to reference the new ConfigMap.

Context: Updating Configuration via a ConfigMap | Modify the Deployment to reference the new ConfigMap.


Prompt:
Complete this text code:

volumes:
- configMap:

Response:
    defaultMode: 420
    name: company-name-20240312 # Update this field
  name: config-volume

Context: Updating Configuration via a ConfigMap | You should see the following output:


Prompt:
Explain this text code:

volumes:
- configMap:
    defaultMode: 420
    name: company-name-20240312 # Update this field
  name: config-volume

Response: This text code Updating Configuration via a ConfigMap | You should see the following output:


Prompt:
Explain this bash code:

kubectl get pods --selector=app.kubernetes.io/name=immutable-configmap-volume

Response: This bash code Updating Configuration via a ConfigMap | You should eventually see an output similar to:

Context: Updating Configuration via a ConfigMap | You should eventually see an output similar to:


Prompt:
Complete this text code:

NAME                                          READY   STATUS        RESTARTS   AGE
immutable-configmap-volume-5fdb88fcc8-29v8n   1/1     Running       0          13s
immutable-configmap-volume-5fdb88fcc8-52ddd   1/1     Running       0          14s

Response:
immutable-configmap-volume-5fdb88fcc8-n5jx4   1/1     Running       0          15s
immutable-configmap-volume-78b6fbff95-5gsfh   1/1     Terminating   0          32m
immutable-configmap-volume-78b6fbff95-7vcj4   1/1     Terminating   0          32m
immutable-configmap-volume-78b6fbff95-vdslm   1/1     Terminating   0          32m


Prompt:
Explain this text code:

NAME                                          READY   STATUS        RESTARTS   AGE
immutable-configmap-volume-5fdb88fcc8-29v8n   1/1     Running       0          13s
immutable-configmap-volume-5fdb88fcc8-52ddd   1/1     Running       0          14s
immutable-configmap-volume-5fdb88fcc8-n5jx4   1/1     Running       0          15s
immutable-configmap-volume-78b6fbff95-5gsfh   1/1     Terminating   0          32m
immutable-configmap-volume-78b6fbff95-7vcj4   1/1     Terminating   0          32m
immutable-configmap-volume-78b6fbff95-vdslm   1/1     Terminating   0          32m

Response: This text code Updating Configuration via a ConfigMap | You should eventually see an output similar to:


Prompt:
Complete this text code:

NAME                                          READY   STATUS    RESTARTS   AGE
immutable-configmap-volume-5fdb88fcc8-29v8n   1/1     Running   0          43s

Response:
immutable-configmap-volume-5fdb88fcc8-52ddd   1/1     Running   0          44s
immutable-configmap-volume-5fdb88fcc8-n5jx4   1/1     Running   0          45s

Context: Updating Configuration via a ConfigMap | View the logs for a Pod in this Deployment:


Prompt:
Explain this text code:

NAME                                          READY   STATUS    RESTARTS   AGE
immutable-configmap-volume-5fdb88fcc8-29v8n   1/1     Running   0          43s
immutable-configmap-volume-5fdb88fcc8-52ddd   1/1     Running   0          44s
immutable-configmap-volume-5fdb88fcc8-n5jx4   1/1     Running   0          45s

Response: This text code Updating Configuration via a ConfigMap | View the logs for a Pod in this Deployment:


Prompt:
Explain this text code:

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployment/immutable-configmap-volume

Response: This text code Updating Configuration via a ConfigMap | You should see an output similar to the below:

Context: Updating Configuration via a ConfigMap | You should see an output similar to the below:


Prompt:
Complete this text code:

Found 3 pods, using pod/immutable-configmap-volume-5fdb88fcc8-n5jx4
Wed Mar 20 04:24:17 UTC 2024 The name of the company is Fiktivesunternehmen GmbH

Response:
Wed Mar 20 04:24:27 UTC 2024 The name of the company is Fiktivesunternehmen GmbH
Wed Mar 20 04:24:37 UTC 2024 The name of the company is Fiktivesunternehmen GmbH

Context: Updating Configuration via a ConfigMap | Once all the deployments have migrated to use the new immutable ConfigMap, it is advised to delete the old one.


Prompt:
Explain this text code:

Found 3 pods, using pod/immutable-configmap-volume-5fdb88fcc8-n5jx4
Wed Mar 20 04:24:17 UTC 2024 The name of the company is Fiktivesunternehmen GmbH
Wed Mar 20 04:24:27 UTC 2024 The name of the company is Fiktivesunternehmen GmbH
Wed Mar 20 04:24:37 UTC 2024 The name of the company is Fiktivesunternehmen GmbH

Response: This text code Updating Configuration via a ConfigMap | Once all the deployments have migrated to use the new immutable ConfigMap, it is advised to delete the old one.


Prompt:
Complete this bash code:

kubectl delete deployment configmap-volume configmap-env-var configmap-two-containers configmap-sidecar-container immutable-configmap-volume
kubectl delete service configmap-service configmap-sidecar-service

Response:
kubectl delete configmap sport fruits color company-name-20240312

kubectl delete configmap company-name-20150801 # In case it was not handled during the task execution

Context: Updating Configuration via a ConfigMap |


Prompt:
Explain this bash code:

kubectl delete deployment configmap-volume configmap-env-var configmap-two-containers configmap-sidecar-container immutable-configmap-volume
kubectl delete service configmap-service configmap-sidecar-service
kubectl delete configmap sport fruits color company-name-20240312

kubectl delete configmap company-name-20150801 # In case it was not handled during the task execution

Response: This bash code Updating Configuration via a ConfigMap |


Prompt:
Explain this shell code:

kubectl create configmap sport --from-literal=sport=football

Response: This shell code Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with the ConfigMap sport mounted as a volume into the Pod's only container.

Context: Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with the ConfigMap sport mounted as a volume into the Pod's only container.


Prompt:
Explain this text code:

deployments/deployment-with-configmap-as-volume.yaml

Response: This text code Updating Configuration via a ConfigMap | Create the Deployment:

Context: Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-volume
  labels:
    app.kubernetes.io/name: configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-volume
    spec:

Response:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred sport is $(cat /etc/config/sport)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: sport


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-volume
  labels:
    app.kubernetes.io/name: configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-volume
    spec:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred sport is $(cat /etc/config/sport)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: sport

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this shell code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-as-volume.yaml

Response: This shell code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):

Context: Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this shell code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-volume

Response: This shell code Updating Configuration via a ConfigMap | You should see an output similar to:

Context: Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

NAME                                READY   STATUS    RESTARTS   AGE
configmap-volume-6b976dfdcf-qxvbm   1/1     Running   0          72s

Response:
configmap-volume-6b976dfdcf-skpvm   1/1     Running   0          72s
configmap-volume-6b976dfdcf-tbc6r   1/1     Running   0          72s

Context: Updating Configuration via a ConfigMap | On each node where one of these Pods is running, the kubelet fetches the data for that ConfigMap and translates it to files in a local volume. The kubelet then mounts that volume into the container, a


Prompt:
Explain this text code:

NAME                                READY   STATUS    RESTARTS   AGE
configmap-volume-6b976dfdcf-qxvbm   1/1     Running   0          72s
configmap-volume-6b976dfdcf-skpvm   1/1     Running   0          72s
configmap-volume-6b976dfdcf-tbc6r   1/1     Running   0          72s

Response: This text code Updating Configuration via a ConfigMap | On each node where one of these Pods is running, the kubelet fetches the data for that ConfigMap and translates it to files in a local volume. The kubelet then mounts that volume into the container, a


Prompt:
Explain this shell code:

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployments/configmap-volume

Response: This shell code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

Found 3 pods, using pod/configmap-volume-76d9c5678f-x5rgj
Thu Jan  4 14:06:46 UTC 2024 My preferred sport is football
Thu Jan  4 14:06:56 UTC 2024 My preferred sport is football

Response:
Thu Jan  4 14:07:06 UTC 2024 My preferred sport is football
Thu Jan  4 14:07:16 UTC 2024 My preferred sport is football
Thu Jan  4 14:07:26 UTC 2024 My preferred sport is football

Context: Updating Configuration via a ConfigMap | Edit the ConfigMap:


Prompt:
Explain this text code:

Found 3 pods, using pod/configmap-volume-76d9c5678f-x5rgj
Thu Jan  4 14:06:46 UTC 2024 My preferred sport is football
Thu Jan  4 14:06:56 UTC 2024 My preferred sport is football
Thu Jan  4 14:07:06 UTC 2024 My preferred sport is football
Thu Jan  4 14:07:16 UTC 2024 My preferred sport is football
Thu Jan  4 14:07:26 UTC 2024 My preferred sport is football

Response: This text code Updating Configuration via a ConfigMap | Edit the ConfigMap:


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  sport: cricket
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.

Response:
metadata:
  creationTimestamp: "2024-01-04T14:05:06Z"
  name: sport
  namespace: default
  resourceVersion: "1743935"
  uid: 024ee001-fe72-487e-872e-34d6464a8a23


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  sport: cricket
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-04T14:05:06Z"
  name: sport
  namespace: default
  resourceVersion: "1743935"
  uid: 024ee001-fe72-487e-872e-34d6464a8a23

Response: This yaml code Updating Configuration via a ConfigMap | You should see the following output:


Prompt:
Complete this text code:

Thu Jan  4 14:11:36 UTC 2024 My preferred sport is football
Thu Jan  4 14:11:46 UTC 2024 My preferred sport is football

Response:
Thu Jan  4 14:11:56 UTC 2024 My preferred sport is football
Thu Jan  4 14:12:06 UTC 2024 My preferred sport is cricket
Thu Jan  4 14:12:16 UTC 2024 My preferred sport is cricket

Context: Updating Configuration via a ConfigMap | When you have a ConfigMap that is mapped into a running Pod using either a configMap volume or a projected volume, and you update that ConfigMap, the running Pod sees the update almost immediately.How


Prompt:
Explain this text code:

Thu Jan  4 14:11:36 UTC 2024 My preferred sport is football
Thu Jan  4 14:11:46 UTC 2024 My preferred sport is football
Thu Jan  4 14:11:56 UTC 2024 My preferred sport is football
Thu Jan  4 14:12:06 UTC 2024 My preferred sport is cricket
Thu Jan  4 14:12:16 UTC 2024 My preferred sport is cricket

Response: This text code Updating Configuration via a ConfigMap | When you have a ConfigMap that is mapped into a running Pod using either a configMap volume or a projected volume, and you update that ConfigMap, the running Pod sees the update almost immediately.How


Prompt:
Explain this shell code:

kubectl create configmap fruits --from-literal=fruits=apples

Response: This shell code Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with an environment variable configured via the ConfigMap fruits.

Context: Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with an environment variable configured via the ConfigMap fruits.


Prompt:
Explain this text code:

deployments/deployment-with-configmap-as-envvar.yaml

Response: This text code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-env-var
  labels:
    app.kubernetes.io/name: configmap-env-var
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-env-var
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-env-var
    spec:

Response:
      containers:
        - name: alpine
          image: alpine:3
          env:
            - name: FRUITS
              valueFrom:
                configMapKeyRef:
                  key: fruits
                  name: fruits
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The basket is full of $FRUITS";
                sleep 10; done;
          ports:
            - containerPort: 80


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-env-var
  labels:
    app.kubernetes.io/name: configmap-env-var
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-env-var
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-env-var
    spec:
      containers:
        - name: alpine
          image: alpine:3
          env:
            - name: FRUITS
              valueFrom:
                configMapKeyRef:
                  key: fruits
                  name: fruits
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The basket is full of $FRUITS";
                sleep 10; done;
          ports:
            - containerPort: 80

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this shell code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-as-envvar.yaml

Response: This shell code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this shell code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-env-var

Response: This shell code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

NAME                                 READY   STATUS    RESTARTS   AGE
configmap-env-var-59cfc64f7d-74d7z   1/1     Running   0          46s

Response:
configmap-env-var-59cfc64f7d-c4wmj   1/1     Running   0          46s
configmap-env-var-59cfc64f7d-dpr98   1/1     Running   0          46s

Context: Updating Configuration via a ConfigMap | The key-value pair in the ConfigMap is configured as an environment variable in the container of the Pod. Check this by viewing the logs of one Pod that belongs to the Deployment.


Prompt:
Explain this text code:

NAME                                 READY   STATUS    RESTARTS   AGE
configmap-env-var-59cfc64f7d-74d7z   1/1     Running   0          46s
configmap-env-var-59cfc64f7d-c4wmj   1/1     Running   0          46s
configmap-env-var-59cfc64f7d-dpr98   1/1     Running   0          46s

Response: This text code Updating Configuration via a ConfigMap | The key-value pair in the ConfigMap is configured as an environment variable in the container of the Pod. Check this by viewing the logs of one Pod that belongs to the Deployment.


Prompt:
Complete this text code:

Found 3 pods, using pod/configmap-env-var-7c994f7769-l74nq
Thu Jan  4 16:07:06 UTC 2024 The basket is full of apples

Response:
Thu Jan  4 16:07:16 UTC 2024 The basket is full of apples
Thu Jan  4 16:07:26 UTC 2024 The basket is full of apples


Prompt:
Explain this text code:

Found 3 pods, using pod/configmap-env-var-7c994f7769-l74nq
Thu Jan  4 16:07:06 UTC 2024 The basket is full of apples
Thu Jan  4 16:07:16 UTC 2024 The basket is full of apples
Thu Jan  4 16:07:26 UTC 2024 The basket is full of apples

Response: This text code Updating Configuration via a ConfigMap | Edit the ConfigMap:


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  fruits: mangoes
kind: ConfigMap
# You can leave the existing metadata as they are.

Response:
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-04T16:04:19Z"
  name: fruits
  namespace: default
  resourceVersion: "1749472"


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  fruits: mangoes
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-04T16:04:19Z"
  name: fruits
  namespace: default
  resourceVersion: "1749472"

Response: This yaml code Updating Configuration via a ConfigMap | You should see the following output:


Prompt:
Explain this shell code:

# As the text explains, the output does NOT change
kubectl logs deployments/configmap-env-var --follow

Response: This shell code Updating Configuration via a ConfigMap | Notice that the output remains unchanged, even though you edited the ConfigMap:

Context: Updating Configuration via a ConfigMap | Notice that the output remains unchanged, even though you edited the ConfigMap:


Prompt:
Complete this text code:

Thu Jan  4 16:12:56 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:06 UTC 2024 The basket is full of apples

Response:
Thu Jan  4 16:13:16 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:26 UTC 2024 The basket is full of apples

Context: Updating Configuration via a ConfigMap | You can trigger that replacement. Perform a rollout for the Deployment, using kubectl rollout:


Prompt:
Explain this text code:

Thu Jan  4 16:12:56 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:06 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:16 UTC 2024 The basket is full of apples
Thu Jan  4 16:13:26 UTC 2024 The basket is full of apples

Response: This text code Updating Configuration via a ConfigMap | You can trigger that replacement. Perform a rollout for the Deployment, using kubectl rollout:


Prompt:
Complete this shell code:

# Trigger the rollout
kubectl rollout restart deployment configmap-env-var

Response:
# Wait for the rollout to complete
kubectl rollout status deployment configmap-env-var --watch=true

Context: Updating Configuration via a ConfigMap | Next, check the Deployment:


Prompt:
Explain this shell code:

# Trigger the rollout
kubectl rollout restart deployment configmap-env-var

# Wait for the rollout to complete
kubectl rollout status deployment configmap-env-var --watch=true

Response: This shell code Updating Configuration via a ConfigMap | Next, check the Deployment:


Prompt:
Explain this text code:

NAME                READY   UP-TO-DATE   AVAILABLE   AGE
configmap-env-var   3/3     3            3           12m

Response: This text code Updating Configuration via a ConfigMap | Check the Pods:

Context: Updating Configuration via a ConfigMap | Check the Pods:


Prompt:
Explain this shell code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-env-var

Response: This shell code Updating Configuration via a ConfigMap | The rollout causes Kubernetes to make a new ReplicaSet for the Deployment; that means the existing Pods eventually terminate, and new ones are created. After few seconds, you should see an output simi

Context: Updating Configuration via a ConfigMap | The rollout causes Kubernetes to make a new ReplicaSet for the Deployment; that means the existing Pods eventually terminate, and new ones are created. After few seconds, you should see an output simi


Prompt:
Complete this text code:

NAME                                 READY   STATUS        RESTARTS   AGE
configmap-env-var-6d94d89bf5-2ph2l   1/1     Running       0          13s

Response:
configmap-env-var-6d94d89bf5-74twx   1/1     Running       0          8s
configmap-env-var-6d94d89bf5-d5vx8   1/1     Running       0          11s

Context: Updating Configuration via a ConfigMap | View the logs for a Pod in this Deployment:


Prompt:
Explain this text code:

NAME                                 READY   STATUS        RESTARTS   AGE
configmap-env-var-6d94d89bf5-2ph2l   1/1     Running       0          13s
configmap-env-var-6d94d89bf5-74twx   1/1     Running       0          8s
configmap-env-var-6d94d89bf5-d5vx8   1/1     Running       0          11s

Response: This text code Updating Configuration via a ConfigMap | View the logs for a Pod in this Deployment:


Prompt:
Explain this shell code:

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployment/configmap-env-var

Response: This shell code Updating Configuration via a ConfigMap | You should see an output similar to the below:

Context: Updating Configuration via a ConfigMap | You should see an output similar to the below:


Prompt:
Complete this text code:

Found 3 pods, using pod/configmap-env-var-6d9ff89fb6-bzcf6
Thu Jan  4 16:30:35 UTC 2024 The basket is full of mangoes

Response:
Thu Jan  4 16:30:45 UTC 2024 The basket is full of mangoes
Thu Jan  4 16:30:55 UTC 2024 The basket is full of mangoes

Context: Updating Configuration via a ConfigMap | This demonstrates the scenario of updating environment variables in a Pod that are derived from a ConfigMap. Changes to the ConfigMap values are applied to the Pod during the subsequent rollout. If Po


Prompt:
Explain this text code:

Found 3 pods, using pod/configmap-env-var-6d9ff89fb6-bzcf6
Thu Jan  4 16:30:35 UTC 2024 The basket is full of mangoes
Thu Jan  4 16:30:45 UTC 2024 The basket is full of mangoes
Thu Jan  4 16:30:55 UTC 2024 The basket is full of mangoes

Response: This text code Updating Configuration via a ConfigMap | This demonstrates the scenario of updating environment variables in a Pod that are derived from a ConfigMap. Changes to the ConfigMap values are applied to the Pod during the subsequent rollout. If Po


Prompt:
Explain this shell code:

kubectl create configmap color --from-literal=color=red

Response: This shell code Updating Configuration via a ConfigMap | Below is an example manifest for a Deployment that manages a set of Pods, each with two containers. The two containers share an emptyDir volume that they use to communicate. The first container runs a

Context: Updating Configuration via a ConfigMap | Below is an example manifest for a Deployment that manages a set of Pods, each with two containers. The two containers share an emptyDir volume that they use to communicate. The first container runs a


Prompt:
Explain this text code:

deployments/deployment-with-configmap-two-containers.yaml

Response: This text code Updating Configuration via a ConfigMap | Create the Deployment:

Context: Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-two-containers
  labels:
    app.kubernetes.io/name: configmap-two-containers
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-two-containers
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-two-containers
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume

Response:
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
        - name: alpine
          image: alpine:3
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-two-containers
  labels:
    app.kubernetes.io/name: configmap-two-containers
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-two-containers
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-two-containers
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
        - name: alpine
          image: alpine:3
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this shell code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-two-containers.yaml

Response: This shell code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):

Context: Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this shell code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-two-containers

Response: This shell code Updating Configuration via a ConfigMap | You should see an output similar to:

Context: Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

NAME                                        READY   STATUS    RESTARTS   AGE
configmap-two-containers-565fb6d4f4-2xhxf   2/2     Running   0          20s

Response:
configmap-two-containers-565fb6d4f4-g5v4j   2/2     Running   0          20s
configmap-two-containers-565fb6d4f4-mzsmf   2/2     Running   0          20s

Context: Updating Configuration via a ConfigMap | Expose the Deployment (the kubectl tool creates a Service for you):


Prompt:
Explain this text code:

NAME                                        READY   STATUS    RESTARTS   AGE
configmap-two-containers-565fb6d4f4-2xhxf   2/2     Running   0          20s
configmap-two-containers-565fb6d4f4-g5v4j   2/2     Running   0          20s
configmap-two-containers-565fb6d4f4-mzsmf   2/2     Running   0          20s

Response: This text code Updating Configuration via a ConfigMap | Expose the Deployment (the kubectl tool creates a Service for you):


Prompt:
Explain this shell code:

kubectl expose deployment configmap-two-containers --name=configmap-service --port=8080 --target-port=80

Response: This shell code Updating Configuration via a ConfigMap | Use kubectl to forward the port:

Context: Updating Configuration via a ConfigMap | Use kubectl to forward the port:


Prompt:
Explain this shell code:

# this stays running in the background
kubectl port-forward service/configmap-service 8080:8080 &

Response: This shell code Updating Configuration via a ConfigMap | Access the service.

Context: Updating Configuration via a ConfigMap | Access the service.


Prompt:
Explain this text code:

Fri Jan  5 08:08:22 UTC 2024 My preferred color is red

Response: This text code Updating Configuration via a ConfigMap | Edit the ConfigMap:

Context: Updating Configuration via a ConfigMap | Edit the ConfigMap:


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  color: blue
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.

Response:
metadata:
  creationTimestamp: "2024-01-05T08:12:05Z"
  name: color
  namespace: configmap
  resourceVersion: "1801272"
  uid: 80d33e4a-cbb4-4bc9-ba8c-544c68e425d6

Context: Updating Configuration via a ConfigMap | Loop over the service URL for few seconds.


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  color: blue
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-05T08:12:05Z"
  name: color
  namespace: configmap
  resourceVersion: "1801272"
  uid: 80d33e4a-cbb4-4bc9-ba8c-544c68e425d6

Response: This yaml code Updating Configuration via a ConfigMap | Loop over the service URL for few seconds.


Prompt:
Explain this shell code:

# Cancel this when you're happy with it (Ctrl-C)
while true; do curl --connect-timeout 7.5 http://localhost:8080; sleep 10; done

Response: This shell code Updating Configuration via a ConfigMap | You should see the output change as follows:

Context: Updating Configuration via a ConfigMap | You should see the output change as follows:


Prompt:
Complete this text code:

Fri Jan  5 08:14:00 UTC 2024 My preferred color is red
Fri Jan  5 08:14:02 UTC 2024 My preferred color is red
Fri Jan  5 08:14:20 UTC 2024 My preferred color is red

Response:
Fri Jan  5 08:14:22 UTC 2024 My preferred color is red
Fri Jan  5 08:14:32 UTC 2024 My preferred color is blue
Fri Jan  5 08:14:43 UTC 2024 My preferred color is blue
Fri Jan  5 08:15:00 UTC 2024 My preferred color is blue

Context: Updating Configuration via a ConfigMap | The above scenario can be replicated by using a Sidecar Container as a helper container to write the HTML file.As a Sidecar Container is conceptually an Init Container, it is guaranteed to start befor


Prompt:
Explain this text code:

Fri Jan  5 08:14:00 UTC 2024 My preferred color is red
Fri Jan  5 08:14:02 UTC 2024 My preferred color is red
Fri Jan  5 08:14:20 UTC 2024 My preferred color is red
Fri Jan  5 08:14:22 UTC 2024 My preferred color is red
Fri Jan  5 08:14:32 UTC 2024 My preferred color is blue
Fri Jan  5 08:14:43 UTC 2024 My preferred color is blue
Fri Jan  5 08:15:00 UTC 2024 My preferred color is blue

Response: This text code Updating Configuration via a ConfigMap | The above scenario can be replicated by using a Sidecar Container as a helper container to write the HTML file.As a Sidecar Container is conceptually an Init Container, it is guaranteed to start befor


Prompt:
Explain this shell code:

kubectl create configmap color --from-literal=color=blue

Response: This shell code Updating Configuration via a ConfigMap | Below is an example manifest for a Deployment that manages a set of Pods, each with a main container and a sidecar container. The two containers share an emptyDir volume that they use to communicate.

Context: Updating Configuration via a ConfigMap | Below is an example manifest for a Deployment that manages a set of Pods, each with a main container and a sidecar container. The two containers share an emptyDir volume that they use to communicate.


Prompt:
Explain this text code:

deployments/deployment-with-configmap-and-sidecar-container.yaml

Response: This text code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-sidecar-container
  labels:
    app.kubernetes.io/name: configmap-sidecar-container
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-sidecar-container
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-sidecar-container
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume
          configMap:

Response:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
      initContainers:
        - name: alpine
          image: alpine:3
          restartPolicy: Always
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-sidecar-container
  labels:
    app.kubernetes.io/name: configmap-sidecar-container
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-sidecar-container
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-sidecar-container
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
      initContainers:
        - name: alpine
          image: alpine:3
          restartPolicy: Always
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this shell code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-and-sidecar-container.yaml

Response: This shell code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this shell code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-sidecar-container

Response: This shell code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

NAME                                           READY   STATUS    RESTARTS   AGE
configmap-sidecar-container-5fb59f558b-87rp7   2/2     Running   0          94s

Response:
configmap-sidecar-container-5fb59f558b-ccs7s   2/2     Running   0          94s
configmap-sidecar-container-5fb59f558b-wnmgk   2/2     Running   0          94s


Prompt:
Explain this text code:

NAME                                           READY   STATUS    RESTARTS   AGE
configmap-sidecar-container-5fb59f558b-87rp7   2/2     Running   0          94s
configmap-sidecar-container-5fb59f558b-ccs7s   2/2     Running   0          94s
configmap-sidecar-container-5fb59f558b-wnmgk   2/2     Running   0          94s

Response: This text code Updating Configuration via a ConfigMap | Expose the Deployment (the kubectl tool creates a Service for you):


Prompt:
Explain this shell code:

kubectl expose deployment configmap-sidecar-container --name=configmap-sidecar-service --port=8081 --target-port=80

Response: This shell code Updating Configuration via a ConfigMap | Use kubectl to forward the port:


Prompt:
Explain this shell code:

# this stays running in the background
kubectl port-forward service/configmap-sidecar-service 8081:8081 &

Response: This shell code Updating Configuration via a ConfigMap | Access the service.


Prompt:
Explain this text code:

Sat Feb 17 13:09:05 UTC 2024 My preferred color is blue

Response: This text code Updating Configuration via a ConfigMap | Edit the ConfigMap:


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  color: green
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.

Response:
metadata:
  creationTimestamp: "2024-02-17T12:20:30Z"
  name: color
  namespace: default
  resourceVersion: "1054"
  uid: e40bb34c-58df-4280-8bea-6ed16edccfaa


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  color: green
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-02-17T12:20:30Z"
  name: color
  namespace: default
  resourceVersion: "1054"
  uid: e40bb34c-58df-4280-8bea-6ed16edccfaa

Response: This yaml code Updating Configuration via a ConfigMap | Loop over the service URL for few seconds.


Prompt:
Explain this shell code:

# Cancel this when you're happy with it (Ctrl-C)
while true; do curl --connect-timeout 7.5 http://localhost:8081; sleep 10; done

Response: This shell code Updating Configuration via a ConfigMap | You should see the output change as follows:


Prompt:
Complete this text code:

Sat Feb 17 13:12:35 UTC 2024 My preferred color is blue
Sat Feb 17 13:12:45 UTC 2024 My preferred color is blue
Sat Feb 17 13:12:55 UTC 2024 My preferred color is blue

Response:
Sat Feb 17 13:13:05 UTC 2024 My preferred color is blue
Sat Feb 17 13:13:15 UTC 2024 My preferred color is green
Sat Feb 17 13:13:25 UTC 2024 My preferred color is green
Sat Feb 17 13:13:35 UTC 2024 My preferred color is green

Context: Updating Configuration via a ConfigMap | Immutable ConfigMaps are especially used for configuration that is constant and is not expected to change over time. Marking a ConfigMap as immutable allows a performance improvement where the kubelet


Prompt:
Explain this text code:

Sat Feb 17 13:12:35 UTC 2024 My preferred color is blue
Sat Feb 17 13:12:45 UTC 2024 My preferred color is blue
Sat Feb 17 13:12:55 UTC 2024 My preferred color is blue
Sat Feb 17 13:13:05 UTC 2024 My preferred color is blue
Sat Feb 17 13:13:15 UTC 2024 My preferred color is green
Sat Feb 17 13:13:25 UTC 2024 My preferred color is green
Sat Feb 17 13:13:35 UTC 2024 My preferred color is green

Response: This text code Updating Configuration via a ConfigMap | Immutable ConfigMaps are especially used for configuration that is constant and is not expected to change over time. Marking a ConfigMap as immutable allows a performance improvement where the kubelet


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  company_name: "ACME, Inc." # existing fictional company name

Response:
kind: ConfigMap
immutable: true
metadata:
  name: company-name-20150801

Context: Updating Configuration via a ConfigMap | Create the Immutable ConfigMap:


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  company_name: "ACME, Inc." # existing fictional company name
kind: ConfigMap
immutable: true
metadata:
  name: company-name-20150801

Response: This yaml code Updating Configuration via a ConfigMap | Create the Immutable ConfigMap:


Prompt:
Explain this shell code:

kubectl apply -f https://k8s.io/examples/configmap/immutable-configmap.yaml

Response: This shell code Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with the Immutable ConfigMap company-name-20150801 mounted as a volume into the Pod's only container.

Context: Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with the Immutable ConfigMap company-name-20150801 mounted as a volume into the Pod's only container.


Prompt:
Explain this text code:

deployments/deployment-with-immutable-configmap-as-volume.yaml

Response: This text code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: immutable-configmap-volume
  labels:
    app.kubernetes.io/name: immutable-configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: immutable-configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: immutable-configmap-volume
    spec:

Response:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The name of the company is $(cat /etc/config/company_name)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: company-name-20150801


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: immutable-configmap-volume
  labels:
    app.kubernetes.io/name: immutable-configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: immutable-configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: immutable-configmap-volume
    spec:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The name of the company is $(cat /etc/config/company_name)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: company-name-20150801

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this shell code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-immutable-configmap-as-volume.yaml

Response: This shell code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this shell code:

kubectl get pods --selector=app.kubernetes.io/name=immutable-configmap-volume

Response: This shell code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

NAME                                          READY   STATUS    RESTARTS   AGE
immutable-configmap-volume-78b6fbff95-5gsfh   1/1     Running   0          62s

Response:
immutable-configmap-volume-78b6fbff95-7vcj4   1/1     Running   0          62s
immutable-configmap-volume-78b6fbff95-vdslm   1/1     Running   0          62s

Context: Updating Configuration via a ConfigMap | The Pod's container refers to the data defined in the ConfigMap and uses it to print a report to stdout. You can check this report by viewing the logs for one of the Pods in that Deployment:


Prompt:
Explain this text code:

NAME                                          READY   STATUS    RESTARTS   AGE
immutable-configmap-volume-78b6fbff95-5gsfh   1/1     Running   0          62s
immutable-configmap-volume-78b6fbff95-7vcj4   1/1     Running   0          62s
immutable-configmap-volume-78b6fbff95-vdslm   1/1     Running   0          62s

Response: This text code Updating Configuration via a ConfigMap | The Pod's container refers to the data defined in the ConfigMap and uses it to print a report to stdout. You can check this report by viewing the logs for one of the Pods in that Deployment:


Prompt:
Explain this shell code:

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployments/immutable-configmap-volume

Response: This shell code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

Found 3 pods, using pod/immutable-configmap-volume-78b6fbff95-5gsfh
Wed Mar 20 03:52:34 UTC 2024 The name of the company is ACME, Inc.

Response:
Wed Mar 20 03:52:44 UTC 2024 The name of the company is ACME, Inc.
Wed Mar 20 03:52:54 UTC 2024 The name of the company is ACME, Inc.

Context: Updating Configuration via a ConfigMap | Create a new immutable ConfigMap by using the manifest shown below:


Prompt:
Explain this text code:

Found 3 pods, using pod/immutable-configmap-volume-78b6fbff95-5gsfh
Wed Mar 20 03:52:34 UTC 2024 The name of the company is ACME, Inc.
Wed Mar 20 03:52:44 UTC 2024 The name of the company is ACME, Inc.
Wed Mar 20 03:52:54 UTC 2024 The name of the company is ACME, Inc.

Response: This text code Updating Configuration via a ConfigMap | Create a new immutable ConfigMap by using the manifest shown below:


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  company_name: "Fiktivesunternehmen GmbH" # new fictional company name

Response:
kind: ConfigMap
immutable: true
metadata:
  name: company-name-20240312


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  company_name: "Fiktivesunternehmen GmbH" # new fictional company name
kind: ConfigMap
immutable: true
metadata:
  name: company-name-20240312

Response: This yaml code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Explain this shell code:

kubectl apply -f https://k8s.io/examples/configmap/new-immutable-configmap.yaml

Response: This shell code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Explain this text code:

NAME                    DATA   AGE
company-name-20150801   1      22m
company-name-20240312   1      24s

Response: This text code Updating Configuration via a ConfigMap | Modify the Deployment to reference the new ConfigMap.

Context: Updating Configuration via a ConfigMap | Modify the Deployment to reference the new ConfigMap.


Prompt:
Complete this yaml code:

volumes:
- configMap:

Response:
    defaultMode: 420
    name: company-name-20240312 # Update this field
  name: config-volume

Context: Updating Configuration via a ConfigMap | You should see the following output:


Prompt:
Explain this yaml code:

volumes:
- configMap:
    defaultMode: 420
    name: company-name-20240312 # Update this field
  name: config-volume

Response: This yaml code Updating Configuration via a ConfigMap | You should see the following output:


Prompt:
Explain this shell code:

kubectl get pods --selector=app.kubernetes.io/name=immutable-configmap-volume

Response: This shell code Updating Configuration via a ConfigMap | You should eventually see an output similar to:

Context: Updating Configuration via a ConfigMap | You should eventually see an output similar to:


Prompt:
Complete this text code:

NAME                                          READY   STATUS        RESTARTS   AGE
immutable-configmap-volume-5fdb88fcc8-29v8n   1/1     Running       0          13s
immutable-configmap-volume-5fdb88fcc8-52ddd   1/1     Running       0          14s

Response:
immutable-configmap-volume-5fdb88fcc8-n5jx4   1/1     Running       0          15s
immutable-configmap-volume-78b6fbff95-5gsfh   1/1     Terminating   0          32m
immutable-configmap-volume-78b6fbff95-7vcj4   1/1     Terminating   0          32m
immutable-configmap-volume-78b6fbff95-vdslm   1/1     Terminating   0          32m


Prompt:
Explain this text code:

NAME                                          READY   STATUS        RESTARTS   AGE
immutable-configmap-volume-5fdb88fcc8-29v8n   1/1     Running       0          13s
immutable-configmap-volume-5fdb88fcc8-52ddd   1/1     Running       0          14s
immutable-configmap-volume-5fdb88fcc8-n5jx4   1/1     Running       0          15s
immutable-configmap-volume-78b6fbff95-5gsfh   1/1     Terminating   0          32m
immutable-configmap-volume-78b6fbff95-7vcj4   1/1     Terminating   0          32m
immutable-configmap-volume-78b6fbff95-vdslm   1/1     Terminating   0          32m

Response: This text code Updating Configuration via a ConfigMap | You should eventually see an output similar to:


Prompt:
Complete this text code:

NAME                                          READY   STATUS    RESTARTS   AGE
immutable-configmap-volume-5fdb88fcc8-29v8n   1/1     Running   0          43s

Response:
immutable-configmap-volume-5fdb88fcc8-52ddd   1/1     Running   0          44s
immutable-configmap-volume-5fdb88fcc8-n5jx4   1/1     Running   0          45s

Context: Updating Configuration via a ConfigMap | View the logs for a Pod in this Deployment:


Prompt:
Explain this text code:

NAME                                          READY   STATUS    RESTARTS   AGE
immutable-configmap-volume-5fdb88fcc8-29v8n   1/1     Running   0          43s
immutable-configmap-volume-5fdb88fcc8-52ddd   1/1     Running   0          44s
immutable-configmap-volume-5fdb88fcc8-n5jx4   1/1     Running   0          45s

Response: This text code Updating Configuration via a ConfigMap | View the logs for a Pod in this Deployment:


Prompt:
Explain this shell code:

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployment/immutable-configmap-volume

Response: This shell code Updating Configuration via a ConfigMap | You should see an output similar to the below:

Context: Updating Configuration via a ConfigMap | You should see an output similar to the below:


Prompt:
Complete this text code:

Found 3 pods, using pod/immutable-configmap-volume-5fdb88fcc8-n5jx4
Wed Mar 20 04:24:17 UTC 2024 The name of the company is Fiktivesunternehmen GmbH

Response:
Wed Mar 20 04:24:27 UTC 2024 The name of the company is Fiktivesunternehmen GmbH
Wed Mar 20 04:24:37 UTC 2024 The name of the company is Fiktivesunternehmen GmbH

Context: Updating Configuration via a ConfigMap | Once all the deployments have migrated to use the new immutable ConfigMap, it is advised to delete the old one.


Prompt:
Explain this text code:

Found 3 pods, using pod/immutable-configmap-volume-5fdb88fcc8-n5jx4
Wed Mar 20 04:24:17 UTC 2024 The name of the company is Fiktivesunternehmen GmbH
Wed Mar 20 04:24:27 UTC 2024 The name of the company is Fiktivesunternehmen GmbH
Wed Mar 20 04:24:37 UTC 2024 The name of the company is Fiktivesunternehmen GmbH

Response: This text code Updating Configuration via a ConfigMap | Once all the deployments have migrated to use the new immutable ConfigMap, it is advised to delete the old one.


Prompt:
Complete this shell code:

kubectl delete deployment configmap-volume configmap-env-var configmap-two-containers configmap-sidecar-container immutable-configmap-volume
kubectl delete service configmap-service configmap-sidecar-service

Response:
kubectl delete configmap sport fruits color company-name-20240312

kubectl delete configmap company-name-20150801 # In case it was not handled during the task execution

Context: Updating Configuration via a ConfigMap |


Prompt:
Explain this shell code:

kubectl delete deployment configmap-volume configmap-env-var configmap-two-containers configmap-sidecar-container immutable-configmap-volume
kubectl delete service configmap-service configmap-sidecar-service
kubectl delete configmap sport fruits color company-name-20240312

kubectl delete configmap company-name-20150801 # In case it was not handled during the task execution

Response: This shell code Updating Configuration via a ConfigMap |


Prompt:
Explain this bash code:

kubectl create configmap sport --from-literal=sport=football

Response: This bash code Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with the ConfigMap sport mounted as a volume into the Pod's only container.

Context: Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with the ConfigMap sport mounted as a volume into the Pod's only container.


Prompt:
Complete this yaml code:

deployments/deployment-with-configmap-as-volume.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-volume
  labels:
    app.kubernetes.io/name: configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-volume
    spec:

Response:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred sport is $(cat /etc/config/sport)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: sport

Context: Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this yaml code:

deployments/deployment-with-configmap-as-volume.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-volume
  labels:
    app.kubernetes.io/name: configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-volume
    spec:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred sport is $(cat /etc/config/sport)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: sport

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-volume
  labels:
    app.kubernetes.io/name: configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-volume
    spec:

Response:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred sport is $(cat /etc/config/sport)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: sport


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-volume
  labels:
    app.kubernetes.io/name: configmap-volume
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-volume
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-volume
    spec:
      containers:
        - name: alpine
          image: alpine:3
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred sport is $(cat /etc/config/sport)";
              sleep 10; done;
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
      volumes:
        - name: config-volume
          configMap:
            name: sport

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-as-volume.yaml

Response: This bash code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):

Context: Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this bash code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-volume

Response: This bash code Updating Configuration via a ConfigMap | You should see an output similar to:

Context: Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Explain this text code:

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployments/configmap-volume

Response: This text code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  sport: cricket
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.

Response:
metadata:
  creationTimestamp: "2024-01-04T14:05:06Z"
  name: sport
  namespace: default
  resourceVersion: "1743935"
  uid: 024ee001-fe72-487e-872e-34d6464a8a23


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  sport: cricket
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-04T14:05:06Z"
  name: sport
  namespace: default
  resourceVersion: "1743935"
  uid: 024ee001-fe72-487e-872e-34d6464a8a23

Response: This yaml code Updating Configuration via a ConfigMap | You should see the following output:


Prompt:
Explain this bash code:

kubectl create configmap fruits --from-literal=fruits=apples

Response: This bash code Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with an environment variable configured via the ConfigMap fruits.

Context: Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with an environment variable configured via the ConfigMap fruits.


Prompt:
Complete this yaml code:

deployments/deployment-with-configmap-as-envvar.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-env-var
  labels:
    app.kubernetes.io/name: configmap-env-var
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-env-var
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-env-var

Response:
    spec:
      containers:
        - name: alpine
          image: alpine:3
          env:
            - name: FRUITS
              valueFrom:
                configMapKeyRef:
                  key: fruits
                  name: fruits
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The basket is full of $FRUITS";
                sleep 10; done;
          ports:
            - containerPort: 80


Prompt:
Explain this yaml code:

deployments/deployment-with-configmap-as-envvar.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-env-var
  labels:
    app.kubernetes.io/name: configmap-env-var
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-env-var
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-env-var
    spec:
      containers:
        - name: alpine
          image: alpine:3
          env:
            - name: FRUITS
              valueFrom:
                configMapKeyRef:
                  key: fruits
                  name: fruits
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The basket is full of $FRUITS";
                sleep 10; done;
          ports:
            - containerPort: 80

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-env-var
  labels:
    app.kubernetes.io/name: configmap-env-var
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-env-var
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-env-var
    spec:

Response:
      containers:
        - name: alpine
          image: alpine:3
          env:
            - name: FRUITS
              valueFrom:
                configMapKeyRef:
                  key: fruits
                  name: fruits
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The basket is full of $FRUITS";
                sleep 10; done;
          ports:
            - containerPort: 80


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-env-var
  labels:
    app.kubernetes.io/name: configmap-env-var
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-env-var
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-env-var
    spec:
      containers:
        - name: alpine
          image: alpine:3
          env:
            - name: FRUITS
              valueFrom:
                configMapKeyRef:
                  key: fruits
                  name: fruits
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) The basket is full of $FRUITS";
                sleep 10; done;
          ports:
            - containerPort: 80

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-as-envvar.yaml

Response: This bash code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this bash code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-env-var

Response: This bash code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this yaml code:

apiVersion: v1
data:
  fruits: mangoes
kind: ConfigMap
# You can leave the existing metadata as they are.

Response:
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-04T16:04:19Z"
  name: fruits
  namespace: default
  resourceVersion: "1749472"


Prompt:
Explain this yaml code:

apiVersion: v1
data:
  fruits: mangoes
kind: ConfigMap
# You can leave the existing metadata as they are.
# The values you'll see won't exactly match these.
metadata:
  creationTimestamp: "2024-01-04T16:04:19Z"
  name: fruits
  namespace: default
  resourceVersion: "1749472"

Response: This yaml code Updating Configuration via a ConfigMap | You should see the following output:


Prompt:
Explain this text code:

# As the text explains, the output does NOT change
kubectl logs deployments/configmap-env-var --follow

Response: This text code Updating Configuration via a ConfigMap | Notice that the output remains unchanged, even though you edited the ConfigMap:

Context: Updating Configuration via a ConfigMap | Notice that the output remains unchanged, even though you edited the ConfigMap:


Prompt:
Complete this text code:

# Trigger the rollout
kubectl rollout restart deployment configmap-env-var

Response:
# Wait for the rollout to complete
kubectl rollout status deployment configmap-env-var --watch=true

Context: Updating Configuration via a ConfigMap | Next, check the Deployment:


Prompt:
Explain this text code:

# Trigger the rollout
kubectl rollout restart deployment configmap-env-var

# Wait for the rollout to complete
kubectl rollout status deployment configmap-env-var --watch=true

Response: This text code Updating Configuration via a ConfigMap | Next, check the Deployment:


Prompt:
Explain this bash code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-env-var

Response: This bash code Updating Configuration via a ConfigMap | The rollout causes Kubernetes to make a new ReplicaSet for the Deployment; that means the existing Pods eventually terminate, and new ones are created. After few seconds, you should see an output simi

Context: Updating Configuration via a ConfigMap | The rollout causes Kubernetes to make a new ReplicaSet for the Deployment; that means the existing Pods eventually terminate, and new ones are created. After few seconds, you should see an output simi


Prompt:
Explain this text code:

# Pick one Pod that belongs to the Deployment, and view its logs
kubectl logs deployment/configmap-env-var

Response: This text code Updating Configuration via a ConfigMap | You should see an output similar to the below:


Prompt:
Explain this bash code:

kubectl create configmap color --from-literal=color=red

Response: This bash code Updating Configuration via a ConfigMap | Below is an example manifest for a Deployment that manages a set of Pods, each with two containers. The two containers share an emptyDir volume that they use to communicate. The first container runs a

Context: Updating Configuration via a ConfigMap | Below is an example manifest for a Deployment that manages a set of Pods, each with two containers. The two containers share an emptyDir volume that they use to communicate. The first container runs a


Prompt:
Complete this yaml code:

deployments/deployment-with-configmap-two-containers.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-two-containers
  labels:
    app.kubernetes.io/name: configmap-two-containers
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-two-containers
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-two-containers
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}

Response:
        - name: config-volume
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
        - name: alpine
          image: alpine:3
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;


Prompt:
Explain this yaml code:

deployments/deployment-with-configmap-two-containers.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-two-containers
  labels:
    app.kubernetes.io/name: configmap-two-containers
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-two-containers
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-two-containers
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
        - name: alpine
          image: alpine:3
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-two-containers
  labels:
    app.kubernetes.io/name: configmap-two-containers
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-two-containers
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-two-containers
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume

Response:
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
        - name: alpine
          image: alpine:3
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-two-containers
  labels:
    app.kubernetes.io/name: configmap-two-containers
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: configmap-two-containers
  template:
    metadata:
      labels:
        app.kubernetes.io/name: configmap-two-containers
    spec:
      volumes:
        - name: shared-data
          emptyDir: {}
        - name: config-volume
          configMap:
            name: color
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: shared-data
              mountPath: /usr/share/nginx/html
        - name: alpine
          image: alpine:3
          volumeMounts:
            - name: shared-data
              mountPath: /pod-data
            - name: config-volume
              mountPath: /etc/config
          command:
            - /bin/sh
            - -c
            - while true; do echo "$(date) My preferred color is $(cat /etc/config/color)" > /pod-data/index.html;
              sleep 10; done;

Response: This yaml code Updating Configuration via a ConfigMap | Create the Deployment:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-two-containers.yaml

Response: This bash code Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):


Prompt:
Explain this bash code:

kubectl get pods --selector=app.kubernetes.io/name=configmap-two-containers

Response: This bash code Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Explain this bash code:

kubectl expose deployment configmap-two-containers --name=configmap-service --port=8080 --target-port=80

Response: This bash code Updating Configuration via a ConfigMap | Use kubectl to forward the port:

Context: Updating Configuration via a ConfigMap | Use kubectl to forward the port: