> For the complete documentation index, see [llms.txt](https://dojo.lkmx.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dojo.lkmx.io/kubernetes/usar-config-maps-para-configurar-una-implementacion.md).

# 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.&#x20;

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

```yaml
  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:

```bash
  kubectl apply -f <path>
```

Usar en un archivo de implementación:

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

Otro ejemplo:

```yaml
  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

* <https://kubernetes.io/docs/concepts/configuration/configmap/>
