1 00:00:00,001 --> 00:00:02,367 [No Audio] 2 00:00:02,367 --> 00:00:06,134 Hello, everyone. As usual, let's start this demo 3 00:00:06,134 --> 00:00:09,834 with a list of available Pods. We have two Pods, 4 00:00:09,967 --> 00:00:14,967 cmd, and lifecyc-pods. One of them is completed 5 00:00:14,967 --> 00:00:18,167 and the other one is still running. Now let's open 6 00:00:18,167 --> 00:00:22,601 the YAML file environment-pod.yaml with nano. 7 00:00:22,767 --> 00:00:25,501 Again, the YAML is pretty similar to 8 00:00:25,501 --> 00:00:29,034 previous demos, so we should focus on the changes. 9 00:00:29,034 --> 00:00:33,467 The names of pod and container, are env-pod, 10 00:00:33,467 --> 00:00:36,401 and env-container. Just like our usual 11 00:00:36,401 --> 00:00:38,667 naming convention. If you take a look at the 12 00:00:38,667 --> 00:00:42,234 image, we have not simply provided a name with 13 00:00:42,234 --> 00:00:46,701 label, we have the whole path or URL of the image. 14 00:00:46,934 --> 00:00:49,867 We have done this, because this time, we don't want 15 00:00:49,867 --> 00:00:53,034 to use Docker Image registry, we want to use 16 00:00:53,034 --> 00:00:56,467 Google Container Registry, which is another place 17 00:00:56,467 --> 00:01:00,101 to find container images. In this demo, we are 18 00:01:00,101 --> 00:01:03,934 using one of the sample Google images called node-hello. 19 00:01:03,934 --> 00:01:06,934 This node hello is more or less like Hello World 20 00:01:06,934 --> 00:01:09,867 of Docker Image registry, and this one is 21 00:01:09,867 --> 00:01:13,367 built on top of alpine base image. With that said, 22 00:01:13,367 --> 00:01:17,667 let's get to the cream of this demo, which is env 23 00:01:17,667 --> 00:01:21,134 or env field, which is used to provide 24 00:01:21,134 --> 00:01:24,501 environment variables to the container. If the 25 00:01:24,501 --> 00:01:27,401 container does not have the environment variables 26 00:01:27,401 --> 00:01:30,934 provided within this field, it adds it along with 27 00:01:30,934 --> 00:01:34,434 its default environment variables. And if an 28 00:01:34,434 --> 00:01:37,767 environment variable with the same name has 29 00:01:37,767 --> 00:01:40,567 already been set up by the Docker Image, the 30 00:01:40,567 --> 00:01:44,667 running container replaces it by the values we provide. 31 00:01:44,767 --> 00:01:48,867 So take this example. Let's say we have a 32 00:01:48,867 --> 00:01:52,167 Docker Image and we provide it environment variables 33 00:01:52,167 --> 00:01:59,034 A, B, and C equals P, Q, and R respectively. 34 00:01:59,034 --> 00:02:02,067 If we are providing the same environment variables with 35 00:02:02,067 --> 00:02:05,967 different values using Kubernetes YAML file, just 36 00:02:05,967 --> 00:02:08,300 like Docker, only the running container will 37 00:02:08,300 --> 00:02:12,033 reflect the changed value. Which means that the 38 00:02:12,033 --> 00:02:15,901 values will reflect on a copy of the image and the 39 00:02:15,901 --> 00:02:18,467 original image will remain unchanged. 40 00:02:18,467 --> 00:02:22,934 So the original images, environment variables would still 41 00:02:22,934 --> 00:02:28,467 be A, B, C equals P,Q, and R, but a copy of it will 42 00:02:28,467 --> 00:02:33,934 have it as A, B, C equals S, T, and U, or anything 43 00:02:33,934 --> 00:02:36,701 else which we provide. In this case, we are 44 00:02:36,701 --> 00:02:41,067 providing to environment variables, POD_GREETING 45 00:02:41,067 --> 00:02:44,401 and POD_FAREWELL, and their values are suitable to 46 00:02:44,401 --> 00:02:51,667 the name as well. POD_GREETING is 'Welcome!', and POD_FAERWELL is, 47 00:02:51,667 --> 00:02:55,534 'We don't want you to go!' with a sad smiley. 48 00:02:55,767 --> 00:02:59,834 With that said, let's save and exit our file. 49 00:02:59,834 --> 00:03:04,601 Let's create the Pod using kubectl create -f command. 50 00:03:05,134 --> 00:03:07,467 Let's see if it is running or not. 51 00:03:07,901 --> 00:03:11,234 The Pod seems to be Running. Now let's get a 52 00:03:11,234 --> 00:03:14,567 description of this Pod using kubectl describe pod 53 00:03:14,567 --> 00:03:17,501 followed by its name env-pod. 54 00:03:17,501 --> 00:03:21,334 Here is the description of this Pod. Let's straightaway 55 00:03:21,334 --> 00:03:24,567 jump to the Environment section and we have two 56 00:03:24,567 --> 00:03:28,067 entries in this field, POD_GREETING and POD_FAREWELL. 57 00:03:28,067 --> 00:03:30,601 Exactly the ones which we had set up. 58 00:03:30,634 --> 00:03:37,134 Let's clear it and execute this Pod using kubectl exec -it 59 00:03:37,134 --> 00:03:39,334 followed by Pod name followed by 60 00:03:39,334 --> 00:03:41,867 the command which we want to run. You may notice 61 00:03:41,867 --> 00:03:44,234 that this command is pretty similar to what Docker 62 00:03:44,234 --> 00:03:47,067 has provided for executing a container as well. 63 00:03:47,167 --> 00:03:50,267 Now we are in root directory of our container. 64 00:03:50,267 --> 00:03:53,367 Let's print our environment variables. And there 65 00:03:53,367 --> 00:03:55,734 we go, we have a long list of environment 66 00:03:55,734 --> 00:03:59,134 variables. This answers more than one questions. 67 00:03:59,134 --> 00:04:01,967 First of all, what about the environment variables 68 00:04:01,967 --> 00:04:05,201 that we had set up? Well, here they are. 69 00:04:05,201 --> 00:04:09,201 Both POD_GREETING and POD_FAREWELL are present. 70 00:04:09,467 --> 00:04:13,901 And second, when we executed the container, why did we 71 00:04:13,901 --> 00:04:18,267 get to root at env pod, not env container. 72 00:04:18,267 --> 00:04:21,801 Well the reason is, we are still in the root directory 73 00:04:21,801 --> 00:04:26,166 of the container itself. But the HOSTNAME is env-pod, 74 00:04:26,166 --> 00:04:28,334 which you can see in this environment 75 00:04:28,334 --> 00:04:30,501 variable. With that out of the way. 76 00:04:30,501 --> 00:04:33,867 Let's exit this container and get back to our terminal.