Prompt:
Explain this text code:

export KUBECONFIG="${KUBECONFIG}:config-demo:config-demo-2"

Response: This text code 10.3 - Configure Access to Multiple Clusters | In your config-exercise directory, enter this command:

Context: 10.3 - Configure Access to Multiple Clusters | In your config-exercise directory, enter this command:


Prompt:
Complete this text code:

contexts:
- context:
    cluster: development
    namespace: frontend
    user: developer
  name: dev-frontend
- context:
    cluster: development
    namespace: ramp
    user: developer

Response:
  name: dev-ramp-up
- context:
    cluster: development
    namespace: storage
    user: developer
  name: dev-storage
- context:
    cluster: test
    namespace: default
    user: experimenter
  name: exp-test

Context: 10.3 - Configure Access to Multiple Clusters | For more information about how kubeconfig files are merged, see Organizing Cluster Access Using kubeconfig Files


Prompt:
Explain this text code:

contexts:
- context:
    cluster: development
    namespace: frontend
    user: developer
  name: dev-frontend
- context:
    cluster: development
    namespace: ramp
    user: developer
  name: dev-ramp-up
- context:
    cluster: development
    namespace: storage
    user: developer
  name: dev-storage
- context:
    cluster: test
    namespace: default
    user: experimenter
  name: exp-test

Response: This text code 10.3 - Configure Access to Multiple Clusters | For more information about how kubeconfig files are merged, see Organizing Cluster Access Using kubeconfig Files


Prompt:
Explain this text code:

export KUBECONFIG="${KUBECONFIG}:${HOME}/.kube/config"

Response: This text code 10.3 - Configure Access to Multiple Clusters | View configuration information merged from all the files that are now listed in your KUBECONFIG environment variable. In your config-exercise directory, enter:

Context: 10.3 - Configure Access to Multiple Clusters | View configuration information merged from all the files that are now listed in your KUBECONFIG environment variable. In your config-exercise directory, enter:


Prompt:
Explain this text code:

$Env:KUBECONFIG="$Env:KUBECONFIG;$HOME\.kube\config"

Response: This text code 10.3 - Configure Access to Multiple Clusters | View configuration information merged from all the files that are now listed in your KUBECONFIG environment variable. In your config-exercise directory, enter:


Prompt:
Explain this bash code:

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

Response: This bash code 10.4 - Use Port Forwarding to Access Applications in a Cluster | The output of a successful command verifies that the deployment was created:

Context: 10.4 - Use Port Forwarding to Access Applications in a Cluster | The output of a successful command verifies that the deployment was created:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/application/mongodb/mongo-service.yaml

Response: This bash code 10.4 - Use Port Forwarding to Access Applications in a Cluster | The output of a successful command verifies that the Service was created:

Context: 10.4 - Use Port Forwarding to Access Applications in a Cluster | The output of a successful command verifies that the Service was created:


Prompt:
Explain this text code:

# Change mongo-75f59d57f4-4nd6q to the name of the Pod
kubectl get pod mongo-75f59d57f4-4nd6q --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'

Response: This text code 10.4 - Use Port Forwarding to Access Applications in a Cluster | The output displays the port for MongoDB in that Pod:

Context: 10.4 - Use Port Forwarding to Access Applications in a Cluster | The output displays the port for MongoDB in that Pod:


Prompt:
Explain this text code:

# Change mongo-75f59d57f4-4nd6q to the name of the Pod
kubectl port-forward mongo-75f59d57f4-4nd6q 28015:27017

Response: This text code 10.4 - Use Port Forwarding to Access Applications in a Cluster | which is the same as

Context: 10.4 - Use Port Forwarding to Access Applications in a Cluster | which is the same as


Prompt:
Explain this bash code:

kubectl port-forward pods/mongo-75f59d57f4-4nd6q 28015:27017

Response: This bash code 10.4 - Use Port Forwarding to Access Applications in a Cluster | or

Context: 10.4 - Use Port Forwarding to Access Applications in a Cluster | or


Prompt:
Explain this bash code:

kubectl port-forward replicaset/mongo-75f59d57f4 28015:27017

Response: This bash code 10.4 - Use Port Forwarding to Access Applications in a Cluster | or


Prompt:
Complete this yaml code:

service/access/hello-application.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  selector:
    matchLabels:
      run: load-balancer-example
  replicas: 2

Response:
  template:
    metadata:
      labels:
        run: load-balancer-example
    spec:
      containers:
        - name: hello-world
          image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:2.0
          ports:
            - containerPort: 8080
              protocol: TCP

Context: 10.5 - Use a Service to Access an Application in a Cluster | Run a Hello World application in your cluster: Create the application Deployment using the file above:


Prompt:
Explain this yaml code:

service/access/hello-application.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  selector:
    matchLabels:
      run: load-balancer-example
  replicas: 2
  template:
    metadata:
      labels:
        run: load-balancer-example
    spec:
      containers:
        - name: hello-world
          image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:2.0
          ports:
            - containerPort: 8080
              protocol: TCP

Response: This yaml code 10.5 - Use a Service to Access an Application in a Cluster | Run a Hello World application in your cluster: Create the application Deployment using the file above:


Prompt:
Complete this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  selector:
    matchLabels:
      run: load-balancer-example
  replicas: 2
  template:

Response:
    metadata:
      labels:
        run: load-balancer-example
    spec:
      containers:
        - name: hello-world
          image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:2.0
          ports:
            - containerPort: 8080
              protocol: TCP


Prompt:
Explain this yaml code:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  selector:
    matchLabels:
      run: load-balancer-example
  replicas: 2
  template:
    metadata:
      labels:
        run: load-balancer-example
    spec:
      containers:
        - name: hello-world
          image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:2.0
          ports:
            - containerPort: 8080
              protocol: TCP

Response: This yaml code 10.5 - Use a Service to Access an Application in a Cluster | Run a Hello World application in your cluster: Create the application Deployment using the file above:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/service/access/hello-application.yaml

Response: This bash code 10.5 - Use a Service to Access an Application in a Cluster | The preceding command creates a Deployment and an associated ReplicaSet. The ReplicaSet has two Pods each of which runs the Hello World application.

Context: 10.5 - Use a Service to Access an Application in a Cluster | The preceding command creates a Deployment and an associated ReplicaSet. The ReplicaSet has two Pods each of which runs the Hello World application.


Prompt:
Explain this bash code:

kubectl get deployments hello-world
kubectl describe deployments hello-world

Response: This bash code 10.5 - Use a Service to Access an Application in a Cluster | Display information about your ReplicaSet objects:

Context: 10.5 - Use a Service to Access an Application in a Cluster | Display information about your ReplicaSet objects:


Prompt:
Explain this bash code:

kubectl get replicasets
kubectl describe replicasets

Response: This bash code 10.5 - Use a Service to Access an Application in a Cluster | Create a Service object that exposes the deployment:

Context: 10.5 - Use a Service to Access an Application in a Cluster | Create a Service object that exposes the deployment:


Prompt:
Explain this bash code:

kubectl expose deployment hello-world --type=NodePort --name=example-service

Response: This bash code 10.5 - Use a Service to Access an Application in a Cluster | Display information about the Service:

Context: 10.5 - Use a Service to Access an Application in a Cluster | Display information about the Service:


Prompt:
Explain this bash code:

kubectl get pods --selector="run=load-balancer-example" --output=wide

Response: This bash code 10.5 - Use a Service to Access an Application in a Cluster | The output is similar to this:

Context: 10.5 - Use a Service to Access an Application in a Cluster | The output is similar to this:


Prompt:
Complete this yaml code:

service/access/backend-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  selector:
    matchLabels:
      app: hello
      tier: backend
      track: stable
  replicas: 3

Response:
  template:
    metadata:
      labels:
        app: hello
        tier: backend
        track: stable
    spec:
      containers:
        - name: hello
          image: "gcr.io/google-samples/hello-go-gke:1.0"
          ports:
            - name: http
              containerPort: 80
...

Context: 10.6 - Connect a Frontend to a Backend Using Services | Create the backend Deployment:


Prompt:
Explain this yaml code:

service/access/backend-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  selector:
    matchLabels:
      app: hello
      tier: backend
      track: stable
  replicas: 3
  template:
    metadata:
      labels:
        app: hello
        tier: backend
        track: stable
    spec:
      containers:
        - name: hello
          image: "gcr.io/google-samples/hello-go-gke:1.0"
          ports:
            - name: http
              containerPort: 80
...

Response: This yaml code 10.6 - Connect a Frontend to a Backend Using Services | Create the backend Deployment:


Prompt:
Complete this yaml code:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  selector:
    matchLabels:
      app: hello
      tier: backend
      track: stable
  replicas: 3
  template:

Response:
    metadata:
      labels:
        app: hello
        tier: backend
        track: stable
    spec:
      containers:
        - name: hello
          image: "gcr.io/google-samples/hello-go-gke:1.0"
          ports:
            - name: http
              containerPort: 80
...


Prompt:
Explain this yaml code:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  selector:
    matchLabels:
      app: hello
      tier: backend
      track: stable
  replicas: 3
  template:
    metadata:
      labels:
        app: hello
        tier: backend
        track: stable
    spec:
      containers:
        - name: hello
          image: "gcr.io/google-samples/hello-go-gke:1.0"
          ports:
            - name: http
              containerPort: 80
...

Response: This yaml code 10.6 - Connect a Frontend to a Backend Using Services | Create the backend Deployment:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/service/access/backend-deployment.yaml

Response: This bash code 10.6 - Connect a Frontend to a Backend Using Services | View information about the backend Deployment:

Context: 10.6 - Connect a Frontend to a Backend Using Services | View information about the backend Deployment:


Prompt:
Complete this yaml code:

service/access/backend-service.yaml
---
apiVersion: v1
kind: Service
metadata:
  name: hello
spec:

Response:
  selector:
    app: hello
    tier: backend
  ports:
  - protocol: TCP
    port: 80
    targetPort: http
...

Context: 10.6 - Connect a Frontend to a Backend Using Services | In the configuration file, you can see that the Service, named hello routes traffic to Pods that have the labels app: hello and tier: backend.


Prompt:
Explain this yaml code:

service/access/backend-service.yaml
---
apiVersion: v1
kind: Service
metadata:
  name: hello
spec:
  selector:
    app: hello
    tier: backend
  ports:
  - protocol: TCP
    port: 80
    targetPort: http
...

Response: This yaml code 10.6 - Connect a Frontend to a Backend Using Services | In the configuration file, you can see that the Service, named hello routes traffic to Pods that have the labels app: hello and tier: backend.


Prompt:
Complete this yaml code:

---
apiVersion: v1
kind: Service
metadata:
  name: hello
spec:
  selector:

Response:
    app: hello
    tier: backend
  ports:
  - protocol: TCP
    port: 80
    targetPort: http
...


Prompt:
Explain this yaml code:

---
apiVersion: v1
kind: Service
metadata:
  name: hello
spec:
  selector:
    app: hello
    tier: backend
  ports:
  - protocol: TCP
    port: 80
    targetPort: http
...

Response: This yaml code 10.6 - Connect a Frontend to a Backend Using Services | In the configuration file, you can see that the Service, named hello routes traffic to Pods that have the labels app: hello and tier: backend.


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/service/access/backend-service.yaml

Response: This bash code 10.6 - Connect a Frontend to a Backend Using Services | At this point, you have a backend Deployment running three replicas of your hello application, and you have a Service that can route traffic to them. However, this service is neither available nor res

Context: 10.6 - Connect a Frontend to a Backend Using Services | At this point, you have a backend Deployment running three replicas of your hello application, and you have a Service that can route traffic to them. However, this service is neither available nor res


Prompt:
Complete this text code:

service/access/frontend-nginx.conf
# The identifier Backend is internal to nginx, and used to name this specific upstream
upstream Backend {
    # hello is the internal DNS name used by the backend Service inside Kubernetes
    server hello;
}

Response:
server {
listen 80;
location / {
    # The following statement will proxy traffic to the upstream named Backend
    proxy_pass http://Backend;
}
}

Context: 10.6 - Connect a Frontend to a Backend Using Services | server { listen 80;


Prompt:
Explain this text code:

service/access/frontend-nginx.conf
# The identifier Backend is internal to nginx, and used to name this specific upstream
upstream Backend {
    # hello is the internal DNS name used by the backend Service inside Kubernetes
    server hello;
}
server {
listen 80;
location / {
    # The following statement will proxy traffic to the upstream named Backend
    proxy_pass http://Backend;
}
}

Response: This text code 10.6 - Connect a Frontend to a Backend Using Services | server { listen 80;


Prompt:
Complete this yaml code:

service/access/frontend-service.yaml
---
apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  selector:

Response:
    app: hello
    tier: frontend
  ports:
  - protocol: "TCP"
    port: 80
    targetPort: 80
  type: LoadBalancer
...

Context: 10.6 - Connect a Frontend to a Backend Using Services | Create the frontend Deployment and Service:


Prompt:
Explain this yaml code:

service/access/frontend-service.yaml
---
apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  selector:
    app: hello
    tier: frontend
  ports:
  - protocol: "TCP"
    port: 80
    targetPort: 80
  type: LoadBalancer
...

Response: This yaml code 10.6 - Connect a Frontend to a Backend Using Services | Create the frontend Deployment and Service:


Prompt:
Complete this yaml code:

---
apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  selector:

Response:
    app: hello
    tier: frontend
  ports:
  - protocol: "TCP"
    port: 80
    targetPort: 80
  type: LoadBalancer
...


Prompt:
Explain this yaml code:

---
apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  selector:
    app: hello
    tier: frontend
  ports:
  - protocol: "TCP"
    port: 80
    targetPort: 80
  type: LoadBalancer
...

Response: This yaml code 10.6 - Connect a Frontend to a Backend Using Services | Create the frontend Deployment and Service:


Prompt:
Complete this yaml code:

service/access/frontend-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
spec:
  selector:
    matchLabels:
      app: hello
      tier: frontend
      track: stable
  replicas: 1
  template:

Response:
    metadata:
      labels:
        app: hello
        tier: frontend
        track: stable
    spec:
      containers:
        - name: nginx
          image: "gcr.io/google-samples/hello-frontend:1.0"
          lifecycle:
            preStop:
              exec:
                command: ["/usr/sbin/nginx","-s","quit"]
...


Prompt:
Explain this yaml code:

service/access/frontend-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
spec:
  selector:
    matchLabels:
      app: hello
      tier: frontend
      track: stable
  replicas: 1
  template:
    metadata:
      labels:
        app: hello
        tier: frontend
        track: stable
    spec:
      containers:
        - name: nginx
          image: "gcr.io/google-samples/hello-frontend:1.0"
          lifecycle:
            preStop:
              exec:
                command: ["/usr/sbin/nginx","-s","quit"]
...

Response: This yaml code 10.6 - Connect a Frontend to a Backend Using Services | Create the frontend Deployment and Service:


Prompt:
Complete this yaml code:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
spec:
  selector:
    matchLabels:
      app: hello
      tier: frontend
      track: stable
  replicas: 1
  template:

Response:
    metadata:
      labels:
        app: hello
        tier: frontend
        track: stable
    spec:
      containers:
        - name: nginx
          image: "gcr.io/google-samples/hello-frontend:1.0"
          lifecycle:
            preStop:
              exec:
                command: ["/usr/sbin/nginx","-s","quit"]
...


Prompt:
Explain this yaml code:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
spec:
  selector:
    matchLabels:
      app: hello
      tier: frontend
      track: stable
  replicas: 1
  template:
    metadata:
      labels:
        app: hello
        tier: frontend
        track: stable
    spec:
      containers:
        - name: nginx
          image: "gcr.io/google-samples/hello-frontend:1.0"
          lifecycle:
            preStop:
              exec:
                command: ["/usr/sbin/nginx","-s","quit"]
...

Response: This yaml code 10.6 - Connect a Frontend to a Backend Using Services | Create the frontend Deployment and Service:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/service/access/frontend-deployment.yaml
kubectl apply -f https://k8s.io/examples/service/access/frontend-service.yaml

Response: This bash code 10.6 - Connect a Frontend to a Backend Using Services | The output verifies that both resources were created:

Context: 10.6 - Connect a Frontend to a Backend Using Services | The output verifies that both resources were created:


Prompt:
Explain this text code:

curl http://${EXTERNAL_IP} # replace this with the EXTERNAL-IP you saw earlier

Response: This text code 10.6 - Connect a Frontend to a Backend Using Services | The output shows the message generated by the backend:

Context: 10.6 - Connect a Frontend to a Backend Using Services | The output shows the message generated by the backend:


Prompt:
Complete this yaml code:

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

Response:
  selector:
    app: example
  ports:
    - port: 8765
      targetPort: 9376
  type: LoadBalancer

Context: 10.7 - Create an External Load Balancer | You can alternatively create the service with the kubectl expose command and its --type=LoadBalancer flag:


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  name: example-service
spec:
  selector:
    app: example
  ports:
    - port: 8765
      targetPort: 9376
  type: LoadBalancer

Response: This yaml code 10.7 - Create an External Load Balancer | You can alternatively create the service with the kubectl expose command and its --type=LoadBalancer flag:


Prompt:
Explain this bash code:

kubectl expose deployment example --port=8765 --target-port=9376 \
        --name=example-service --type=LoadBalancer

Response: This bash code 10.7 - Create an External Load Balancer | This command creates a new Service using the same selectors as the referenced resource (in the case of the example above, a Deployment named example).

Context: 10.7 - Create an External Load Balancer | This command creates a new Service using the same selectors as the referenced resource (in the case of the example above, a Deployment named example).


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Service
metadata:
  name: example-service
spec:
  selector:

Response:
    app: example
  ports:
    - port: 8765
      targetPort: 9376
  externalTrafficPolicy: Local
  type: LoadBalancer

Context: 10.7 - Create an External Load Balancer | Load balancing services from some cloud providers do not let you configure different weights for each target.


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Service
metadata:
  name: example-service
spec:
  selector:
    app: example
  ports:
    - port: 8765
      targetPort: 9376
  externalTrafficPolicy: Local
  type: LoadBalancer

Response: This yaml code 10.7 - Create an External Load Balancer | Load balancing services from some cloud providers do not let you configure different weights for each target.


Prompt:
Complete this bash code:

kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec['initContainers', 'containers'][*].image}" |\
tr -s '[[:space:]]' '\n' |\

Response:
sort |\
uniq -c

Context: 10.8 - List All Container Images Running in a Cluster | The jsonpath is interpreted as follows:


Prompt:
Explain this bash code:

kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec['initContainers', 'containers'][*].image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c

Response: This bash code 10.8 - List All Container Images Running in a Cluster | The jsonpath is interpreted as follows:


Prompt:
Explain this bash code:

kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |\
sort

Response: This bash code 10.8 - List All Container Images Running in a Cluster | To target only Pods matching a specific label, use the -l flag. The following matches only Pods with labels matching app=nginx.

Context: 10.8 - List All Container Images Running in a Cluster | To target only Pods matching a specific label, use the -l flag. The following matches only Pods with labels matching app=nginx.


Prompt:
Explain this bash code:

kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}" -l app=nginx

Response: This bash code 10.8 - List All Container Images Running in a Cluster | To target only pods in a specific namespace, use the namespace flag. The following matches only Pods in the kube-system namespace.

Context: 10.8 - List All Container Images Running in a Cluster | To target only pods in a specific namespace, use the namespace flag. The following matches only Pods in the kube-system namespace.


Prompt:
Explain this bash code:

kubectl get pods --namespace kube-system -o jsonpath="{.items[*].spec.containers[*].image}"

Response: This bash code 10.8 - List All Container Images Running in a Cluster | As an alternative to jsonpath, Kubectl supports using go-templates for formatting the output:

Context: 10.8 - List All Container Images Running in a Cluster | As an alternative to jsonpath, Kubectl supports using go-templates for formatting the output:


Prompt:
Explain this bash code:

kubectl get pods --all-namespaces -o go-template --template="{{range .items}}{{range .spec.containers}}{{.image}} {{end}}{{end}}"

Response: This bash code 10.8 - List All Container Images Running in a Cluster | An Ingress is an API object that defines rules which allow external access to services in a cluster. An Ingress controller fulfills the rules set in the Ingress.

Context: 10.8 - List All Container Images Running in a Cluster | An Ingress is an API object that defines rules which allow external access to services in a cluster. An Ingress controller fulfills the rules set in the Ingress.


Prompt:
Explain this bash code:

kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0

Response: This bash code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | The output should be:

Context: 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | The output should be:


Prompt:
Explain this bash code:

kubectl expose deployment web --type=NodePort --port=8080

Response: This bash code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | The output should be:


Prompt:
Explain this text code:

# The command must be run in a separate terminal.
minikube service web --url

Response: This text code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | The output is similar to:

Context: 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | The output is similar to:


Prompt:
Complete this yaml code:

service/networking/example-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
spec:
  ingressClassName: nginx
  rules:
    - host: hello-world.example

Response:
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 8080

Context: 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | Create the Ingress object by running the following command:


Prompt:
Explain this yaml code:

service/networking/example-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
spec:
  ingressClassName: nginx
  rules:
    - host: hello-world.example
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 8080

Response: This yaml code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | Create the Ingress object by running the following command:


Prompt:
Complete this yaml code:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
spec:
  ingressClassName: nginx
  rules:
    - host: hello-world.example

Response:
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 8080


Prompt:
Explain this yaml code:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
spec:
  ingressClassName: nginx
  rules:
    - host: hello-world.example
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 8080

Response: This yaml code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | Create the Ingress object by running the following command:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/service/networking/example-ingress.yaml

Response: This bash code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | The output should be:


Prompt:
Explain this text code:

curl --resolve "hello-world.example:80:$( minikube ip )" -i http://hello-world.example

Response: This text code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | minikube tunnel The output is similar to:Tunnel successfully started NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ... The service/ingress e

Context: 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | minikube tunnel The output is similar to:Tunnel successfully started NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ... The service/ingress e


Prompt:
Explain this text code:

curl --resolve "hello-world.example:80:127.0.0.1" -i http://hello-world.example

Response: This text code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | Optionally, you can also visit hello-world.example from your browser.

Context: 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | Optionally, you can also visit hello-world.example from your browser.


Prompt:
Explain this bash code:

kubectl create deployment web2 --image=gcr.io/google-samples/hello-app:2.0

Response: This bash code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | The output should be:


Prompt:
Explain this bash code:

kubectl expose deployment web2 --port=8080 --type=NodePort

Response: This bash code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | The output should be:


Prompt:
Complete this text code:

- path: /v2
  pathType: Prefix
  backend:

Response:
    service:
      name: web2
      port:
        number: 8080

Context: 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | Apply the changes:


Prompt:
Explain this text code:

- path: /v2
  pathType: Prefix
  backend:
    service:
      name: web2
      port:
        number: 8080

Response: This text code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | Apply the changes:


Prompt:
Explain this text code:

curl --resolve "hello-world.example:80:$( minikube ip )" -i http://hello-world.example

Response: This text code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | minikube tunnel The output is similar to:Tunnel successfully started NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ... The service/ingress e


Prompt:
Explain this text code:

curl --resolve "hello-world.example:80:127.0.0.1" -i http://hello-world.example

Response: This text code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | The output is similar to:


Prompt:
Explain this text code:

curl --resolve "hello-world.example:80:$( minikube ip )" -i http://hello-world.example/v2

Response: This text code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | minikube tunnel The output is similar to:Tunnel successfully started NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ... The service/ingress e


Prompt:
Explain this text code:

curl --resolve "hello-world.example:80:127.0.0.1" -i http://hello-world.example/v2

Response: This text code 10.9 - Set up Ingress on Minikube with the NGINX Ingress Controller | The output is similar to:


Prompt:
Complete this yaml code:

pods/two-container-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: two-containers
spec:

  restartPolicy: Never

  volumes:
  - name: shared-data
    emptyDir: {}

  containers:

Response:
  - name: nginx-container
    image: nginx
    volumeMounts:
    - name: shared-data
      mountPath: /usr/share/nginx/html

  - name: debian-container
    image: debian
    volumeMounts:
    - name: shared-data
      mountPath: /pod-data
    command: ["/bin/sh"]
    args: ["-c", "echo Hello from the debian container > /pod-data/index.html"]

Context: 10.10 - Communicate Between Containers in the Same Pod Using a Shared Volume | In the configuration file, you can see that the Pod has a Volume named shared-data.


Prompt:
Explain this yaml code:

pods/two-container-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: two-containers
spec:

  restartPolicy: Never

  volumes:
  - name: shared-data
    emptyDir: {}

  containers:

  - name: nginx-container
    image: nginx
    volumeMounts:
    - name: shared-data
      mountPath: /usr/share/nginx/html

  - name: debian-container
    image: debian
    volumeMounts:
    - name: shared-data
      mountPath: /pod-data
    command: ["/bin/sh"]
    args: ["-c", "echo Hello from the debian container > /pod-data/index.html"]

Response: This yaml code 10.10 - Communicate Between Containers in the Same Pod Using a Shared Volume | In the configuration file, you can see that the Pod has a Volume named shared-data.


Prompt:
Complete this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: two-containers
spec:

  restartPolicy: Never

  volumes:
  - name: shared-data
    emptyDir: {}

  containers:

Response:
  - name: nginx-container
    image: nginx
    volumeMounts:
    - name: shared-data
      mountPath: /usr/share/nginx/html

  - name: debian-container
    image: debian
    volumeMounts:
    - name: shared-data
      mountPath: /pod-data
    command: ["/bin/sh"]
    args: ["-c", "echo Hello from the debian container > /pod-data/index.html"]


Prompt:
Explain this yaml code:

apiVersion: v1
kind: Pod
metadata:
  name: two-containers
spec:

  restartPolicy: Never

  volumes:
  - name: shared-data
    emptyDir: {}

  containers:

  - name: nginx-container
    image: nginx
    volumeMounts:
    - name: shared-data
      mountPath: /usr/share/nginx/html

  - name: debian-container
    image: debian
    volumeMounts:
    - name: shared-data
      mountPath: /pod-data
    command: ["/bin/sh"]
    args: ["-c", "echo Hello from the debian container > /pod-data/index.html"]

Response: This yaml code 10.10 - Communicate Between Containers in the Same Pod Using a Shared Volume | In the configuration file, you can see that the Pod has a Volume named shared-data.


Prompt:
Complete this json code:

{
  "cluster_name" : "kubernetes_logging",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,

Response:
  "active_primary_shards" : 5,
  "active_shards" : 5,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 5
}

Context: 10.12 - Access Services Running on Clusters | To access the https Elasticsearch service health information _cluster/health?pretty=true, you would use:


Prompt:
Explain this json code:

{
  "cluster_name" : "kubernetes_logging",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 5,
  "active_shards" : 5,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 5
}

Response: This json code 10.12 - Access Services Running on Clusters | To access the https Elasticsearch service health information _cluster/health?pretty=true, you would use:


Prompt:
Complete this yaml code:

apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
  name: <name of the registration object>
spec:
  group: <API group name this extension apiserver hosts>

Response:
  version: <API version this extension apiserver hosts>
  groupPriorityMinimum: <priority this APIService for this group, see API documentation>
  versionPriority: <prioritizes ordering of this version within a group, see API documentation>
  service:
    namespace: <namespace of the extension apiserver service>
    name: <name of the extension apiserver service>
  caBundle: <pem encoded ca cert that signs the server cert used by the webhook>

Context: 11.1 - Configure the Aggregation Layer | The name of an APIService object must be a valid path segment name.


Prompt:
Explain this yaml code:

apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
  name: <name of the registration object>
spec:
  group: <API group name this extension apiserver hosts>
  version: <API version this extension apiserver hosts>
  groupPriorityMinimum: <priority this APIService for this group, see API documentation>
  versionPriority: <prioritizes ordering of this version within a group, see API documentation>
  service:
    namespace: <namespace of the extension apiserver service>
    name: <name of the extension apiserver service>
  caBundle: <pem encoded ca cert that signs the server cert used by the webhook>

Response: This yaml code 11.1 - Configure the Aggregation Layer | The name of an APIService object must be a valid path segment name.


Prompt:
Complete this yaml code:

apiVersion: apiregistration.k8s.io/v1
kind: APIService
...
spec:
  ...

Response:
  service:
    namespace: my-service-namespace
    name: my-service-name
    port: 1234
  caBundle: "Ci0tLS0tQk...<base64-encoded PEM bundle>...tLS0K"
...

Context: 11.1 - Configure the Aggregation Layer | This page shows how to install a custom resource into the Kubernetes API by creating a CustomResourceDefinition.


Prompt:
Explain this yaml code:

apiVersion: apiregistration.k8s.io/v1
kind: APIService
...
spec:
  ...
  service:
    namespace: my-service-namespace
    name: my-service-name
    port: 1234
  caBundle: "Ci0tLS0tQk...<base64-encoded PEM bundle>...tLS0K"
...

Response: This yaml code 11.1 - Configure the Aggregation Layer | This page shows how to install a custom resource into the Kubernetes API by creating a CustomResourceDefinition.


Prompt:
Complete this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: crontabs.stable.example.com
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: stable.example.com
  # list of versions supported by this CustomResourceDefinition
  versions:
    - name: v1
      # Each version can be enabled/disabled by Served flag.
      served: true
      # One and only one version must be marked as the storage version.
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:

Response:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: crontabs
    # singular name to be used as an alias on the CLI and for display
    singular: crontab
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: CronTab
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - ct

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and create it:


Prompt:
Explain this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: crontabs.stable.example.com
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: stable.example.com
  # list of versions supported by this CustomResourceDefinition
  versions:
    - name: v1
      # Each version can be enabled/disabled by Served flag.
      served: true
      # One and only one version must be marked as the storage version.
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: crontabs
    # singular name to be used as an alias on the CLI and for display
    singular: crontab
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: CronTab
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - ct

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and create it:


Prompt:
Complete this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:

Response:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image


Prompt:
Explain this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and create it:


Prompt:
Complete this yaml code:

apiVersion: v1
items:
- apiVersion: stable.example.com/v1
  kind: CronTab
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"stable.example.com/v1","kind":"CronTab","metadata":{"annotations":{},"name":"my-new-cron-object","namespace":"default"},"spec":{"cronSpec":"* * * * */5","image":"my-awesome-cron-image"}}
    creationTimestamp: "2021-06-20T07:35:27Z"
    generation: 1

Response:
    name: my-new-cron-object
    namespace: default
    resourceVersion: "1326"
    uid: 9aab1d66-628e-41bb-a422-57b8b3b1f5a9
  spec:
    cronSpec: '* * * * */5'
    image: my-awesome-cron-image
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | When you delete a CustomResourceDefinition, the server will uninstall the RESTful API endpoint and delete all custom objects stored in it.


Prompt:
Explain this yaml code:

apiVersion: v1
items:
- apiVersion: stable.example.com/v1
  kind: CronTab
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"stable.example.com/v1","kind":"CronTab","metadata":{"annotations":{},"name":"my-new-cron-object","namespace":"default"},"spec":{"cronSpec":"* * * * */5","image":"my-awesome-cron-image"}}
    creationTimestamp: "2021-06-20T07:35:27Z"
    generation: 1
    name: my-new-cron-object
    namespace: default
    resourceVersion: "1326"
    uid: 9aab1d66-628e-41bb-a422-57b8b3b1f5a9
  spec:
    cronSpec: '* * * * */5'
    image: my-awesome-cron-image
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | When you delete a CustomResourceDefinition, the server will uninstall the RESTful API endpoint and delete all custom objects stored in it.


Prompt:
Explain this bash code:

kubectl delete -f resourcedefinition.yaml
kubectl get crontabs

Response: This bash code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If you later recreate the same CustomResourceDefinition, it will start out empty.

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If you later recreate the same CustomResourceDefinition, it will start out empty.


Prompt:
Complete this text code:

properties:
  foo:
    # ...

Response:
allOf:
- properties:
    foo:
      # ...

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Non-structural example 2:


Prompt:
Explain this text code:

properties:
  foo:
    # ...
allOf:
- properties:
    foo:
      # ...

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Non-structural example 2:


Prompt:
Complete this text code:

allOf:
- items:

Response:
    properties:
      foo:
        # ...

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | conflicts with rule 2. The following would be correct:


Prompt:
Explain this text code:

allOf:
- items:
    properties:
      foo:
        # ...

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | conflicts with rule 2. The following would be correct:


Prompt:
Complete this text code:

items:
  properties:
    foo:
      # ...

Response:
allOf:
- items:
    properties:
      foo:
        # ...

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Non-structural example 3:


Prompt:
Explain this text code:

items:
  properties:
    foo:
      # ...
allOf:
- items:
    properties:
      foo:
        # ...

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Non-structural example 3:


Prompt:
Complete this text code:

properties:
  foo:
    pattern: "abc"
  metadata:
    type: object
    properties:
      name:
        type: string
        pattern: "^a"
      finalizers:

Response:
        type: array
        items:
          type: string
          pattern: "my-finalizer"
anyOf:
- properties:
    bar:
      type: integer
      minimum: 42
  required: ["bar"]
  description: "foo bar object"

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | is not a structural schema because of the following violations:


Prompt:
Explain this text code:

properties:
  foo:
    pattern: "abc"
  metadata:
    type: object
    properties:
      name:
        type: string
        pattern: "^a"
      finalizers:
        type: array
        items:
          type: string
          pattern: "my-finalizer"
anyOf:
- properties:
    bar:
      type: integer
      minimum: 42
  required: ["bar"]
  description: "foo bar object"

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | is not a structural schema because of the following violations:


Prompt:
Complete this text code:

type: object
description: "foo bar object"
properties:
  foo:
    type: string
    pattern: "abc"
  bar:
    type: integer
  metadata:

Response:
    type: object
    properties:
      name:
        type: string
        pattern: "^a"
anyOf:
- properties:
    bar:
      minimum: 42
  required: ["bar"]

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Violations of the structural schema rules are reported in the NonStructural condition in the CustomResourceDefinition.


Prompt:
Explain this text code:

type: object
description: "foo bar object"
properties:
  foo:
    type: string
    pattern: "abc"
  bar:
    type: integer
  metadata:
    type: object
    properties:
      name:
        type: string
        pattern: "^a"
anyOf:
- properties:
    bar:
      minimum: 42
  required: ["bar"]

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Violations of the structural schema rules are reported in the NonStructural condition in the CustomResourceDefinition.


Prompt:
Complete this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object

Response:
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image
  someRandomField: 42


Prompt:
Explain this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image
  someRandomField: 42

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and create it:


Prompt:
Explain this bash code:

kubectl create --validate=false -f my-crontab.yaml -o yaml

Response: This bash code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Your output is similar to:

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Your output is similar to:


Prompt:
Complete this yaml code:

apiVersion: stable.example.com/v1
kind: CronTab
metadata:
  creationTimestamp: 2017-05-31T12:56:35Z
  generation: 1
  name: my-new-cron-object

Response:
  namespace: default
  resourceVersion: "285"
  uid: 9423255b-4600-11e7-af6a-28d2447dc82b
spec:
  cronSpec: '* * * * */5'
  image: my-awesome-cron-image

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Notice that the field someRandomField was pruned.


Prompt:
Explain this yaml code:

apiVersion: stable.example.com/v1
kind: CronTab
metadata:
  creationTimestamp: 2017-05-31T12:56:35Z
  generation: 1
  name: my-new-cron-object
  namespace: default
  resourceVersion: "285"
  uid: 9423255b-4600-11e7-af6a-28d2447dc82b
spec:
  cronSpec: '* * * * */5'
  image: my-awesome-cron-image

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Notice that the field someRandomField was pruned.


Prompt:
Complete this text code:

type: object
properties:

Response:
  json:
    x-kubernetes-preserve-unknown-fields: true

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | The field json can store any JSON value, without anything being pruned.


Prompt:
Explain this text code:

type: object
properties:
  json:
    x-kubernetes-preserve-unknown-fields: true

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | The field json can store any JSON value, without anything being pruned.


Prompt:
Complete this text code:

type: object
properties:
  json:

Response:
    x-kubernetes-preserve-unknown-fields: true
    type: object
    description: this is arbitrary JSON

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | With this, only object type values are allowed.


Prompt:
Explain this text code:

type: object
properties:
  json:
    x-kubernetes-preserve-unknown-fields: true
    type: object
    description: this is arbitrary JSON

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | With this, only object type values are allowed.


Prompt:
Complete this text code:

type: object
properties:
  json:
    x-kubernetes-preserve-unknown-fields: true
    type: object
    properties:

Response:
      spec:
        type: object
        properties:
          foo:
            type: string
          bar:
            type: string

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | With this, the value:


Prompt:
Explain this text code:

type: object
properties:
  json:
    x-kubernetes-preserve-unknown-fields: true
    type: object
    properties:
      spec:
        type: object
        properties:
          foo:
            type: string
          bar:
            type: string

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | With this, the value:


Prompt:
Complete this text code:

json:
  spec:
    foo: abc

Response:
    bar: def
    something: x
  status:
    something: x

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | is pruned to:


Prompt:
Explain this text code:

json:
  spec:
    foo: abc
    bar: def
    something: x
  status:
    something: x

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | is pruned to:


Prompt:
Complete this text code:

json:
  spec:
    foo: abc

Response:
    bar: def
  status:
    something: x

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | This means that the something field in the specified spec object is pruned, but everything outside is not.


Prompt:
Explain this text code:

json:
  spec:
    foo: abc
    bar: def
  status:
    something: x

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | This means that the something field in the specified spec object is pruned, but everything outside is not.


Prompt:
Complete this text code:

type: object
properties:

Response:
  foo:
    x-kubernetes-int-or-string: true

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Also those nodes are partially excluded from rule 3 in the sense that the following two patterns are allowed (exactly those, without variations in order to additional fields):


Prompt:
Explain this text code:

type: object
properties:
  foo:
    x-kubernetes-int-or-string: true

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Also those nodes are partially excluded from rule 3 in the sense that the following two patterns are allowed (exactly those, without variations in order to additional fields):


Prompt:
Complete this text code:

x-kubernetes-int-or-string: true
anyOf:

Response:
  - type: integer
  - type: string
...

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and


Prompt:
Explain this text code:

x-kubernetes-int-or-string: true
anyOf:
  - type: integer
  - type: string
...

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and


Prompt:
Complete this text code:

x-kubernetes-int-or-string: true
allOf:
  - anyOf:

Response:
      - type: integer
      - type: string
  - # ... zero or more
...

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | With one of those specification, both an integer and a string validate.


Prompt:
Explain this text code:

x-kubernetes-int-or-string: true
allOf:
  - anyOf:
      - type: integer
      - type: string
  - # ... zero or more
...

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | With one of those specification, both an integer and a string validate.


Prompt:
Complete this text code:

type: object
properties:

Response:
  foo:
    x-kubernetes-embedded-resource: true
    x-kubernetes-preserve-unknown-fields: true

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Here, the field foo holds a complete object, e.g.:


Prompt:
Explain this text code:

type: object
properties:
  foo:
    x-kubernetes-embedded-resource: true
    x-kubernetes-preserve-unknown-fields: true

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Here, the field foo holds a complete object, e.g.:


Prompt:
Complete this yaml code:

foo:
  apiVersion: v1

Response:
  kind: Pod
  spec:
    # ...

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Because x-kubernetes-preserve-unknown-fields: true is specified alongside, nothing is pruned. The use of x-kubernetes-preserve-unknown-fields: true is optional though.


Prompt:
Explain this yaml code:

foo:
  apiVersion: v1
  kind: Pod
  spec:
    # ...

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Because x-kubernetes-preserve-unknown-fields: true is specified alongside, nothing is pruned. The use of x-kubernetes-preserve-unknown-fields: true is optional though.


Prompt:
Complete this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab

Response:
metadata:
  finalizers:
  - stable.example.com/finalizer

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Identifiers of custom finalizers consist of a domain name, a forward slash and the name of the finalizer. Any controller can add a finalizer to any object's list of finalizers.


Prompt:
Explain this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  finalizers:
  - stable.example.com/finalizer

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Identifiers of custom finalizers consist of a domain name, a forward slash and the name of the finalizer. Any controller can add a finalizer to any object's list of finalizers.


Prompt:
Complete this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        # openAPIV3Schema is the schema for validating custom objects.
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object

Response:
              properties:
                cronSpec:
                  type: string
                  pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
                image:
                  type: string
                replicas:
                  type: integer
                  minimum: 1
                  maximum: 10
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and create it:


Prompt:
Explain this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        # openAPIV3Schema is the schema for validating custom objects.
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                  pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
                image:
                  type: string
                replicas:
                  type: integer
                  minimum: 1
                  maximum: 10
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and create it:


Prompt:
Complete this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object

Response:
spec:
  cronSpec: "* * * *"
  image: my-awesome-cron-image
  replicas: 15

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and attempt to create it:


Prompt:
Explain this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "* * * *"
  image: my-awesome-cron-image
  replicas: 15

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and attempt to create it:


Prompt:
Complete this text code:

The CronTab "my-new-cron-object" is invalid: []: Invalid value: map[string]interface {}{"apiVersion":"stable.example.com/v1", "kind":"CronTab", "metadata":map[string]interface {}{"name":"my-new-cron-object", "namespace":"default", "deletionTimestamp":interface {}(nil), "deletionGracePeriodSeconds":(*int64)(nil), "creationTimestamp":"2017-09-05T05:20:07Z", "uid":"e14d79e7-91f9-11e7-a598-f0761cb232d1", "clusterName":""}, "spec":map[string]interface {}{"cronSpec":"* * * *", "image":"my-awesome-cron-image", "replicas":15}}:
validation failure list:

Response:
spec.cronSpec in body should match '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
spec.replicas in body should be less than or equal to 10

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If the fields contain valid values, the object creation request is accepted.


Prompt:
Explain this text code:

The CronTab "my-new-cron-object" is invalid: []: Invalid value: map[string]interface {}{"apiVersion":"stable.example.com/v1", "kind":"CronTab", "metadata":map[string]interface {}{"name":"my-new-cron-object", "namespace":"default", "deletionTimestamp":interface {}(nil), "deletionGracePeriodSeconds":(*int64)(nil), "creationTimestamp":"2017-09-05T05:20:07Z", "uid":"e14d79e7-91f9-11e7-a598-f0761cb232d1", "clusterName":""}, "spec":map[string]interface {}{"cronSpec":"* * * *", "image":"my-awesome-cron-image", "replicas":15}}:
validation failure list:
spec.cronSpec in body should match '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
spec.replicas in body should be less than or equal to 10

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If the fields contain valid values, the object creation request is accepted.


Prompt:
Complete this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object

Response:
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image
  replicas: 5

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | And create it:


Prompt:
Explain this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image
  replicas: 5

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | And create it:


Prompt:
Explain this bash code:

kubectl apply -f my-crontab.yaml
crontab "my-new-cron-object" created

Response: This bash code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If you are using a version of Kubernetes older than v1.30, you need to explicitly enable the CRDValidationRatcheting feature gate to use this behavior, which then applies to all CustomResourceDefiniti

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If you are using a version of Kubernetes older than v1.30, you need to explicitly enable the CRDValidationRatcheting feature gate to use this behavior, which then applies to all CustomResourceDefiniti


Prompt:
Complete this text code:

# ...
  openAPIV3Schema:
    type: object
    properties:
      spec:
        type: object
        x-kubernetes-validations:
          - rule: "self.minReplicas <= self.replicas"
            message: "replicas should be greater than or equal to minReplicas."
          - rule: "self.replicas <= self.maxReplicas"
            message: "replicas should be smaller than or equal to maxReplicas."

Response:
        properties:
          # ...
          minReplicas:
            type: integer
          replicas:
            type: integer
          maxReplicas:
            type: integer
        required:
          - minReplicas
          - replicas
          - maxReplicas

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | will reject a request to create this custom resource:


Prompt:
Explain this text code:

# ...
  openAPIV3Schema:
    type: object
    properties:
      spec:
        type: object
        x-kubernetes-validations:
          - rule: "self.minReplicas <= self.replicas"
            message: "replicas should be greater than or equal to minReplicas."
          - rule: "self.replicas <= self.maxReplicas"
            message: "replicas should be smaller than or equal to maxReplicas."
        properties:
          # ...
          minReplicas:
            type: integer
          replicas:
            type: integer
          maxReplicas:
            type: integer
        required:
          - minReplicas
          - replicas
          - maxReplicas

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | will reject a request to create this custom resource:


Prompt:
Complete this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object

Response:
spec:
  minReplicas: 0
  replicas: 20
  maxReplicas: 10

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | with the response:


Prompt:
Explain this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  minReplicas: 0
  replicas: 20
  maxReplicas: 10

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | with the response:


Prompt:
Complete this text code:

# ...
  openAPIV3Schema:
    type: object
    x-kubernetes-validations:
      - rule: "self.status.availableReplicas >= self.spec.minReplicas"
    properties:
        spec:
          type: object

Response:
          properties:
            minReplicas:
              type: integer
            # ...
        status:
          type: object
          properties:
            availableReplicas:
              type: integer

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If the Rule is scoped to an object with properties, the accessible properties of the object are field selectable via self.field and field presence can be checked via has(self.field). Null valued field


Prompt:
Explain this text code:

# ...
  openAPIV3Schema:
    type: object
    x-kubernetes-validations:
      - rule: "self.status.availableReplicas >= self.spec.minReplicas"
    properties:
        spec:
          type: object
          properties:
            minReplicas:
              type: integer
            # ...
        status:
          type: object
          properties:
            availableReplicas:
              type: integer

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If the Rule is scoped to an object with properties, the accessible properties of the object are field selectable via self.field and field presence can be checked via has(self.field). Null valued field


Prompt:
Complete this text code:

# ...
  openAPIV3Schema:
    type: object
    properties:
      spec:
        type: object

Response:
        x-kubernetes-validations:
          - rule: "has(self.foo)"
        properties:
          # ...
          foo:
            type: integer

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If the Rule is scoped to an object with additionalProperties (i.e. a map) the value of the map are accessible via self[mapKey], map containment can be checked via mapKey in self and all entries of the


Prompt:
Explain this text code:

# ...
  openAPIV3Schema:
    type: object
    properties:
      spec:
        type: object
        x-kubernetes-validations:
          - rule: "has(self.foo)"
        properties:
          # ...
          foo:
            type: integer

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If the Rule is scoped to an object with additionalProperties (i.e. a map) the value of the map are accessible via self[mapKey], map containment can be checked via mapKey in self and all entries of the


Prompt:
Complete this text code:

# ...
  openAPIV3Schema:
    type: object
    properties:
      spec:
        type: object
        x-kubernetes-validations:

Response:
          - rule: "self['xyz'].foo > 0"
        additionalProperties:
          # ...
          type: object
          properties:
            foo:
              type: integer

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If the Rule is scoped to an array, the elements of the array are accessible via self[i] and also by macros and functions.


Prompt:
Explain this text code:

# ...
  openAPIV3Schema:
    type: object
    properties:
      spec:
        type: object
        x-kubernetes-validations:
          - rule: "self['xyz'].foo > 0"
        additionalProperties:
          # ...
          type: object
          properties:
            foo:
              type: integer

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If the Rule is scoped to an array, the elements of the array are accessible via self[i] and also by macros and functions.


Prompt:
Complete this text code:

# ...
  openAPIV3Schema:
    type: object
    properties:
      # ...

Response:
      foo:
        type: array
        x-kubernetes-validations:
          - rule: "size(self) == 1"
        items:
          type: string

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If the Rule is scoped to a scalar, self is bound to the scalar value.


Prompt:
Explain this text code:

# ...
  openAPIV3Schema:
    type: object
    properties:
      # ...
      foo:
        type: array
        x-kubernetes-validations:
          - rule: "size(self) == 1"
        items:
          type: string

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If the Rule is scoped to a scalar, self is bound to the scalar value.


Prompt:
Complete this text code:

# ...
  openAPIV3Schema:
    type: object
    properties:
      spec:
        type: object

Response:
        properties:
          # ...
          foo:
            type: integer
            x-kubernetes-validations:
            - rule: "self > 0"

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Examples:


Prompt:
Explain this text code:

# ...
  openAPIV3Schema:
    type: object
    properties:
      spec:
        type: object
        properties:
          # ...
          foo:
            type: integer
            x-kubernetes-validations:
            - rule: "self > 0"

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Examples:


Prompt:
Explain this text code:

x-kubernetes-validations:
- rule: "self.x <= self.maxLimit"
  messageExpression: '"x exceeded max limit of " + string(self.maxLimit)'

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Keep in mind that CEL string concatenation (+ operator) does not auto-cast to string. If you have a non-string scalar, use the string(<value>) function to cast the scalar to a string like shown in the

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Keep in mind that CEL string concatenation (+ operator) does not auto-cast to string. If you have a non-string scalar, use the string(<value>) function to cast the scalar to a string like shown in the


Prompt:
Explain this text code:

x-kubernetes-validations:
- rule: "self.x <= self.maxLimit"
  reason: "FieldValueInvalid"

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | The HTTP status code returned to the caller will match the reason of the first failed validation rule. The currently supported reasons are: "FieldValueInvalid", "FieldValueForbidden", "FieldValueRequi

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | The HTTP status code returned to the caller will match the reason of the first failed validation rule. The currently supported reasons are: "FieldValueInvalid", "FieldValueForbidden", "FieldValueRequi


Prompt:
Explain this text code:

x-kubernetes-validations:
- rule: "self.foo.test.x <= self.maxLimit"
  fieldPath: ".foo.test.x"

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | In the example above, the validation checks the value of field x should be less than the value of maxLimit. If no fieldPath specified, when validation fails, the fieldPath would be default to wherever

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | In the example above, the validation checks the value of field x should be less than the value of maxLimit. If no fieldPath specified, when validation fails, the fieldPath would be default to wherever


Prompt:
Complete this text code:

type: string
enum: ["low", "medium", "high"]

Response:
x-kubernetes-validations:
- rule: "!(self == 'high' && oldSelf == 'low') && !(self == 'low' && oldSelf == 'high')"
  message: cannot transition directly between 'low' and 'high'

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Unlike other rules, transition rules apply only to operations meeting the following criteria:


Prompt:
Explain this text code:

type: string
enum: ["low", "medium", "high"]
x-kubernetes-validations:
- rule: "!(self == 'high' && oldSelf == 'low') && !(self == 'low' && oldSelf == 'high')"
  message: cannot transition directly between 'low' and 'high'

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Unlike other rules, transition rules apply only to operations meeting the following criteria:


Prompt:
Complete this text code:

openAPIV3Schema:
  type: object
  properties:
    foo:

Response:
      type: array
      items:
        type: string
      x-kubernetes-validations:
        - rule: "self.all(x, x.contains('a string'))"

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | then the API server rejects this rule on validation budget grounds with error:


Prompt:
Explain this text code:

openAPIV3Schema:
  type: object
  properties:
    foo:
      type: array
      items:
        type: string
      x-kubernetes-validations:
        - rule: "self.all(x, x.contains('a string'))"

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | then the API server rejects this rule on validation budget grounds with error:


Prompt:
Complete this text code:

openAPIV3Schema:
  type: object
  properties:
    foo:
      type: array

Response:
      maxItems: 25
      items:
        type: string
        maxLength: 10
      x-kubernetes-validations:
        - rule: "self.all(x, x.contains('a string'))"

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | The cost estimation system takes into account how many times the rule will be executed in addition to the estimated cost of the rule itself. For instance, the following rule will have the same estimat


Prompt:
Explain this text code:

openAPIV3Schema:
  type: object
  properties:
    foo:
      type: array
      maxItems: 25
      items:
        type: string
        maxLength: 10
      x-kubernetes-validations:
        - rule: "self.all(x, x.contains('a string'))"

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | The cost estimation system takes into account how many times the rule will be executed in addition to the estimated cost of the rule itself. For instance, the following rule will have the same estimat


Prompt:
Complete this text code:

openAPIV3Schema:
  type: object
  properties:
    foo:
      type: array

Response:
      maxItems: 25
      items:
        type: string
        x-kubernetes-validations:
          - rule: "self.contains('a string'))"
        maxLength: 10

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If a list inside of a list has a validation rule that uses self.all, that is significantly more expensive than a non-nested list with the same rule. A rule that would have been allowed on a non-nested


Prompt:
Explain this text code:

openAPIV3Schema:
  type: object
  properties:
    foo:
      type: array
      maxItems: 25
      items:
        type: string
        x-kubernetes-validations:
          - rule: "self.contains('a string'))"
        maxLength: 10

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | If a list inside of a list has a validation rule that uses self.all, that is significantly more expensive than a non-nested list with the same rule. A rule that would have been allowed on a non-nested


Prompt:
Complete this text code:

openAPIV3Schema:
  type: object
  properties:
    foo:

Response:
      type: array
      items:
        type: integer
    x-kubernetes-validations:
      - rule: "self.all(x, x == 5)"

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | But the same rule on the following schema (with a nested array added) produces a validation error:


Prompt:
Explain this text code:

openAPIV3Schema:
  type: object
  properties:
    foo:
      type: array
      items:
        type: integer
    x-kubernetes-validations:
      - rule: "self.all(x, x == 5)"

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | But the same rule on the following schema (with a nested array added) produces a validation error:


Prompt:
Complete this text code:

openAPIV3Schema:
  type: object
  properties:
    foo:
      type: array

Response:
      items:
        type: array
        items:
          type: integer
        x-kubernetes-validations:
          - rule: "self.all(x, x == 5)"

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | This is because each item of foo is itself an array, and each subarray in turn calls self.all. Avoid nested lists and maps if possible where validation rules are used.


Prompt:
Explain this text code:

openAPIV3Schema:
  type: object
  properties:
    foo:
      type: array
      items:
        type: array
        items:
          type: integer
        x-kubernetes-validations:
          - rule: "self.all(x, x == 5)"

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | This is because each item of foo is itself an array, and each subarray in turn calls self.all. Avoid nested lists and maps if possible where validation rules are used.


Prompt:
Complete this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        # openAPIV3Schema is the schema for validating custom objects.
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:

Response:
                cronSpec:
                  type: string
                  pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
                  default: "5 0 * * *"
                image:
                  type: string
                replicas:
                  type: integer
                  minimum: 1
                  maximum: 10
                  default: 1
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | With this both cronSpec and replicas are defaulted:


Prompt:
Explain this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        # openAPIV3Schema is the schema for validating custom objects.
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                  pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
                  default: "5 0 * * *"
                image:
                  type: string
                replicas:
                  type: integer
                  minimum: 1
                  maximum: 10
                  default: 1
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | With this both cronSpec and replicas are defaulted:


Prompt:
Complete this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:

Response:
  name: my-new-cron-object
spec:
  image: my-awesome-cron-image

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | leads to


Prompt:
Explain this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  image: my-awesome-cron-image

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | leads to


Prompt:
Complete this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object

Response:
spec:
  cronSpec: "5 0 * * *"
  image: my-awesome-cron-image
  replicas: 1

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Defaulting happens on the object


Prompt:
Explain this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "5 0 * * *"
  image: my-awesome-cron-image
  replicas: 1

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Defaulting happens on the object


Prompt:
Complete this text code:

type: object
properties:
  spec:
    type: object
    properties:
      foo:
        type: string

Response:
        nullable: false
        default: "default"
      bar:
        type: string
        nullable: true
      baz:
        type: string

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | creating an object with null values for foo and bar and baz


Prompt:
Explain this text code:

type: object
properties:
  spec:
    type: object
    properties:
      foo:
        type: string
        nullable: false
        default: "default"
      bar:
        type: string
        nullable: true
      baz:
        type: string

Response: This text code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | creating an object with null values for foo and bar and baz


Prompt:
Complete this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct
  versions:
  - name: v1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:

Response:
          spec:
            type: object
            properties:
              cronSpec:
                type: string
              image:
                type: string
              replicas:
                type: integer
    additionalPrinterColumns:
    - name: Spec
      type: string
      description: The cron spec defining the interval a CronJob is run
      jsonPath: .spec.cronSpec
    - name: Replicas
      type: integer
      description: The number of jobs launched by the CronJob
      jsonPath: .spec.replicas
    - name: Age
      type: date
      jsonPath: .metadata.creationTimestamp

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Create the CustomResourceDefinition:


Prompt:
Explain this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct
  versions:
  - name: v1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              cronSpec:
                type: string
              image:
                type: string
              replicas:
                type: integer
    additionalPrinterColumns:
    - name: Spec
      type: string
      description: The cron spec defining the interval a CronJob is run
      jsonPath: .spec.cronSpec
    - name: Replicas
      type: integer
      description: The number of jobs launched by the CronJob
      jsonPath: .spec.replicas
    - name: Age
      type: date
      jsonPath: .metadata.creationTimestamp

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Create the CustomResourceDefinition:


Prompt:
Complete this yaml code:

customresourcedefinition/shirt-resource-definition.yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: shirts.stable.example.com
spec:
  group: stable.example.com
  scope: Namespaced
  names:
    plural: shirts
    singular: shirt
    kind: Shirt
  versions:
  - name: v1
    served: true
    storage: true
    schema:
      openAPIV3Schema:

Response:
        type: object
        properties:
          spec:
            type: object
            properties:
              color:
                type: string
              size:
                type: string
    selectableFields:
    - jsonPath: .spec.color
    - jsonPath: .spec.size
    additionalPrinterColumns:
    - jsonPath: .spec.color
      name: Color
      type: string
    - jsonPath: .spec.size
      name: Size
      type: string


Prompt:
Explain this yaml code:

customresourcedefinition/shirt-resource-definition.yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: shirts.stable.example.com
spec:
  group: stable.example.com
  scope: Namespaced
  names:
    plural: shirts
    singular: shirt
    kind: Shirt
  versions:
  - name: v1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              color:
                type: string
              size:
                type: string
    selectableFields:
    - jsonPath: .spec.color
    - jsonPath: .spec.size
    additionalPrinterColumns:
    - jsonPath: .spec.color
      name: Color
      type: string
    - jsonPath: .spec.size
      name: Size
      type: string

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Create the CustomResourceDefinition:


Prompt:
Complete this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: shirts.stable.example.com
spec:
  group: stable.example.com
  scope: Namespaced
  names:
    plural: shirts
    singular: shirt
    kind: Shirt
  versions:
  - name: v1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object

Response:
        properties:
          spec:
            type: object
            properties:
              color:
                type: string
              size:
                type: string
    selectableFields:
    - jsonPath: .spec.color
    - jsonPath: .spec.size
    additionalPrinterColumns:
    - jsonPath: .spec.color
      name: Color
      type: string
    - jsonPath: .spec.size
      name: Size
      type: string


Prompt:
Explain this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: shirts.stable.example.com
spec:
  group: stable.example.com
  scope: Namespaced
  names:
    plural: shirts
    singular: shirt
    kind: Shirt
  versions:
  - name: v1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              color:
                type: string
              size:
                type: string
    selectableFields:
    - jsonPath: .spec.color
    - jsonPath: .spec.size
    additionalPrinterColumns:
    - jsonPath: .spec.color
      name: Color
      type: string
    - jsonPath: .spec.size
      name: Size
      type: string

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Create the CustomResourceDefinition:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/customresourcedefinition/shirt-resource-definition.yaml

Response: This bash code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Define some Shirts by editing shirt-resources.yaml; for example:

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Define some Shirts by editing shirt-resources.yaml; for example:


Prompt:
Complete this yaml code:

customresourcedefinition/shirt-resources.yaml
---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:
  name: example1
spec:
  color: blue
  size: S
---
apiVersion: stable.example.com/v1
kind: Shirt

Response:
metadata:
  name: example2
spec:
  color: blue
  size: M
---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:
  name: example3
spec:
  color: green
  size: M

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Create the custom resources:


Prompt:
Explain this yaml code:

customresourcedefinition/shirt-resources.yaml
---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:
  name: example1
spec:
  color: blue
  size: S
---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:
  name: example2
spec:
  color: blue
  size: M
---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:
  name: example3
spec:
  color: green
  size: M

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Create the custom resources:


Prompt:
Complete this yaml code:

---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:
  name: example1
spec:
  color: blue
  size: S
---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:

Response:
  name: example2
spec:
  color: blue
  size: M
---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:
  name: example3
spec:
  color: green
  size: M


Prompt:
Explain this yaml code:

---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:
  name: example1
spec:
  color: blue
  size: S
---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:
  name: example2
spec:
  color: blue
  size: M
---
apiVersion: stable.example.com/v1
kind: Shirt
metadata:
  name: example3
spec:
  color: green
  size: M

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Create the custom resources:


Prompt:
Explain this bash code:

kubectl apply -f https://k8s.io/examples/customresourcedefinition/shirt-resources.yaml

Response: This bash code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Get all the resources:

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Get all the resources:


Prompt:
Explain this bash code:

kubectl get shirts.stable.example.com --field-selector spec.color=blue

Response: This bash code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Should output:

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Should output:


Prompt:
Explain this bash code:

kubectl get shirts.stable.example.com --field-selector spec.color=green,spec.size=M

Response: This bash code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | Should output:


Prompt:
Complete this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
            status:

Response:
              type: object
              properties:
                replicas:
                  type: integer
                labelSelector:
                  type: string
      # subresources describes the subresources for custom resources.
      subresources:
        # status enables the status subresource.
        status: {}
        # scale enables the scale subresource.
        scale:
          # specReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Spec.Replicas.
          specReplicasPath: .spec.replicas
          # statusReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Replicas.
          statusReplicasPath: .status.replicas
          # labelSelectorPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Selector.
          labelSelectorPath: .status.labelSelector
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | And create it:


Prompt:
Explain this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
            status:
              type: object
              properties:
                replicas:
                  type: integer
                labelSelector:
                  type: string
      # subresources describes the subresources for custom resources.
      subresources:
        # status enables the status subresource.
        status: {}
        # scale enables the scale subresource.
        scale:
          # specReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Spec.Replicas.
          specReplicasPath: .spec.replicas
          # statusReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Replicas.
          statusReplicasPath: .status.replicas
          # labelSelectorPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.Selector.
          labelSelectorPath: .status.labelSelector
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | And create it:


Prompt:
Complete this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object

Response:
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image
  replicas: 3

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and create it:


Prompt:
Explain this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image
  replicas: 3

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and create it:


Prompt:
Complete this bash code:

kubectl scale --replicas=5 crontabs/my-new-cron-object
crontabs "my-new-cron-object" scaled

Response:
kubectl get crontabs my-new-cron-object -o jsonpath='{.spec.replicas}'
5

Context: 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | You can use a PodDisruptionBudget to protect custom resources that have the scale subresource enabled.


Prompt:
Explain this bash code:

kubectl scale --replicas=5 crontabs/my-new-cron-object
crontabs "my-new-cron-object" scaled

kubectl get crontabs my-new-cron-object -o jsonpath='{.spec.replicas}'
5

Response: This bash code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | You can use a PodDisruptionBudget to protect custom resources that have the scale subresource enabled.


Prompt:
Complete this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object

Response:
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct
    # categories is a list of grouped resources the custom resource belongs to.
    categories:
    - all


Prompt:
Explain this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct
    # categories is a list of grouped resources the custom resource belongs to.
    categories:
    - all

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and create it:


Prompt:
Complete this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:

Response:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image


Prompt:
Explain this yaml code:

apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image

Response: This yaml code 11.2.1 - Extend the Kubernetes API with CustomResourceDefinitions | and create it:


Prompt:
Complete this yaml code:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: crontabs.example.com
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: example.com
  # list of versions supported by this CustomResourceDefinition
  versions:
  - name: v1beta1
    # Each version can be enabled/disabled by Served flag.
    served: true
    # One and only one version must be marked as the storage version.
    storage: true
    # A schema is required
    schema:
      openAPIV3Schema:
        type: object
        properties:
          host:
            type: string
          port:
            type: string
  - name: v1
    served: true

Response:
    storage: false
    schema:
      openAPIV3Schema:
        type: object
        properties:
          host:
            type: string
          port:
            type: string
  # The conversion section is introduced in Kubernetes 1.13+ with a default value of
  # None conversion (strategy sub-field set to None).
  conversion:
    # None conversion assumes the same schema for all versions and only sets the apiVersion
    # field of custom resources to the proper value
    strategy: None
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: crontabs
    # singular name to be used as an alias on the CLI and for display
    singular: crontab
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: CronTab
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - ct

Context: 11.2.2 - Versions in CustomResourceDefinitions | # Deprecated in v1.16 in favor of apiextensions.k8s.io/v1 apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: # name must match the spec fields below, and be in the for