19.06.2021 Views

148422597X Kubernetes Management Design Patterns [Vohra 2017-01-29] {E559F6BB}

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 11

Using ConfigMaps

In Chapter 10 and some earlier chapters, we used the spec: containers: env: field to specify an

environment variable for the Docker image mysql for the MySQL database.

Problem

Consider the use case that some environment variables such as username and password for a database are

to be used in multiple replication controller or pod definition files. The username and password value would

need to be specified in each of the definition files. And if the username and password were to change, all the

definition files would need to be updated as well, which could be very tedious. Alternatively, variable values

could be supplied to kubectl when a command is run, which involves specifying command-line flags each

time the command is run.

Solution

The ConfigMap management pattern is a map of configuration properties that can be used in definition

files for pods, replication controllers, and other Kubernetes objects to configure environment variables,

command arguments, and configuration files such as key-value pairs in volumes, to list a few example

uses. A single ConfigMap may package multiple configuration properties as key/value pairs. By creating

ConfigMaps, you specify the configuration properties in a single configuration map, which can be updated

as required without having to update each of the definition files in which the ConfigMap is used. Decoupling

the containers from the configuration data provides portability of the applications running in the containers.

Overview

A ConfigMap definition file schema provides for the following (Table 11-1) fields.

Table 11-1. ConfigMap Fields

Field

kind

apiVersion

metadata

data

Description

The resource type. Must be set to ConfigMap.

Version of the schema.

Metadata such as name, labels, namespace and annotations.

Configuration data as key/value pairs.

© Deepak Vohra 2017

D. Vohra, Kubernetes Management Design Patterns, DOI 10.1007/978-1-4842-2598-1_11

257

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!