Prompt:
Explain this text code:

NAME       TYPE           CLUSTER-IP     EXTERNAL-IP        PORT(S)               AGE
my-nginx   LoadBalancer   10.0.162.149     xx.xxx.xxx.xxx     8080:30163/TCP        21s

Response: This text code 8.1 - Connecting Applications with Services | The IP address in the EXTERNAL-IP column is the one that is available on the public internet. The CLUSTER-IP is only available inside your cluster/private cloud network.

Context: 8.1 - Connecting Applications with Services | The IP address in the EXTERNAL-IP column is the one that is available on the public internet. The CLUSTER-IP is only available inside your cluster/private cloud network.


Prompt:
Explain this text code:

curl https://<EXTERNAL-IP> -k
...
<title>Welcome to nginx!</title>

Response: This text code 8.1 - Connecting Applications with Services | The IP address in the EXTERNAL-IP column is the one that is available on the public internet. The CLUSTER-IP is only available inside your cluster/private cloud network.


Prompt:
Complete this shell code:

kubectl describe service my-nginx
...

Response:
LoadBalancer Ingress:   a320587ffd19711e5a37606cf4a74574-1142138393.us-east-1.elb.amazonaws.com
...

Context: 8.1 - Connecting Applications with Services | Applications running in a Kubernetes cluster find and communicate with each other, and the outside world, through the Service abstraction. This document explains what happens to the source IP of packe


Prompt:
Explain this shell code:

kubectl describe service my-nginx
...
LoadBalancer Ingress:   a320587ffd19711e5a37606cf4a74574-1142138393.us-east-1.elb.amazonaws.com
...

Response: This shell code 8.1 - Connecting Applications with Services | Applications running in a Kubernetes cluster find and communicate with each other, and the outside world, through the Service abstraction. This document explains what happens to the source IP of packe


Prompt:
Explain this shell code:

kubectl create deployment source-ip-app --image=registry.k8s.io/echoserver:1.10

Response: This shell code 8.2 - Using Source IP | The output is:

Context: 8.2 - Using Source IP | The output is:


Prompt:
Complete this text code:

NAME                           STATUS     ROLES    AGE     VERSION
kubernetes-node-6jst   Ready      <none>   2h      v1.13.0

Response:
kubernetes-node-cx31   Ready      <none>   2h      v1.13.0
kubernetes-node-jj1t   Ready      <none>   2h      v1.13.0

Context: 8.2 - Using Source IP | Get the proxy mode on one of the nodes (kube-proxy listens on port 10249):


Prompt:
Explain this text code:

NAME                           STATUS     ROLES    AGE     VERSION
kubernetes-node-6jst   Ready      <none>   2h      v1.13.0
kubernetes-node-cx31   Ready      <none>   2h      v1.13.0
kubernetes-node-jj1t   Ready      <none>   2h      v1.13.0

Response: This text code 8.2 - Using Source IP | Get the proxy mode on one of the nodes (kube-proxy listens on port 10249):


Prompt:
Explain this shell code:

# Run this in a shell on the node you want to query.
curl http://localhost:10249/proxyMode

Response: This shell code 8.2 - Using Source IP | The output is:

Context: 8.2 - Using Source IP | The output is:


Prompt:
Explain this shell code:

kubectl expose deployment source-ip-app --name=clusterip --port=80 --target-port=8080

Response: This shell code 8.2 - Using Source IP | The output is:

Context: 8.2 - Using Source IP | The output is:


Prompt:
Explain this text code:

NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
clusterip    ClusterIP   10.0.170.92   <none>        80/TCP    51s

Response: This text code 8.2 - Using Source IP | And hitting the ClusterIP from a pod in the same cluster:

Context: 8.2 - Using Source IP | And hitting the ClusterIP from a pod in the same cluster:


Prompt:
Explain this shell code:

kubectl run busybox -it --image=busybox:1.28 --restart=Never --rm

Response: This shell code 8.2 - Using Source IP | The output is similar to this:

Context: 8.2 - Using Source IP | The output is similar to this:


Prompt:
Explain this text code:

Waiting for pod default/busybox to be running, status is Pending, pod ready: false
If you don't see a command prompt, try pressing enter.

Response: This text code 8.2 - Using Source IP | You can then run a command inside that Pod:

Context: 8.2 - Using Source IP | You can then run a command inside that Pod:


Prompt:
Explain this shell code:

# Run this inside the terminal from "kubectl run"
ip addr

Response: This shell code 8.2 - Using Source IP | …then use wget to query the local webserver

Context: 8.2 - Using Source IP | …then use wget to query the local webserver


Prompt:
Complete this text code:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever

Response:
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc noqueue
    link/ether 0a:58:0a:f4:03:08 brd ff:ff:ff:ff:ff:ff
    inet 10.244.3.8/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::188a:84ff:feb0:26a5/64 scope link
       valid_lft forever preferred_lft forever


Prompt:
Explain this text code:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc noqueue
    link/ether 0a:58:0a:f4:03:08 brd ff:ff:ff:ff:ff:ff
    inet 10.244.3.8/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::188a:84ff:feb0:26a5/64 scope link
       valid_lft forever preferred_lft forever

Response: This text code 8.2 - Using Source IP | …then use wget to query the local webserver


Prompt:
Explain this shell code:

# Replace "10.0.170.92" with the IPv4 address of the Service named "clusterip"
wget -qO - 10.0.170.92

Response: This shell code 8.2 - Using Source IP | The client_address is always the client pod's IP address, whether the client pod and server pod are in the same node or in different nodes.

Context: 8.2 - Using Source IP | The client_address is always the client pod's IP address, whether the client pod and server pod are in the same node or in different nodes.


Prompt:
Complete this text code:

CLIENT VALUES:
client_address=10.244.3.8

Response:
command=GET
...


Prompt:
Explain this text code:

CLIENT VALUES:
client_address=10.244.3.8
command=GET
...

Response: This text code 8.2 - Using Source IP | The client_address is always the client pod's IP address, whether the client pod and server pod are in the same node or in different nodes.


Prompt:
Explain this shell code:

kubectl expose deployment source-ip-app --name=nodeport --port=80 --target-port=8080 --type=NodePort

Response: This shell code 8.2 - Using Source IP | The output is:

Context: 8.2 - Using Source IP | The output is:


Prompt:
Explain this shell code:

NODEPORT=$(kubectl get -o jsonpath="{.spec.ports[0].nodePort}" services nodeport)
NODES=$(kubectl get nodes -o jsonpath='{ $.items[*].status.addresses[?(@.type=="InternalIP")].address }')

Response: This shell code 8.2 - Using Source IP | If you're running on a cloud provider, you may need to open up a firewall-rule for the nodes:nodeport reported above. Now you can try reaching the Service from outside the cluster through the node por

Context: 8.2 - Using Source IP | If you're running on a cloud provider, you may need to open up a firewall-rule for the nodes:nodeport reported above. Now you can try reaching the Service from outside the cluster through the node por


Prompt:
Explain this shell code:

for node in $NODES; do curl -s $node:$NODEPORT | grep -i client_address; done

Response: This shell code 8.2 - Using Source IP | The output is similar to:

Context: 8.2 - Using Source IP | The output is similar to:


Prompt:
Explain this text code:

client_address=10.180.1.1
client_address=10.240.0.5
client_address=10.240.0.3

Response: This text code 8.2 - Using Source IP | Note that these are not the correct client IPs, they're cluster internal IPs. This is what happens:

Context: 8.2 - Using Source IP | Note that these are not the correct client IPs, they're cluster internal IPs. This is what happens:


Prompt:
Explain this shell code:

kubectl patch svc nodeport -p '{"spec":{"externalTrafficPolicy":"Local"}}'

Response: This shell code 8.2 - Using Source IP | The output is:

Context: 8.2 - Using Source IP | The output is:


Prompt:
Explain this shell code:

for node in $NODES; do curl --connect-timeout 1 -s $node:$NODEPORT | grep -i client_address; done

Response: This shell code 8.2 - Using Source IP | The output is similar to:


Prompt:
Explain this shell code:

kubectl expose deployment source-ip-app --name=loadbalancer --port=80 --target-port=8080 --type=LoadBalancer

Response: This shell code 8.2 - Using Source IP | The output is:

Context: 8.2 - Using Source IP | The output is:


Prompt:
Explain this text code:

NAME           TYPE           CLUSTER-IP    EXTERNAL-IP       PORT(S)   AGE
loadbalancer   LoadBalancer   10.0.65.118   203.0.113.140     80/TCP    5m

Response: This text code 8.2 - Using Source IP | Next, send a request to this Service's external-ip:

Context: 8.2 - Using Source IP | Next, send a request to this Service's external-ip:


Prompt:
Explain this shell code:

kubectl patch svc loadbalancer -p '{"spec":{"externalTrafficPolicy":"Local"}}'

Response: This shell code 8.2 - Using Source IP | You should immediately see the service.spec.healthCheckNodePort field allocated by Kubernetes:

Context: 8.2 - Using Source IP | You should immediately see the service.spec.healthCheckNodePort field allocated by Kubernetes:


Prompt:
Explain this shell code:

kubectl get svc loadbalancer -o yaml | grep -i healthCheckNodePort

Response: This shell code 8.2 - Using Source IP | The output is similar to this:


Prompt:
Explain this text code:

NAME                            READY     STATUS    RESTARTS   AGE       IP             NODE
source-ip-app-826191075-qehz4   1/1       Running   0          20h       10.180.1.136   kubernetes-node-6jst

Response: This text code 8.2 - Using Source IP | Use curl to fetch the /healthz endpoint on various nodes:

Context: 8.2 - Using Source IP | Use curl to fetch the /healthz endpoint on various nodes:


Prompt:
Explain this shell code:

# Run this locally on a node you choose
curl localhost:32122/healthz

Response: This shell code 8.2 - Using Source IP | On a different node you might get a different result:

Context: 8.2 - Using Source IP | On a different node you might get a different result:


Prompt:
Explain this shell code:

# Run this locally on a node you choose
curl localhost:32122/healthz

Response: This shell code 8.2 - Using Source IP | A controller running on the control plane is responsible for allocating the cloud load balancer. The same controller also allocates HTTP health checks pointing to this port/path on each node. Wait abo

Context: 8.2 - Using Source IP | A controller running on the control plane is responsible for allocating the cloud load balancer. The same controller also allocates HTTP health checks pointing to this port/path on each node. Wait abo


Prompt:
Complete this yaml code:

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

Response:
      terminationGracePeriodSeconds: 120 # extra long grace period
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
        lifecycle:
          preStop:
            exec:
              # Real life termination may take any time up to terminationGracePeriodSeconds.
              # In this example - just hang around for at least the duration of terminationGracePeriodSeconds,
              # at 120 seconds container will be forcibly terminated.
              # Note, all this time nginx will keep processing requests.
              command: [
                "/bin/sh", "-c", "sleep 180"
              ]

Context: 8.3 - Explore Termination Behavior for Pods And Their Endpoints | Now create the Deployment Pod and Service using the above files:


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      terminationGracePeriodSeconds: 120 # extra long grace period
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
        lifecycle:
          preStop:
            exec:
              # Real life termination may take any time up to terminationGracePeriodSeconds.
              # In this example - just hang around for at least the duration of terminationGracePeriodSeconds,
              # at 120 seconds container will be forcibly terminated.
              # Note, all this time nginx will keep processing requests.
              command: [
                "/bin/sh", "-c", "sleep 180"
              ]

Response: This yaml code 8.3 - Explore Termination Behavior for Pods And Their Endpoints | Now create the Deployment Pod and Service using the above files:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:

Response:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

Response: This yaml code 8.3 - Explore Termination Behavior for Pods And Their Endpoints | Now create the Deployment Pod and Service using the above files:


Prompt:
Explain this shell code:

kubectl apply -f pod-with-graceful-termination.yaml
kubectl apply -f explore-graceful-termination-nginx.yaml

Response: This shell code 8.3 - Explore Termination Behavior for Pods And Their Endpoints | Once the Pod and Service are running, you can get the name of any associated EndpointSlices:

Context: 8.3 - Explore Termination Behavior for Pods And Their Endpoints | Once the Pod and Service are running, you can get the name of any associated EndpointSlices:


Prompt:
Explain this none code:

NAME                  ADDRESSTYPE   PORTS   ENDPOINTS                 AGE
nginx-service-6tjbr   IPv4          80      10.12.1.199,10.12.1.201   22m

Response: This none code 8.3 - Explore Termination Behavior for Pods And Their Endpoints | You can see its status, and validate that there is one endpoint registered:

Context: 8.3 - Explore Termination Behavior for Pods And Their Endpoints | You can see its status, and validate that there is one endpoint registered:


Prompt:
Explain this shell code:

kubectl get endpointslices -o json -l kubernetes.io/service-name=nginx-service

Response: This shell code 8.3 - Explore Termination Behavior for Pods And Their Endpoints | The output is similar to this:

Context: 8.3 - Explore Termination Behavior for Pods And Their Endpoints | The output is similar to this:


Prompt:
Complete this none code:

{
    "addressType": "IPv4",
    "apiVersion": "discovery.k8s.io/v1",
    "endpoints": [
        {
            "addresses": [

Response:
                "10.12.1.201"
            ],
            "conditions": {
                "ready": true,
                "serving": true,
                "terminating": false

Context: 8.3 - Explore Termination Behavior for Pods And Their Endpoints | Now let's terminate the Pod and validate that the Pod is being terminated respecting the graceful termination period configuration:


Prompt:
Explain this none code:

{
    "addressType": "IPv4",
    "apiVersion": "discovery.k8s.io/v1",
    "endpoints": [
        {
            "addresses": [
                "10.12.1.201"
            ],
            "conditions": {
                "ready": true,
                "serving": true,
                "terminating": false

Response: This none code 8.3 - Explore Termination Behavior for Pods And Their Endpoints | Now let's terminate the Pod and validate that the Pod is being terminated respecting the graceful termination period configuration:


Prompt:
Explain this shell code:

kubectl delete pod nginx-deployment-7768647bf9-b4b9s

Response: This shell code 8.3 - Explore Termination Behavior for Pods And Their Endpoints | All pods:

Context: 8.3 - Explore Termination Behavior for Pods And Their Endpoints | All pods:


Prompt:
Explain this none code:

NAME                                READY   STATUS        RESTARTS      AGE
nginx-deployment-7768647bf9-b4b9s   1/1     Terminating   0             4m1s
nginx-deployment-7768647bf9-rkxlw   1/1     Running       0             8s

Response: This none code 8.3 - Explore Termination Behavior for Pods And Their Endpoints | You can see that the new pod got scheduled.

Context: 8.3 - Explore Termination Behavior for Pods And Their Endpoints | You can see that the new pod got scheduled.


Prompt:
Explain this shell code:

kubectl get endpointslice -o json nginx-service-6tjbr

Response: This shell code 8.3 - Explore Termination Behavior for Pods And Their Endpoints | The output is similar to this:


Prompt:
Complete this none code:

{
    "addressType": "IPv4",
    "apiVersion": "discovery.k8s.io/v1",
    "endpoints": [
        {
            "addresses": [
                "10.12.1.201"
            ],
            "conditions": {
                "ready": false,
                "serving": true,
                "terminating": true
            },
            "nodeName": "gke-main-default-pool-dca1511c-d17b",
            "targetRef": {
                "kind": "Pod",
                "name": "nginx-deployment-7768647bf9-b4b9s",
                "namespace": "default",
                "uid": "66fa831c-7eb2-407f-bd2c-f96dfe841478"

Response:
            },
            "zone": "us-central1-c"
        },
        {
            "addresses": [
                "10.12.1.202"
            ],
            "conditions": {
                "ready": true,
                "serving": true,
                "terminating": false
            },
            "nodeName": "gke-main-default-pool-dca1511c-d17b",
            "targetRef": {
                "kind": "Pod",
                "name": "nginx-deployment-7768647bf9-rkxlw",
                "namespace": "default",
                "uid": "722b1cbe-dcd7-4ed4-8928-4a4d0e2bbe35"
            },
            "zone": "us-central1-c"

Context: 8.3 - Explore Termination Behavior for Pods And Their Endpoints | This allows applications to communicate their state during termination and clients (such as load balancers) to implement connection draining functionality. These clients may detect terminating endpoin


Prompt:
Explain this none code:

{
    "addressType": "IPv4",
    "apiVersion": "discovery.k8s.io/v1",
    "endpoints": [
        {
            "addresses": [
                "10.12.1.201"
            ],
            "conditions": {
                "ready": false,
                "serving": true,
                "terminating": true
            },
            "nodeName": "gke-main-default-pool-dca1511c-d17b",
            "targetRef": {
                "kind": "Pod",
                "name": "nginx-deployment-7768647bf9-b4b9s",
                "namespace": "default",
                "uid": "66fa831c-7eb2-407f-bd2c-f96dfe841478"
            },
            "zone": "us-central1-c"
        },
        {
            "addresses": [
                "10.12.1.202"
            ],
            "conditions": {
                "ready": true,
                "serving": true,
                "terminating": false
            },
            "nodeName": "gke-main-default-pool-dca1511c-d17b",
            "targetRef": {
                "kind": "Pod",
                "name": "nginx-deployment-7768647bf9-rkxlw",
                "namespace": "default",
                "uid": "722b1cbe-dcd7-4ed4-8928-4a4d0e2bbe35"
            },
            "zone": "us-central1-c"

Response: This none code 8.3 - Explore Termination Behavior for Pods And Their Endpoints | This allows applications to communicate their state during termination and clients (such as load balancers) to implement connection draining functionality. These clients may detect terminating endpoin


Prompt:
Explain this text code:

# Start a new terminal, and leave this running.
minikube dashboard

Response: This text code 1 - Hello Minikube | Now, switch back to the terminal where you ran minikube start.

Context: 1 - Hello Minikube | Now, switch back to the terminal where you ran minikube start.


Prompt:
Explain this text code:

# Start a new terminal, and leave this running.
minikube dashboard --url

Response: This text code 1 - Hello Minikube | Now, you can use this URL and switch back to the terminal where you ran minikube start.

Context: 1 - Hello Minikube | Now, you can use this URL and switch back to the terminal where you ran minikube start.


Prompt:
Explain this text code:

# Run a test container image that includes a webserver
kubectl create deployment hello-node --image=registry.k8s.io/e2e-test-images/agnhost:2.53 -- /agnhost netexec --http-port=8080

Response: This text code 1 - Hello Minikube | View the Deployment:

Context: 1 - Hello Minikube | View the Deployment:


Prompt:
Explain this bash code:

kubectl expose deployment hello-node --type=LoadBalancer --port=8080

Response: This bash code 1 - Hello Minikube | The --type=LoadBalancer flag indicates that you want to expose your Service outside of the cluster.

Context: 1 - Hello Minikube | The --type=LoadBalancer flag indicates that you want to expose your Service outside of the cluster.


Prompt:
Explain this bash code:

kubectl delete service hello-node
kubectl delete deployment hello-node

Response: This bash code 1 - Hello Minikube | Stop the Minikube cluster

Context: 1 - Hello Minikube | Stop the Minikube cluster


Prompt:
Explain this bash code:

kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1

Response: This bash code 2.2.1 - Using kubectl to Create a Deployment | Great! You just deployed your first application by creating a deployment. This performed a few things for you:

Context: 2.2.1 - Using kubectl to Create a Deployment | Great! You just deployed your first application by creating a deployment. This performed a few things for you:


Prompt:
Explain this text code:

export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
echo Name of the Pod: $POD_NAME

Response: This text code 2.2.1 - Using kubectl to Create a Deployment | You can access the Pod through the proxied API, by running:

Context: 2.2.1 - Using kubectl to Create a Deployment | You can access the Pod through the proxied API, by running:


Prompt:
Explain this text code:

curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME:8080/proxy/

Response: This text code 2.2.1 - Using kubectl to Create a Deployment | In order for the new Deployment to be accessible without using the proxy, a Service is required which will be explained in Module 4.

Context: 2.2.1 - Using kubectl to Create a Deployment | In order for the new Deployment to be accessible without using the proxy, a Service is required which will be explained in Module 4.


Prompt:
Explain this text code:

export POD_NAME="$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')"
echo Name of the Pod: $POD_NAME

Response: This text code 2.3.1 - Viewing Pods and Nodes | To see the output of our application, run a curl request:

Context: 2.3.1 - Viewing Pods and Nodes | To see the output of our application, run a curl request:


Prompt:
Explain this text code:

curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME:8080/proxy/

Response: This text code 2.3.1 - Viewing Pods and Nodes | The URL is the route to the API of the Pod.

Context: 2.3.1 - Viewing Pods and Nodes | The URL is the route to the API of the Pod.


Prompt:
Explain this bash code:

kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080

Response: This bash code 2.4.1 - Using a Service to Expose Your App | We have now a running Service called kubernetes-bootcamp. Here we see that the Service received a unique cluster-IP, an internal port and an external-IP (the IP of the Node).

Context: 2.4.1 - Using a Service to Expose Your App | We have now a running Service called kubernetes-bootcamp. Here we see that the Service received a unique cluster-IP, an internal port and an external-IP (the IP of the Node).


Prompt:
Explain this text code:

export NODE_PORT="$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')"
echo "NODE_PORT=$NODE_PORT"

Response: This text code 2.4.1 - Using a Service to Expose Your App | Now we can test that the app is exposed outside of the cluster using curl, the IP address of the Node and the externally exposed port:

Context: 2.4.1 - Using a Service to Expose Your App | Now we can test that the app is exposed outside of the cluster using curl, the IP address of the Node and the externally exposed port:


Prompt:
Explain this text code:

export POD_NAME="$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')"
echo "Name of the Pod: $POD_NAME"

Response: This text code 2.4.1 - Using a Service to Expose Your App | To apply a new label we use the label subcommand followed by the object type, object name and the new label:

Context: 2.4.1 - Using a Service to Expose Your App | To apply a new label we use the label subcommand followed by the object type, object name and the new label:


Prompt:
Explain this bash code:

kubectl exec -ti $POD_NAME -- curl http://localhost:8080

Response: This bash code 2.4.1 - Using a Service to Expose Your App | We see here that the application is up. This is because the Deployment is managing the application. To shut down the application, you would need to delete the Deployment as well.

Context: 2.4.1 - Using a Service to Expose Your App | We see here that the application is up. This is because the Deployment is managing the application. To shut down the application, you would need to delete the Deployment as well.


Prompt:
Explain this bash code:

kubectl expose deployment/kubernetes-bootcamp --type="LoadBalancer" --port 8080

Response: This bash code 2.5.1 - Running Multiple Instances of Your App | Scaling out a Deployment will ensure new Pods are created and scheduled to Nodes with available resources. Scaling will increase the number of Pods to the new desired state. Kubernetes also supports a

Context: 2.5.1 - Running Multiple Instances of Your App | Scaling out a Deployment will ensure new Pods are created and scheduled to Nodes with available resources. Scaling will increase the number of Pods to the new desired state. Kubernetes also supports a


Prompt:
Explain this bash code:

kubectl scale deployments/kubernetes-bootcamp --replicas=4

Response: This bash code 2.5.1 - Running Multiple Instances of Your App | To list your Deployments once again, use get deployments:

Context: 2.5.1 - Running Multiple Instances of Your App | To list your Deployments once again, use get deployments:


Prompt:
Explain this text code:

export NODE_PORT="$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')"
echo NODE_PORT=$NODE_PORT

Response: This text code 2.5.1 - Running Multiple Instances of Your App | Next, we’ll do a curl to the exposed IP address and port. Execute the command multiple times:

Context: 2.5.1 - Running Multiple Instances of Your App | Next, we’ll do a curl to the exposed IP address and port. Execute the command multiple times:


Prompt:
Explain this bash code:

kubectl scale deployments/kubernetes-bootcamp --replicas=2

Response: This bash code 2.5.1 - Running Multiple Instances of Your App | List the Deployments to check if the change was applied with the get deployments subcommand:

Context: 2.5.1 - Running Multiple Instances of Your App | List the Deployments to check if the change was applied with the get deployments subcommand:


Prompt:
Explain this bash code:

kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=docker.io/jocatalin/kubernetes-bootcamp:v2

Response: This bash code 2.6.1 - Performing a Rolling Update | The command notified the Deployment to use a different image for your app and initiated a rolling update. Check the status of the new Pods, and view the old one terminating with the get pods subcomman

Context: 2.6.1 - Performing a Rolling Update | The command notified the Deployment to use a different image for your app and initiated a rolling update. Check the status of the new Pods, and view the old one terminating with the get pods subcomman


Prompt:
Explain this bash code:

kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080

Response: This bash code 2.6.1 - Performing a Rolling Update | Create an environment variable called NODE_PORT that has the value of the Node port assigned:

Context: 2.6.1 - Performing a Rolling Update | Create an environment variable called NODE_PORT that has the value of the Node port assigned:


Prompt:
Explain this text code:

export NODE_PORT="$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')"
echo "NODE_PORT=$NODE_PORT"

Response: This text code 2.6.1 - Performing a Rolling Update | Next, do a curl to the exposed IP and port:

Context: 2.6.1 - Performing a Rolling Update | Next, do a curl to the exposed IP and port:


Prompt:
Explain this bash code:

kubectl rollout status deployments/kubernetes-bootcamp

Response: This bash code 2.6.1 - Performing a Rolling Update | To view the current image version of the app, run the describe pods subcommand:

Context: 2.6.1 - Performing a Rolling Update | To view the current image version of the app, run the describe pods subcommand:


Prompt:
Explain this bash code:

kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=gcr.io/google-samples/kubernetes-bootcamp:v10

Response: This bash code 2.6.1 - Performing a Rolling Update | Use get deployments to see the status of the deployment:

Context: 2.6.1 - Performing a Rolling Update | Use get deployments to see the status of the deployment:


Prompt:
Explain this bash code:

kubectl rollout undo deployments/kubernetes-bootcamp

Response: This bash code 2.6.1 - Performing a Rolling Update | The rollout undo command reverts the deployment to the previous known state (v2 of the image). Updates are versioned and you can revert to any previously known state of a Deployment.

Context: 2.6.1 - Performing a Rolling Update | The rollout undo command reverts the deployment to the previous known state (v2 of the image). Updates are versioned and you can revert to any previously known state of a Deployment.


Prompt:
Explain this bash code:

kubectl delete deployments/kubernetes-bootcamp services/kubernetes-bootcamp

Response: This bash code 2.6.1 - Performing a Rolling Update | This page provides a step-by-step example of updating configuration within a Pod via a ConfigMap and builds upon the Configure a Pod to Use a ConfigMap task.At the end of this tutorial, you will under

Context: 2.6.1 - Performing a Rolling Update | This page provides a step-by-step example of updating configuration within a Pod via a ConfigMap and builds upon the Configure a Pod to Use a ConfigMap task.At the end of this tutorial, you will under


Prompt:
Explain this bash code:

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

Response: This bash code 3.1 - 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: 3.1 - 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: 3.1 - 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 3.1 - 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 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):

Context: 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | You should see an output similar to:

Context: 3.1 - 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 3.1 - 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

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


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 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | Below is an example of a Deployment manifest with an environment variable configured via the ConfigMap fruits.

Context: 3.1 - 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 3.1 - 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 3.1 - 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 3.1 - 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 3.1 - 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 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | Notice that the output remains unchanged, even though you edited the ConfigMap:

Context: 3.1 - 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: 3.1 - 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 3.1 - 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 3.1 - 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: 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | You should see an output similar to the below:

Context: 3.1 - 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 3.1 - 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: 3.1 - 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 3.1 - 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 3.1 - 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 3.1 - 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 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | Use kubectl to forward the port:

Context: 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | Access the service.

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


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: 3.1 - 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 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | You should see the output change as follows:

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


Prompt:
Explain this bash code:

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

Response: This bash code 3.1 - 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: 3.1 - 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:

deployments/deployment-with-configmap-and-sidecar-container.yaml
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

Response:
          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;


Prompt:
Explain this yaml code:

deployments/deployment-with-configmap-and-sidecar-container.yaml
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 3.1 - 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 3.1 - 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 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Explain this bash code:

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

Response: This bash code 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | Access the service.


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 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | You should see the output change as follows:


Prompt:
Complete this yaml code:

configmap/immutable-configmap.yaml
apiVersion: v1
data:
  company_name: "ACME, Inc." # existing fictional company name

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

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


Prompt:
Explain this yaml code:

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

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


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


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 3.1 - 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 3.1 - 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: 3.1 - 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:

deployments/deployment-with-immutable-configmap-as-volume.yaml
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

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


Prompt:
Explain this yaml code:

deployments/deployment-with-immutable-configmap-as-volume.yaml
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 3.1 - 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 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | Check the pods for this Deployment to ensure they are ready (matching by selector):

Context: 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | You should see an output similar to:

Context: 3.1 - 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/immutable-configmap-volume

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


Prompt:
Complete this yaml code:

configmap/new-immutable-configmap.yaml
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:

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

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


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 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | You should see an output similar to:


Prompt:
Complete this text code:

volumes:
- configMap:

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

Context: 3.1 - 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 3.1 - 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 3.1 - Updating Configuration via a ConfigMap | You should eventually see an output similar to:

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


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 3.1 - Updating Configuration via a ConfigMap | You should see an output similar to the below:


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: 3.1 - Updating Configuration via a ConfigMap | This page provides a real world example of how to configure Redis using a ConfigMap and builds upon the Configure a Pod to Use a ConfigMap task.


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 3.1 - Updating Configuration via a ConfigMap | This page provides a real world example of how to configure Redis using a ConfigMap and builds upon the Configure a Pod to Use a ConfigMap task.


Prompt:
Complete this yaml code:

cat <<EOF >./example-redis-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:

Response:
  name: example-redis-config
data:
  redis-config: ""
EOF

Context: 3.2 - Configuring Redis using a ConfigMap | Apply the ConfigMap created above, along with a Redis pod manifest:


Prompt:
Explain this yaml code:

cat <<EOF >./example-redis-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: example-redis-config
data:
  redis-config: ""
EOF

Response: This yaml code 3.2 - Configuring Redis using a ConfigMap | Apply the ConfigMap created above, along with a Redis pod manifest:


Prompt:
Explain this bash code:

kubectl apply -f example-redis-config.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/config/redis-pod.yaml

Response: This bash code 3.2 - Configuring Redis using a ConfigMap | Examine the contents of the Redis pod manifest and note the following:

Context: 3.2 - Configuring Redis using a ConfigMap | Examine the contents of the Redis pod manifest and note the following:


Prompt:
Complete this yaml code:

pods/config/redis-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: redis:8.0.2
    command:
      - redis-server
      - "/redis-master/redis.conf"
    env:
    - name: MASTER
      value: "true"
    ports:
    - containerPort: 6379

Response:
    resources:
      limits:
        cpu: "0.1"
    volumeMounts:
    - mountPath: /redis-master-data
      name: data
    - mountPath: /redis-master
      name: config
  volumes:
    - name: data
      emptyDir: {}
    - name: config
      configMap:
        name: example-redis-config
        items:
        - key: redis-config
          path: redis.conf

Context: 3.2 - Configuring Redis using a ConfigMap | Examine the created objects:


Prompt:
Explain this yaml code:

pods/config/redis-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: redis:8.0.2
    command:
      - redis-server
      - "/redis-master/redis.conf"
    env:
    - name: MASTER
      value: "true"
    ports:
    - containerPort: 6379
    resources:
      limits:
        cpu: "0.1"
    volumeMounts:
    - mountPath: /redis-master-data
      name: data
    - mountPath: /redis-master
      name: config
  volumes:
    - name: data
      emptyDir: {}
    - name: config
      configMap:
        name: example-redis-config
        items:
        - key: redis-config
          path: redis.conf

Response: This yaml code 3.2 - Configuring Redis using a ConfigMap | Examine the created objects:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: redis:8.0.2
    command:
      - redis-server
      - "/redis-master/redis.conf"
    env:
    - name: MASTER
      value: "true"
    ports:
    - containerPort: 6379

Response:
    resources:
      limits:
        cpu: "0.1"
    volumeMounts:
    - mountPath: /redis-master-data
      name: data
    - mountPath: /redis-master
      name: config
  volumes:
    - name: data
      emptyDir: {}
    - name: config
      configMap:
        name: example-redis-config
        items:
        - key: redis-config
          path: redis.conf


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: redis:8.0.2
    command:
      - redis-server
      - "/redis-master/redis.conf"
    env:
    - name: MASTER
      value: "true"
    ports:
    - containerPort: 6379
    resources:
      limits:
        cpu: "0.1"
    volumeMounts:
    - mountPath: /redis-master-data
      name: data
    - mountPath: /redis-master
      name: config
  volumes:
    - name: data
      emptyDir: {}
    - name: config
      configMap:
        name: example-redis-config
        items:
        - key: redis-config
          path: redis.conf

Response: This yaml code 3.2 - Configuring Redis using a ConfigMap | Examine the created objects:


Prompt:
Explain this bash code:

kubectl get pod/redis configmap/example-redis-config

Response: This bash code 3.2 - Configuring Redis using a ConfigMap | You should see the following output:

Context: 3.2 - Configuring Redis using a ConfigMap | You should see the following output:


Prompt:
Complete this text code:

Name:         example-redis-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Response:
Data
====
redis-config:

Context: 3.2 - Configuring Redis using a ConfigMap | Use kubectl exec to enter the pod and run the redis-cli tool to check the current configuration:


Prompt:
Explain this text code:

Name:         example-redis-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
redis-config:

Response: This text code 3.2 - Configuring Redis using a ConfigMap | Use kubectl exec to enter the pod and run the redis-cli tool to check the current configuration:


Prompt:
Complete this yaml code:

pods/config/example-redis-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:

Response:
  name: example-redis-config
data:
  redis-config: |
    maxmemory 2mb
    maxmemory-policy allkeys-lru

Context: 3.2 - Configuring Redis using a ConfigMap | Apply the updated ConfigMap:


Prompt:
Explain this yaml code:

pods/config/example-redis-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: example-redis-config
data:
  redis-config: |
    maxmemory 2mb
    maxmemory-policy allkeys-lru

Response: This yaml code 3.2 - Configuring Redis using a ConfigMap | Apply the updated ConfigMap:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: ConfigMap
metadata:
  name: example-redis-config

Response:
data:
  redis-config: |
    maxmemory 2mb
    maxmemory-policy allkeys-lru


Prompt:
Explain this yaml code:

apiVersion: v1
kind: ConfigMap
metadata:
  name: example-redis-config
data:
  redis-config: |
    maxmemory 2mb
    maxmemory-policy allkeys-lru

Response: This yaml code 3.2 - Configuring Redis using a ConfigMap | Apply the updated ConfigMap:


Prompt:
Complete this text code:

Name:         example-redis-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Response:
Data
====
redis-config:
----
maxmemory 2mb
maxmemory-policy allkeys-lru

Context: 3.2 - Configuring Redis using a ConfigMap | Check the Redis Pod again using redis-cli via kubectl exec to see if the configuration was applied:


Prompt:
Explain this text code:

Name:         example-redis-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
redis-config:
----
maxmemory 2mb
maxmemory-policy allkeys-lru

Response: This text code 3.2 - Configuring Redis using a ConfigMap | Check the Redis Pod again using redis-cli via kubectl exec to see if the configuration was applied:


Prompt:
Explain this bash code:

kubectl delete pod redis
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/config/redis-pod.yaml

Response: This bash code 3.2 - Configuring Redis using a ConfigMap | Now re-check the configuration values one last time:

Context: 3.2 - Configuring Redis using a ConfigMap | Now re-check the configuration values one last time:


Prompt:
Explain this bash code:

kubectl delete pod/redis configmap/example-redis-config

Response: This bash code 3.2 - Configuring Redis using a ConfigMap | This section is relevant for people adopting a new built-in sidecar containers feature for their workloads.

Context: 3.2 - Configuring Redis using a ConfigMap | This section is relevant for people adopting a new built-in sidecar containers feature for their workloads.


Prompt:
Explain this bash code:

kubectl get --raw /metrics | grep kubernetes_feature_enabled | grep SidecarContainers

Response: This bash code 3.3 - Adopting Sidecar Containers | For the individual node:

Context: 3.3 - Adopting Sidecar Containers | For the individual node:


Prompt:
Explain this bash code:

kubectl get --raw /api/v1/nodes/<node-name>/proxy/metrics | grep kubernetes_feature_enabled | grep SidecarContainers

Response: This bash code 3.3 - Adopting Sidecar Containers | If you see something like this:

Context: 3.3 - Adopting Sidecar Containers | If you see something like this:


Prompt:
Explain this bash code:

kubectl cluster-info --context kind-psa-wo-cluster-pss

Response: This bash code 4.1 - Apply Pod Security Standards at the Cluster Level | The output is similar to this:

Context: 4.1 - Apply Pod Security Standards at the Cluster Level | The output is similar to this:


Prompt:
Explain this bash code:

kubectl label --dry-run=server --overwrite ns --all \
pod-security.kubernetes.io/enforce=privileged

Response: This bash code 4.1 - Apply Pod Security Standards at the Cluster Level | The output is similar to:

Context: 4.1 - Apply Pod Security Standards at the Cluster Level | The output is similar to:


Prompt:
Explain this bash code:

kubectl label --dry-run=server --overwrite ns --all \
pod-security.kubernetes.io/enforce=baseline

Response: This bash code 4.1 - Apply Pod Security Standards at the Cluster Level | The output is similar to:


Prompt:
Explain this bash code:

kubectl label --dry-run=server --overwrite ns --all \
pod-security.kubernetes.io/enforce=restricted

Response: This bash code 4.1 - Apply Pod Security Standards at the Cluster Level | The output is similar to:


Prompt:
Explain this text code:

kind create cluster --name psa-with-cluster-pss --config /tmp/pss/cluster-config.yaml

Response: This text code 4.1 - Apply Pod Security Standards at the Cluster Level | The output is similar to this:


Prompt:
Explain this bash code:

kubectl cluster-info --context kind-psa-with-cluster-pss

Response: This bash code 4.1 - Apply Pod Security Standards at the Cluster Level | The output is similar to this:


Prompt:
Complete this yaml code:

security/example-baseline-pod.yaml
apiVersion: v1
 kind: Pod
 metadata:
   name: nginx

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

Context: 4.1 - Apply Pod Security Standards at the Cluster Level | The pod is started normally, but the output includes a warning:


Prompt:
Explain this yaml code:

security/example-baseline-pod.yaml
apiVersion: v1
 kind: Pod
 metadata:
   name: nginx
 spec:
   containers:
     - image: nginx
       name: nginx
       ports:
         - containerPort: 80

Response: This yaml code 4.1 - Apply Pod Security Standards at the Cluster Level | The pod is started normally, but the output includes a warning:


Prompt:
Complete this yaml code:

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

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


Prompt:
Explain this yaml code:

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

Response: This yaml code 4.1 - Apply Pod Security Standards at the Cluster Level | The pod is started normally, but the output includes a warning:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/security/example-baseline-pod.yaml

Response: This bash code 4.1 - Apply Pod Security Standards at the Cluster Level | The pod is started normally, but the output includes a warning:


Prompt:
Explain this bash code:

kubectl label --overwrite ns example \
   pod-security.kubernetes.io/warn=baseline \
   pod-security.kubernetes.io/warn-version=latest

Response: This bash code 4.2 - Apply Pod Security Standards at the Namespace Level | You can configure multiple pod security standard checks on any namespace, using labels. The following command will enforce the baseline Pod Security Standard, but warn and audit for restricted Pod Sec

Context: 4.2 - Apply Pod Security Standards at the Namespace Level | You can configure multiple pod security standard checks on any namespace, using labels. The following command will enforce the baseline Pod Security Standard, but warn and audit for restricted Pod Sec


Prompt:
Complete this bash code:

kubectl label --overwrite ns example \
  pod-security.kubernetes.io/enforce=baseline \
  pod-security.kubernetes.io/enforce-version=latest \

Response:
  pod-security.kubernetes.io/warn=restricted \
  pod-security.kubernetes.io/warn-version=latest \
  pod-security.kubernetes.io/audit=restricted \
  pod-security.kubernetes.io/audit-version=latest

Context: 4.2 - Apply Pod Security Standards at the Namespace Level | Create a baseline Pod in the example namespace:


Prompt:
Explain this bash code:

kubectl label --overwrite ns example \
  pod-security.kubernetes.io/enforce=baseline \
  pod-security.kubernetes.io/enforce-version=latest \
  pod-security.kubernetes.io/warn=restricted \
  pod-security.kubernetes.io/warn-version=latest \
  pod-security.kubernetes.io/audit=restricted \
  pod-security.kubernetes.io/audit-version=latest

Response: This bash code 4.2 - Apply Pod Security Standards at the Namespace Level | Create a baseline Pod in the example namespace:


Prompt:
Explain this bash code:

kubectl apply -n example -f https://k8s.io/examples/security/example-baseline-pod.yaml

Response: This bash code 4.2 - Apply Pod Security Standards at the Namespace Level | The Pod does start OK; the output includes a warning. For example:

Context: 4.2 - Apply Pod Security Standards at the Namespace Level | The Pod does start OK; the output includes a warning. For example:


Prompt:
Explain this bash code:

kubectl apply -n default -f https://k8s.io/examples/security/example-baseline-pod.yaml

Response: This bash code 4.2 - Apply Pod Security Standards at the Namespace Level | Output is similar to this:

Context: 4.2 - Apply Pod Security Standards at the Namespace Level | Output is similar to this:


Prompt:
Explain this text code:

ssh gke-test-default-pool-239f5d02-gyn2 "sudo cat /sys/kernel/security/apparmor/profiles | sort"

Response: This text code 4.3 - Restrict a Container's Access to Resources with AppArmor | For more details on loading profiles on nodes, see Setting up nodes with profiles.

Context: 4.3 - Restrict a Container's Access to Resources with AppArmor | For more details on loading profiles on nodes, see Setting up nodes with profiles.


Prompt:
Explain this text code:

securityContext:
  appArmorProfile:
    type: <profile_type>

Response: This text code 4.3 - Restrict a Container's Access to Resources with AppArmor | Where <profile_type> is one of:

Context: 4.3 - Restrict a Container's Access to Resources with AppArmor | Where <profile_type> is one of:


Prompt:
Explain this bash code:

kubectl exec <pod_name> -- cat /proc/1/attr/current

Response: This bash code 4.3 - Restrict a Container's Access to Resources with AppArmor | The output should look something like this:

Context: 4.3 - Restrict a Container's Access to Resources with AppArmor | The output should look something like this:


Prompt:
Complete this cpp code:

# This example assumes that node names match host names, and are reachable via SSH.
NODES=($( kubectl get node -o jsonpath='{.items[*].status.addresses[?(.type == "Hostname")].address}' ))

for NODE in ${NODES[*]}; do ssh $NODE 'sudo apparmor_parser -q <<EOF
#include <tunables/global>

profile k8s-apparmor-example-deny-write flags=(attach_disconnected) {
  #include <abstractions/base>

Response:
  file,

  # Deny all file writes.
  deny /** w,
}
EOF'
done

Context: 4.3 - Restrict a Container's Access to Resources with AppArmor | Next, run a simple "Hello AppArmor" Pod with the deny-write profile:


Prompt:
Explain this cpp code:

# This example assumes that node names match host names, and are reachable via SSH.
NODES=($( kubectl get node -o jsonpath='{.items[*].status.addresses[?(.type == "Hostname")].address}' ))

for NODE in ${NODES[*]}; do ssh $NODE 'sudo apparmor_parser -q <<EOF
#include <tunables/global>

profile k8s-apparmor-example-deny-write flags=(attach_disconnected) {
  #include <abstractions/base>

  file,

  # Deny all file writes.
  deny /** w,
}
EOF'
done

Response: This cpp code 4.3 - Restrict a Container's Access to Resources with AppArmor | Next, run a simple "Hello AppArmor" Pod with the deny-write profile:


Prompt:
Complete this yaml code:

pods/security/hello-apparmor.yaml
apiVersion: v1
kind: Pod
metadata:
  name: hello-apparmor
spec:
  securityContext:

Response:
    appArmorProfile:
      type: Localhost
      localhostProfile: k8s-apparmor-example-deny-write
  containers:
  - name: hello
    image: busybox:1.28
    command: [ "sh", "-c", "echo 'Hello AppArmor!' && sleep 1h" ]

Context: 4.3 - Restrict a Container's Access to Resources with AppArmor | You can verify that the container is actually running with that profile by checking /proc/1/attr/current:


Prompt:
Explain this yaml code:

pods/security/hello-apparmor.yaml
apiVersion: v1
kind: Pod
metadata:
  name: hello-apparmor
spec:
  securityContext:
    appArmorProfile:
      type: Localhost
      localhostProfile: k8s-apparmor-example-deny-write
  containers:
  - name: hello
    image: busybox:1.28
    command: [ "sh", "-c", "echo 'Hello AppArmor!' && sleep 1h" ]

Response: This yaml code 4.3 - Restrict a Container's Access to Resources with AppArmor | You can verify that the container is actually running with that profile by checking /proc/1/attr/current:


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: hello-apparmor
spec:
  securityContext:

Response:
    appArmorProfile:
      type: Localhost
      localhostProfile: k8s-apparmor-example-deny-write
  containers:
  - name: hello
    image: busybox:1.28
    command: [ "sh", "-c", "echo 'Hello AppArmor!' && sleep 1h" ]


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: hello-apparmor
spec:
  securityContext:
    appArmorProfile:
      type: Localhost
      localhostProfile: k8s-apparmor-example-deny-write
  containers:
  - name: hello
    image: busybox:1.28
    command: [ "sh", "-c", "echo 'Hello AppArmor!' && sleep 1h" ]

Response: This yaml code 4.3 - Restrict a Container's Access to Resources with AppArmor | You can verify that the container is actually running with that profile by checking /proc/1/attr/current:


Prompt:
Explain this bash code:

kubectl exec hello-apparmor -- cat /proc/1/attr/current

Response: This bash code 4.3 - Restrict a Container's Access to Resources with AppArmor | The output should be:

Context: 4.3 - Restrict a Container's Access to Resources with AppArmor | The output should be:


Prompt:
Complete this yaml code:

kubectl create -f /dev/stdin <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: hello-apparmor-2
spec:
  securityContext:

Response:
    appArmorProfile:
      type: Localhost
      localhostProfile: k8s-apparmor-example-allow-write
  containers:
  - name: hello
    image: busybox:1.28
    command: [ "sh", "-c", "echo 'Hello AppArmor!' && sleep 1h" ]
EOF

Context: 4.3 - Restrict a Container's Access to Resources with AppArmor | Although the Pod was created successfully, further examination will show that it is stuck in pending:


Prompt:
Explain this yaml code:

kubectl create -f /dev/stdin <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: hello-apparmor-2
spec:
  securityContext:
    appArmorProfile:
      type: Localhost
      localhostProfile: k8s-apparmor-example-allow-write
  containers:
  - name: hello
    image: busybox:1.28
    command: [ "sh", "-c", "echo 'Hello AppArmor!' && sleep 1h" ]
EOF

Response: This yaml code 4.3 - Restrict a Container's Access to Resources with AppArmor | Although the Pod was created successfully, further examination will show that it is stuck in pending:


Prompt:
Complete this text code:

pods/security/seccomp/profiles/audit.json
{

Response:
    "defaultAction": "SCMP_ACT_LOG"
}

Context: 4.4 - Restrict a Container's Syscalls with seccomp | pods/security/seccomp/profiles/violation.json { "defaultAction": "SCMP_ACT_ERRNO" }


Prompt:
Explain this text code:

pods/security/seccomp/profiles/audit.json
{
    "defaultAction": "SCMP_ACT_LOG"
}

Response: This text code 4.4 - Restrict a Container's Syscalls with seccomp | pods/security/seccomp/profiles/violation.json { "defaultAction": "SCMP_ACT_ERRNO" }


Prompt:
Complete this text code:

pods/security/seccomp/profiles/violation.json
{

Response:
    "defaultAction": "SCMP_ACT_ERRNO"
}

Context: 4.4 - Restrict a Container's Syscalls with seccomp | pods/security/seccomp/profiles/fine-grained.json { "defaultAction": "SCMP_ACT_ERRNO", "architectures": [ "SCMP_ARCH_X86_64", "SCMP_ARCH_X86", "SCMP_ARCH_X32" ],


Prompt:
Explain this text code:

pods/security/seccomp/profiles/violation.json
{
    "defaultAction": "SCMP_ACT_ERRNO"
}

Response: This text code 4.4 - Restrict a Container's Syscalls with seccomp | pods/security/seccomp/profiles/fine-grained.json { "defaultAction": "SCMP_ACT_ERRNO", "architectures": [ "SCMP_ARCH_X86_64", "SCMP_ARCH_X86", "SCMP_ARCH_X32" ],


Prompt:
Complete this text code:

pods/security/seccomp/profiles/fine-grained.json
{
    "defaultAction": "SCMP_ACT_ERRNO",
    "architectures": [
        "SCMP_ARCH_X86_64",
        "SCMP_ARCH_X86",
        "SCMP_ARCH_X32"
    ],
    "syscalls": [
        {
            "names": [
                "accept4",
                "epoll_wait",
                "pselect6",
                "futex",
                "madvise",
                "epoll_ctl",
                "getsockname",
                "setsockopt",
                "vfork",
                "mmap",
                "read",
                "write",
                "close",
                "arch_prctl",
                "sched_getaffinity",
                "munmap",
                "brk",
                "rt_sigaction",
                "rt_sigprocmask",
                "sigaltstack",
                "gettid",
                "clone",
                "bind",
                "socket",

Response:
                "openat",
                "readlinkat",
                "exit_group",
                "epoll_create1",
                "listen",
                "rt_sigreturn",
                "sched_yield",
                "clock_gettime",
                "connect",
                "dup2",
                "epoll_pwait",
                "execve",
                "exit",
                "fcntl",
                "getpid",
                "getuid",
                "ioctl",
                "mprotect",
                "nanosleep",
                "open",
                "poll",
                "recvfrom",
                "sendto",
                "set_tid_address",
                "setitimer",
                "writev",
                "fstatfs",
                "getdents64",
                "pipe2",
                "getrlimit"
            ],
            "action": "SCMP_ACT_ALLOW"
        }
    ]
}

Context: 4.4 - Restrict a Container's Syscalls with seccomp | Run these commands:


Prompt:
Explain this text code:

pods/security/seccomp/profiles/fine-grained.json
{
    "defaultAction": "SCMP_ACT_ERRNO",
    "architectures": [
        "SCMP_ARCH_X86_64",
        "SCMP_ARCH_X86",
        "SCMP_ARCH_X32"
    ],
    "syscalls": [
        {
            "names": [
                "accept4",
                "epoll_wait",
                "pselect6",
                "futex",
                "madvise",
                "epoll_ctl",
                "getsockname",
                "setsockopt",
                "vfork",
                "mmap",
                "read",
                "write",
                "close",
                "arch_prctl",
                "sched_getaffinity",
                "munmap",
                "brk",
                "rt_sigaction",
                "rt_sigprocmask",
                "sigaltstack",
                "gettid",
                "clone",
                "bind",
                "socket",
                "openat",
                "readlinkat",
                "exit_group",
                "epoll_create1",
                "listen",
                "rt_sigreturn",
                "sched_yield",
                "clock_gettime",
                "connect",
                "dup2",
                "epoll_pwait",
                "execve",
                "exit",
                "fcntl",
                "getpid",
                "getuid",
                "ioctl",
                "mprotect",
                "nanosleep",
                "open",
                "poll",
                "recvfrom",
                "sendto",
                "set_tid_address",
                "setitimer",
                "writev",
                "fstatfs",
                "getdents64",
                "pipe2",
                "getrlimit"
            ],
            "action": "SCMP_ACT_ALLOW"
        }
    ]
}

Response: This text code 4.4 - Restrict a Container's Syscalls with seccomp | Run these commands:


Prompt:
Complete this json code:

{
    "defaultAction": "SCMP_ACT_ERRNO",
    "architectures": [
        "SCMP_ARCH_X86_64",
        "SCMP_ARCH_X86",
        "SCMP_ARCH_X32"
    ],
    "syscalls": [
        {
            "names": [
                "accept4",
                "epoll_wait",
                "pselect6",
                "futex",
                "madvise",
                "epoll_ctl",
                "getsockname",
                "setsockopt",
                "vfork",
                "mmap",
                "read",
                "write",
                "close",
                "arch_prctl",
                "sched_getaffinity",
                "munmap",
                "brk",
                "rt_sigaction",
                "rt_sigprocmask",
                "sigaltstack",
                "gettid",
                "clone",
                "bind",
                "socket",

Response:
                "openat",
                "readlinkat",
                "exit_group",
                "epoll_create1",
                "listen",
                "rt_sigreturn",
                "sched_yield",
                "clock_gettime",
                "connect",
                "dup2",
                "epoll_pwait",
                "execve",
                "exit",
                "fcntl",
                "getpid",
                "getuid",
                "ioctl",
                "mprotect",
                "nanosleep",
                "open",
                "poll",
                "recvfrom",
                "sendto",
                "set_tid_address",
                "setitimer",
                "writev",
                "fstatfs",
                "getdents64",
                "pipe2",
                "getrlimit"
            ],
            "action": "SCMP_ACT_ALLOW"
        }
    ]
}