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

Figure 11-6. Creating a ConfigMap from a directory

You can list the ConfigMap YAML definition with the following command:

./kubectl get configmaps mysql-config -o yaml

The mysql-config definition file is listed as shown in Figure 11-7.

Figure 11-7. ConfigMap definition file

261

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

Saved successfully!

Ooh no, something went wrong!