> 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/ingles/kubernetes/use-config-maps-to-configure-a-deployment.md).

# Use config maps to configure a deployment

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.

```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 are not recommended for sensible data configuration.

Load file to kubernetes cluster.

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

Use in a deployment file.

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

Further example.

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

## Reference Links

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