8 Configuring Applications with ConfigMaps and Secrets

 

This chapter covers

  • Setting the command and arguments for the container's main process
  • Setting environment variables
  • Storing configuration in ConfigMaps
  • Storing sensitive information in Secrets
  • Using the Downward API to expose Pod metadata to the application

In the previous chapters you learned how to run an application process in Kubernetes. Now, you’ll learn how to configure the application—either directly in the Pod manifest or through decoupled resources referenced by the Pod manifest. You’ll also learn how to inject Pod metadata into the environment of the containers within the Pod.

Note

8.1 Setting the command, arguments, and environment variables

Like regular applications, containerized applications can be configured using command-line arguments, environment variables, and files.

You learned that the command that gets executed in the container is typically defined in the container image. You specify the command in the container’s Dockerfile using the ENTRYPOINT directive and the arguments with the CMD directive. Environment variables can also be specified; you do this with the ENV directive. If the application is configured using configuration files, these can be added to the container image using the COPY directive. You’ve seen several examples of this in the previous chapters.

8.1.1 Setting the command and arguments

8.1.2 Setting environment variables in a container

8.2 Using a ConfigMap to decouple configuration from the Pod manifest

8.2.1 Introducing ConfigMaps

8.2.2 Creating a ConfigMap object

8.2.3 Injecting ConfigMap values into environment variables

8.2.4 Updating and deleting ConfigMaps

8.3 Using Secrets to pass sensitive data to containers

8.3.1 Introducing Secrets

8.3.2 Creating a Secret

8.3.3 Using Secrets in containers

8.3.4 Understanding why Secrets aren’t always secure

8.4 Exposing metadata to containers via the Downward API

8.4.1 Introducing the Downward API

8.4.2 Injecting Pod metadata into environment variables

8.5 Summary