Free CKA Exam Braindumps (page: 11)

Page 10 of 31

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






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