ExamGecko

Linux Foundation CKA Practice Test - Questions Answers, Page 4

Question list
Search
Search

Create a pod that echo "hello world" and then exists. Have the pod deleted automatically when it's completed

A.
See the solution below.
A.
See the solution below.
Answers
Suggested answer: A

Explanation:

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

/bin/sh -c 'echo hello world'

kubectl get po # You shouldn't see pod with the name "busybox"

Create a pod with environment variables as var1=value1.Check the environment variable in pod

A.
See the solution below.
A.
See the solution below.
Answers
Suggested answer: A

Explanation:

kubectl run nginx --image=nginx --restart=Never --env=var1=value1

# then

kubectl exec -it nginx -- env

# or

kubectl exec -it nginx -- sh -c 'echo $var1'

# or

kubectl describe po nginx | grep value1

Get list of all the pods showing name and namespace with a jsonpath expression.

A.
See the solution below.
A.
See the solution below.
Answers
Suggested answer: A

Explanation:

kubectl get pods -o=jsonpath="{.items[*]['metadata.name' , 'metadata.namespace']}"

Check the image version in pod without the describe command

A.
See the solution below.
A.
See the solution below.
Answers
Suggested answer: A

Explanation:

kubectl get po nginx -o

jsonpath='{.spec.containers[].image}{"\n"}'

List the nginx pod with custom columns POD_NAME and POD_STATUS

A.
See the solution below.
A.
See the solution below.
Answers
Suggested answer: A

Explanation:

kubectl get po -o=custom-columns="POD_NAME:.metadata.name,

POD_STATUS:.status.containerStatuses[].state"

List all the pods sorted by name

A.
See the solution below.
A.
See the solution below.
Answers
Suggested answer: A

Explanation:

kubect1 get pods --sort-by=.metadata.name

Create a pod that having 3 containers in it? (Multi-Container)

A.
See the solution below.
A.
See the solution below.
Answers
Suggested answer: A

Explanation:

image=nginx, image=redis, image=consul

Name nginx container as "nginx-container"

Name redis container as "redis-container"

Name consul container as "consul-container"

Create a pod manifest file for a container and append container section for rest of the images

kubectl run multi-container --generator=run-pod/v1 --image=nginx --

dry-run -o yaml > multi-container.yaml

# then

vim multi-container.yaml

apiVersion: v1

kind: Pod

metadata:

labels:

run: multi-container

name: multi-container

spec:

containers:

- image: nginx

name: nginx-container

- image: redis

name: redis-container

- image: consul

name: consul-container

restartPolicy: Always

Create 2 nginx image pods in which one of them is labelled with env=prod and another one labelled with env=dev and verify the same.

A.
See the solution below.
A.
See the solution below.
Answers
Suggested answer: A

Explanation:

kubectl run --generator=run-pod/v1 --image=nginx -- labels=env=prod nginx-prod --dry-run -o yaml >

nginx-prodpod.yaml Now, edit nginx-prod-pod.yaml file and remove entries like "creationTimestamp:

null" "dnsPolicy: ClusterFirst"

vim nginx-prod-pod.yaml

apiVersion: v1

kind: Pod

metadata:

labels:

env: prod

name: nginx-prod

spec:

containers:

- image: nginx

name: nginx-prod

restartPolicy: Always

# kubectl create -f nginx-prod-pod.yaml

kubectl run --generator=run-pod/v1 --image=nginx --

labels=env=dev nginx-dev --dry-run -o yaml > nginx-dev-pod.yaml

apiVersion: v1

kind: Pod

metadata:

labels:

env: dev

name: nginx-dev

spec:

containers:

- image: nginx

name: nginx-dev

restartPolicy: Always

# kubectl create -f nginx-prod-dev.yaml

Verify :

kubectl get po --show-labels

kubectl get po -l env=prod

kubectl get po -l env=dev

Get IP address of the pod – "nginx-dev"

A.
See the solution below.
A.
See the solution below.
Answers
Suggested answer: A

Explanation:

Kubect1 get po -o wide

Using JsonPath

kubect1 get pods -o=jsonpath='{range

.items[*]}{.metadata.name}{"\t"}{.status.podIP}{"\n"}{end}'

Print pod name and start time to "/opt/pod-status" file

A.
See the solution below.
A.
See the solution below.
Answers
Suggested answer: A

Explanation:

kubect1 get pods -o=jsonpath='{range

.items[*]}{.metadata.name}{"\t"}{.status.podIP}{"\n"}{end}'

Total 67 questions
Go to page: of 7