Create ConfigMap

Introduction

ConfigMap allow you to decouple configuration artifacts and secrets from image content to keep containerized applications portable. Using ConfigMap, you can independently control MySQL configuration.

Create the mysql Namespace

We will create a new Namespace called mysql that will host all the components.

kubectl create namespace mysql

Create ConfigMap

Run the following commands to download the ConfigMap.

cd ~/environment/templates
wget https://eksworkshop.com/beginner/170_statefulset/configmap.files/mysql-configmap.yml

Check the configuration of mysql-configmap.yml file.

cat ~/environment/templates/mysql-configmap.yml

The ConfigMap stores master.cnf, slave.cnf and passes them when initializing master and slave pods defined in StatefulSet: * master.cnf is for the MySQL master pod which has binary log option (log-bin) to provides a record of the data changes to be sent to slave servers. * slave.cnf is for slave pods which have super-read-only option.


apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-config
  namespace: mysql
  labels:
    app: mysql
data:
  master.cnf: |
    # Apply this config only on the master.
    [mysqld]
    log-bin
  slave.cnf: |
    # Apply this config only on slaves.
    [mysqld]
    super-read-only

Create “mysql-config” ConfigMap.

kubectl create -f ~/environment/templates/mysql-configmap.yml