A config map is a configuration file that holds a sort of variables to be used in the configuration of a deployment.
This example shows how to configure the configuration of a database.
apiVersion: V1
kind: ConfigMap
metadata:
name: test-configmap #name the configmap
data:
#Conexion db
DB_HOST: 127.0.0.1
DB_PORT: '3306'
DB_NAME: 'test_load'
DB_USER: 'user'
DB_PASS: '1234'
Configmaps are not recommended for sensible data configuration.
Load file to kubernetes cluster.
Use in a deployment file.
- name: DB_HOST
valueFrom:
configMapKeyRef:
name: test-configmap
key: DB_HOST
Further example.
apiVersion: v1
kind: Deployment
metadata:
name: test-load-api
spec:
selector:
matchLabels:
app: test-load-api
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: test-load-api
spec:
containers:
- name: test-load-api
image: dockerdevops/test_load:0.1.0
env:
- name: DB_HOST
valueFrom:
configMapKeyRef:
name: test-configmap #name of the configmap with the variables
key: DB_HOST
- name: DB_PORT
valueFrom:
configMapKeyRef:
name: test-configmap #name of the configmap with the variables
key: DB_PORT
- name: DB_NAME
valueFrom:
configMapKeyRef:
name: test-configmap #name of the configmap with the variables
key: DB_NAME
- name: DB_USER
valueFrom:
configMapKeyRef:
name: test-configmap #name of the configmap with the variables
key: DB_USER
- name: DB_PASS
valueFrom:
configMapKeyRef:
name: test-configmap #name of the configmap with the variables
key: DB_PASS