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

marco.cirilli
from marco.cirilli More from this publisher
19.06.2021 Views

Chapter 11 ■ Using ConfigMapsFigure 11-6. Creating a ConfigMap from a directoryYou can list the ConfigMap YAML definition with the following command:./kubectl get configmaps mysql-config -o yamlThe mysql-config definition file is listed as shown in Figure 11-7.Figure 11-7. ConfigMap definition file261

Chapter 11 ■ Using ConfigMapsNext, consume the ConfigMap in a replication controller; to do that, create a definition file mysql.yaml:sudo vi mysql.yamlUse the config map mysql-config to obtain environment variable values for the MySQL databaseDocker image mysql.---apiVersion: v1kind: ReplicationControllermetadata:labels:app: mysql-appname: mysqlspec:replicas: 3selector:app: mysql-apptemplate:metadata:labels:app: mysql-appspec:containers:-env:-name: MYSQL_ROOT_PASSWORDvalueFrom:configMapKeyRef:key: mysql.root.passwordname: mysql-config-name: MYSQL_DATABASEvalueFrom:configMapKeyRef:key: mysql.databasename: mysql-config-name: MYSQL_USERvalueFrom:configMapKeyRef:key: mysql.username: mysql-config-name: MYSQL_PASSWORDvalueFrom:configMapKeyRef:key: mysql.username: mysql-config-262

Chapter 11 ■ Using ConfigMaps

Next, consume the ConfigMap in a replication controller; to do that, create a definition file mysql.yaml:

sudo vi mysql.yaml

Use the config map mysql-config to obtain environment variable values for the MySQL database

Docker image mysql.

---

apiVersion: v1

kind: ReplicationController

metadata:

labels:

app: mysql-app

name: mysql

spec:

replicas: 3

selector:

app: mysql-app

template:

metadata:

labels:

app: mysql-app

spec:

containers:

-

env:

-

name: MYSQL_ROOT_PASSWORD

valueFrom:

configMapKeyRef:

key: mysql.root.password

name: mysql-config

-

name: MYSQL_DATABASE

valueFrom:

configMapKeyRef:

key: mysql.database

name: mysql-config

-

name: MYSQL_USER

valueFrom:

configMapKeyRef:

key: mysql.user

name: mysql-config

-

name: MYSQL_PASSWORD

valueFrom:

configMapKeyRef:

key: mysql.user

name: mysql-config

-

262

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

Saved successfully!

Ooh no, something went wrong!