Free CKA Exam Braindumps
Certified Kubernetes Administrator Questions 36–40 (page: 9)

Updated On: 10-Feb-2026

Create a pod with init container which create a file "test.txt" in "workdir" directory. Main container should check a file "test.txt" exists and execute sleep 9999 if the file exists.

  1. Solution:

    // create an initial yaml file with this
    kubectl run init-cont-pod --image=alpine --restart=Never --dry-run -o


    yaml > init-cont-pod.yaml
    // edit the yml as below and create it
    vim init-cont-pod.yaml
    apiVersion: v1
    kind: Pod
    metadata:
    name: init-cont-pod
    labels:
    app: myapp
    spec:
    volumes:
    - name: test-volume
    emptyDir: {}
    containers:
    - name: main-container
    image: busybox:1.28
    command: ['sh', '-c', 'if [ -f /workdir/test.txt ]; then sleep 9999; fi']
    volumeMounts:
    - name: test-volume
    mountPath: /workdir
    initContainers:
    - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', "mkdir /workdir; echo >
    /workdir/test.txt"]
    volumeMounts:
    - name: test-volume
    mountPath: /workdir
    // Create the pod
    kubectl apply -f init-cont-pod.yaml
    kubectl get pods
    // Check Events by doing
    kubectl describe po init-cont-pod
    Init Containers:
    init-myservice:
    Container ID:
    docker://ebdbf5fad1c95111d9b0e0e2e743c2e347c81b8d4eb5abcccdfe1dd74524 0d4f
    Image: busybox:1.28
    Image ID: dockerpullable://busybox@sha256:141c253bc4c3fd0a201d32dc1f493bcf3fff003b6df 416dea4f41046e0f37d47
    Port: <none>
    Host Port: <none>
    Command:
    sh
    -c
    mkdir /workdir; echo > /workdir/test.txt


    State: Terminated
    Reason: Completed

Answer(s): A



Create a pod with init container which waits for a service called "myservice" to be created. Once init container completes, the myapp-container should start and print a message "The app is running" and sleep for 3600 seconds.

  1. Solution:

    vim multi-container-pod.yaml
    apiVersion: v1
    kind: Pod
    metadata:
    name: myapp-pod
    labels:
    app: myapp
    spec:
    containers:
    - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
    initContainers:
    - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).s vc.cluster.local; do echo waiting for myservice; sleep 2; done"]
    // Check whether service called "myservice" exists
    kubectl get svc
    Note: Pod will not start if service called "myservice" doesn't exist.
    // Now, Create the pod
    kubectl apply -f multi-container-pod.yaml

Answer(s): A



Create 5 nginx pods in which two of them is labeled env=prod and three of them is labeled env=dev

  1. Solution:

    kubectl run nginx-dev1 --image=nginx --restart=Never -- labels=env=dev
    kubectl run nginx-dev2 --image=nginx --restart=Never -- labels=env=dev
    kubectl run nginx-dev3 --image=nginx --restart=Never -- labels=env=dev
    kubectl run nginx-prod1 --image=nginx --restart=Never -- labels=env=prod
    kubectl run nginx-prod2 --image=nginx --restart=Never -- labels=env=prod

Answer(s): A



Get the pods with label env=dev and output the labels

  1. Solution:

    kubectl get pods -l env=dev --show-labels

Answer(s): A



Get the pods with labels env=dev and env=prod and output the labels as well

  1. Solution:

    kubectl get pods -l 'env in (dev,prod)' --show-labels

Answer(s): A



Viewing page 9 of 26
Viewing questions 41 - 45 out of 122 questions


Post your Comments and Discuss Linux Foundation CKA exam prep with other Community members:

AI Tutor AI Tutor 👋 I’m here to help!