1 00:00:00,001 --> 00:00:03,367 [No Audio] 2 00:00:03,367 --> 00:00:06,501 Let's start this demo by printing a list of 3 00:00:06,501 --> 00:00:10,101 available Pods using kubectl get pods. 4 00:00:10,967 --> 00:00:15,001 We only have 1 Pod, lifecyc-pod, which is from the 5 00:00:15,001 --> 00:00:17,701 previous demo, because we have deleted the 6 00:00:17,701 --> 00:00:21,601 imperative and declarative Pods. Don't worry, 7 00:00:21,601 --> 00:00:24,534 we will go through how to delete Pods as well. 8 00:00:24,534 --> 00:00:29,401 But for now, let's go to the file command-pod.yaml. 9 00:00:29,734 --> 00:00:32,234 The YAML file looks pretty similar compared to 10 00:00:32,234 --> 00:00:35,834 previous two demos as well. So let's focus on the 11 00:00:35,834 --> 00:00:39,467 changes here. First of all, the names of the pod 12 00:00:39,467 --> 00:00:44,934 and container have changed. The pod is named cmd-pod, 13 00:00:44,934 --> 00:00:48,667 and the container is named cmd-container. 14 00:00:48,667 --> 00:00:53,934 Makes sense. Then, in spec field, after 15 00:00:53,934 --> 00:00:57,401 name and image of the container, we have command 16 00:00:57,401 --> 00:01:00,867 field, command field indicates the entrypoint 17 00:01:00,867 --> 00:01:04,134 command in the Docker Image. If we do not provide 18 00:01:04,134 --> 00:01:06,434 any command or value to the command field, 19 00:01:06,566 --> 00:01:11,001 Kubernetes uses default entrypoint of Docker Image. 20 00:01:11,401 --> 00:01:15,134 But we can change it by providing command 21 00:01:15,134 --> 00:01:18,334 and its arguments. Instead of keeping the 22 00:01:18,334 --> 00:01:21,401 container up by running a loop of bash command, 23 00:01:21,401 --> 00:01:24,001 we are just asking it to print a couple of 24 00:01:24,001 --> 00:01:28,467 environment variables. So the command is printenv, 25 00:01:28,467 --> 00:01:31,867 and its arguments are HOSTNAME, and 26 00:01:31,867 --> 00:01:36,267 KUBERNETES_PORT. You may notice, that 27 00:01:36,267 --> 00:01:39,467 the command and the arguments are written in 28 00:01:39,467 --> 00:01:42,367 between double inverted commas and they're 29 00:01:42,367 --> 00:01:46,501 encapsulated by square brackets. The arguments are 30 00:01:46,501 --> 00:01:50,401 separated by a comma. Let's exit the file and 31 00:01:50,401 --> 00:01:57,201 make a Pod. Run kubectl create -f command-pod.yaml. 32 00:01:57,201 --> 00:01:59,301 The port should have been created. 33 00:01:59,301 --> 00:02:02,534 Let's test it with kubectl get pods. 34 00:02:02,767 --> 00:02:06,601 Here we go, but check it out. This pod is not in 35 00:02:06,601 --> 00:02:09,234 Running state, it is in the Completed state. 36 00:02:09,234 --> 00:02:12,601 The reason is, we have not provided any endless loop 37 00:02:12,601 --> 00:02:16,634 command like bash, we had just asked it to print a 38 00:02:16,634 --> 00:02:19,234 couple of environment variables, which it did 39 00:02:19,234 --> 00:02:22,301 successfully within a few milliseconds maybe. So by 40 00:02:22,301 --> 00:02:25,401 the time we run the command kubectl get pods, the 41 00:02:25,401 --> 00:02:28,267 container had already finished its task and the 42 00:02:28,267 --> 00:02:31,567 Pod was in Completed state. Let's have a 43 00:02:31,567 --> 00:02:37,267 description of this Pod using kubectl describe pod cmd-pod. 44 00:02:37,267 --> 00:02:39,601 Here is our long, well-structured 45 00:02:39,601 --> 00:02:42,234 description. I'm pretty sure you can comprehend 46 00:02:42,234 --> 00:02:46,201 most of the parts easily, so let's directly jump 47 00:02:46,201 --> 00:02:49,601 to the command and arguments section. The command 48 00:02:49,601 --> 00:02:53,201 is the same what we had provided, which is printenv, 49 00:02:53,201 --> 00:02:57,267 and its arguments are HOSTNAME and KUBERNETES_PORT. 50 00:02:57,267 --> 00:02:59,834 Now if we jump to Events, we can 51 00:02:59,834 --> 00:03:04,667 also see that the container had started 35 seconds ago, 52 00:03:04,667 --> 00:03:08,567 whereas it finished 34 seconds ago. So within 53 00:03:08,567 --> 00:03:10,967 one second all of the commands were performed. 54 00:03:10,967 --> 00:03:14,501 We can also verify this by looking at the log of the Pod. 55 00:03:14,501 --> 00:03:18,667 Simply write kubectl logs and then the Pod name 56 00:03:18,667 --> 00:03:21,967 which is cmd-pod. And there you go, 57 00:03:21,967 --> 00:03:26,467 we have our HOSTNAME and KUBERNETES_PORT both printed.