Usar config maps para configurar una implementación

Un config maps es un archivo de configuración que contiene una especie de variables que se utilizarán en la configuración de una implementación.

Este ejemplo muestra cómo cambiar la configuración de una base de datos:

  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 no se recomienda para la configuración de datos sensibles.

Subir el archivo en el clúster de Kubernetes:

  kubectl apply -f <path>

Usar en un archivo de implementación:

  - name: DB_HOST
    valueFrom:
      configMapKeyRef:
        name: test-configmap
        key: DB_HOST

Otro ejemplo:

  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

Enlaces de referencia

Last updated