Chapter 20. Configuration Resource

Kubernetes provides native configuration resources for regular and confidential data, which allows you to decouple the configuration lifecycle from the application lifecycle. The Configuration Resource pattern explains the concepts of ConfigMap and Secret resources and how we can use them, as well as their limitations.

Problem

One significant disadvantage of the EnvVar Configuration pattern, discussed in Chapter 19, is that it’s suitable for only a handful of variables and simple configurations. Another disadvantage is that because environment variables can be defined in various places, it is often hard to find the definition of a variable. And even if you find it, you can’t be entirely sure it won’t be overridden in another location. For example, environment variables defined within a OCI image can be replaced during runtime in a Kubernetes Deployment resource.

Often, it is better to keep all the configuration data in a single place and not scattered around in various resource definition files. But it does not make sense to put the content of a whole configuration file into an environment variable. So some extra indirection would allow more flexibility, which is what Kubernetes configuration resources offer.

Solution

Kubernetes provides dedicated configuration Resources that are more flexible than pure environment variables. These are the ConfigMap and Secret objects for general-purpose and sensitive data, respectively.

We can use both in ...

Get Kubernetes Patterns, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.