1
00:00:06,850 --> 00:00:12,180
In this lecture we discuss how to work with configuration data in Kubernetes.

2
00:00:12,220 --> 00:00:17,050
In the previous lecture we saw how to define environment variables in it pod definition file.

3
00:00:17,770 --> 00:00:23,350
When you have a lot of pod definition files it will become difficult to manage the environment data

4
00:00:23,350 --> 00:00:26,110
stored within the query files.

5
00:00:26,110 --> 00:00:32,500
We can take this information out of the pod definition file and manage it centrally using Configuration

6
00:00:32,500 --> 00:00:39,920
Maps. ConfigMaps are used to pass configuration data in the form of key value pairs in Kubernetes.


7
00:00:40,150 --> 00:00:44,020
When it pod is created inject the config map into the pod.

8
00:00:44,110 --> 00:00:50,380
So the key value pairs that are available as environment variables for the application hosted inside

9
00:00:50,380 --> 00:00:52,330
the container in the pod.

10
00:00:52,690 --> 00:00:56,220
There are two phases involved in configuring ConfigMaps.

11
00:00:56,260 --> 00:01:05,070
First create the ConfigMaps and second Inject them into the POD. Just like any other Kubernetes object.

12
00:01:05,070 --> 00:01:08,330
There are two ways of creating a configmap.

13
00:01:08,580 --> 00:01:16,140
The imperative way - without using a ConfigMap definition file and the Declarative way by using a Config

14
00:01:16,140 --> 00:01:17,960
map definition file.

15
00:01:18,180 --> 00:01:24,240
If you do not wish to create a configmap definition, you could simply use the kubectl create

16
00:01:24,300 --> 00:01:29,040
configmap command and specify the required arguments.

17
00:01:29,040 --> 00:01:32,420
Let's take a look at that first with this method.

18
00:01:32,520 --> 00:01:39,120
you can directly specify the key value pairs in the command line. To create a configMap of the given

19
00:01:39,120 --> 00:01:43,720
values, run the kubectl create configmap command.

20
00:01:43,920 --> 00:01:51,360
The command is followed by the config name and the option –from-literal. The from literal option is

21
00:01:51,360 --> 00:01:55,560
used to specify the key value pairs in the command itself.

22
00:01:55,560 --> 00:02:03,090
In this example, we are creating a configmap by the name app-config, with a key value pair APP_COLOR

23
00:02:03,180 --> 00:02:04,800
equals blue.

24
00:02:04,980 --> 00:02:12,310
If you wish to add additional key value pairs simply specify the from literal options multiple times.

25
00:02:12,360 --> 00:02:17,760
However this will get complicated when you have too many configuration items.

26
00:02:17,760 --> 00:02:22,280
Another way to input configuration data is through a file.

27
00:02:22,290 --> 00:02:28,880
Use the from file option to specify a path to the file that contains the required data.

28
00:02:29,130 --> 00:02:36,650
The data from this file is read and stored under the name of the file let us now look at the declarative

29
00:02:36,650 --> 00:02:37,520
approach.

30
00:02:37,700 --> 00:02:42,470
For this we create a definition file just like how we did for the pod.

31
00:02:42,560 --> 00:02:50,330
The file has apiVersion, kind, metadata and instead of spec, here we have “data”.

32
00:02:50,330 --> 00:02:57,050
The apiVersion is v1, kind is ConfigMap. Under metadata specify the name of the config

33
00:02:57,050 --> 00:02:57,870
map.

34
00:02:58,070 --> 00:03:05,930
We will call it app-config. Under data add the configuration data in a key-value format. Run the kubectl


35
00:03:05,930 --> 00:03:13,010
create command and specify the configuration file name. So that creates the app-config config

36
00:03:13,040 --> 00:03:15,630
map with the values we specified.

37
00:03:15,980 --> 00:03:22,690
You can create as many configmaps as you need in the same way for various different purposes.

38
00:03:22,700 --> 00:03:28,920
Here I have one for my application, other for mysql and another one for redis.

39
00:03:29,120 --> 00:03:36,260
So it is important to name the config maps appropriately as you will be using these names later while

40
00:03:36,260 --> 00:03:44,120
associating it with PODs. To view the configmaps, run the kubectl get configmaps command. This lists

41
00:03:44,210 --> 00:03:49,930
the newly created configmap named app-config. The describe configmaps command

42
00:03:49,940 --> 00:03:58,440
List the configuration data as well under the data section now that we have the config map created let

43
00:03:58,440 --> 00:04:07,030
us proceed with step 2 configuring it with a pod here I have a simple pod definition file that runs

44
00:04:07,060 --> 00:04:14,710
my simple web application to inject an environment variable add a new property to the container called

45
00:04:14,860 --> 00:04:23,620
envFrom. The envFrom property is a list, so we can pass as many environment variables as required. Each

46
00:04:23,680 --> 00:04:30,490
item in the list corresponds to a configMap item. Specify the name of the configmap we created earlier.

47
00:04:31,150 --> 00:04:38,470
This is how we inject a specific configmap from the ones we created before. Creating the pod definition

48
00:04:38,470 --> 00:04:48,290
file now creates a web application with a blue background. What we just saw was using configMaps to inject

49
00:04:48,310 --> 00:04:50,160
environment variables.

50
00:04:50,160 --> 00:04:56,970
There are other ways to inject configuration data into pods you can inject it as a single environment

51
00:04:56,970 --> 00:05:02,820
variable or you can inject the whole the data as files in a volume.

52
00:05:03,000 --> 00:05:08,880
We will look at some of these options in the coding exercises that accompany this lecture.

53
00:05:08,910 --> 00:05:15,900
So head over to the coding exercises section and practice viewing configuring and troubleshooting environment

54
00:05:15,900 --> 00:05:18,930
variables on a live Kubernetes environment.
