content_image/781509.jpg
We see here that a ConfigMap can also carry the content of complete configuration files, like the Spring Boot application.properties  in this example. You can imagine that for a nontrivial use case, this section could get quite large! 

Instead of manually creating the full resource descriptor, we can use kubectl  to create ConfigMaps or Secrets too. For the preceding example, the equivalent kubectl  com‐ mand looks like that in Example 19-2. 

kubectl create cm spring-boot-config \ --from-literal=JAVA_OPTIONS=-Djava.security.egd=file:/dev/urandom \ --from-file=application.properties 

This ConfigMap then can be read in various places—everywhere environment vari‐ ables are defined, as demonstrated Example 19-3. 

apiVersion : v1 kind : Pod metadata : name : random-generator spec : containers : - env : - name : PATTERN valueFrom : configMapKeyRef : name : random-generator-config key : PATTERN 

.... 

If a ConfigMap has many entries that you want to consume as environment variables, using a certain syntax can save a lot of typing. Rather than specifying each entry indi‐ vidually, as shown in the preceding example in the env:  section, envFrom:  allows exposing all ConfigMap entries that have a key that also can be used as a valid envi‐ ronment variable. We can prepend this with a prefix, as shown in Example 19-4. 

apiVersion : v1 kind : Pod metadata : name : random-generator spec : containers : envFrom : 

<img src='content_image/781509.jpg'>

