Answers to Review Questions
Chapter 2, Core Concepts
-
You can either use the imperative approach or the declarative approach. First, we’ll look at creating the namespace with the imperative approach:
$ kubectl create namespace ckad
Create the Pod:
$ kubectl run nginx --image=nginx:1.17.10 --port=80 --namespace=ckad
Alternatively, you can use the declarative approach. Create a new YAML file called ckad-namespace.yaml with the following contents:
apiVersion:v1kind:Namespacemetadata:name:ckadCreate the namespace from the YAML file:
$ kubectl create -f ckad-namespace.yaml
Create a new YAML file called nginx-pod.yaml with the following contents:
apiVersion:v1kind:Podmetadata:name:nginxspec:containers:-name:nginximage:nginx:1.17.10ports:-containerPort:80Create the Pod from the YAML file:
$ kubectl create -f nginx-pod.yaml --namespace=ckad
-
You can use the command-line option
-o wideto retrieve the IP address of the Pod:$ kubectl get pod nginx --namespace=ckad -o wide
The same information is available if you query for the Pod details:
$ kubectl describe pod nginx --namespace=ckad | grep IP:
-
You can use the command-line options
--rmand-itto start a temporary Pod. The following command assumes that the IP address of the Pod namednginxis 10.1.0.66:$ kubectl run busybox --image=busybox --restart=Never --rm -it -n ckad \ -- wget -O- 10.1.0.66:80
-
To download the logs, use a simple
logscommand:$ kubectl logs nginx --namespace=ckad ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access