meta data de esta página
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
| virtualizacion:kubernetes:configmap [2020/11/05 20:37] – lc | virtualizacion:kubernetes:configmap [2023/01/18 14:37] (actual) – editor externo 127.0.0.1 | ||
|---|---|---|---|
| Línea 1: | Línea 1: | ||
| ===== ConfigMap ===== | ===== ConfigMap ===== | ||
| Configmap ter permite configurar tus pods desde un fichero de configuración sin necesidad de hacerlo manualmente y facilitando su portabilidad. | Configmap ter permite configurar tus pods desde un fichero de configuración sin necesidad de hacerlo manualmente y facilitando su portabilidad. | ||
| + | |||
| + | Un configmap se define siempre con una llave y un valor. Además el Pod y el ConfigMap deben estar en el mismo Namespace. | ||
| Se puede hacer desde un fichero .conf o bien desde nuestro manifiesto | Se puede hacer desde un fichero .conf o bien desde nuestro manifiesto | ||
| Línea 6: | Línea 8: | ||
| Por Ejemplo | Por Ejemplo | ||
| <sxh yaml> | <sxh yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: ConfigMap | ||
| + | metadata: | ||
| + | name: nginx-config | ||
| + | labels: | ||
| + | app: front | ||
| + | data: #Definimos dos llaves una llamadas test y la otra nginx | ||
| + | test: hola # | ||
| + | nginx: | #Definimos la segunda llave | ||
| + | server { | ||
| + | listen | ||
| + | server_name | ||
| + | location / { | ||
| + | root / | ||
| + | index index.html index.htm; | ||
| + | } | ||
| + | error_page | ||
| + | location = /50x.html { | ||
| + | root / | ||
| + | } | ||
| + | } | ||
| + | --- | ||
| + | apiVersion: apps/v1 | ||
| + | kind: Deployment | ||
| + | metadata: | ||
| + | name: deployment-test | ||
| + | labels: | ||
| + | app: front | ||
| + | spec: | ||
| + | replicas: 1 | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | app: front | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: front | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: nginx # | ||
| + | image: nginx: | ||
| + | volumeMounts: | ||
| + | - name: nginx-vol | ||
| + | mountPath: / | ||
| + | volumes: | ||
| + | - name: nginx-vol | ||
| + | configMap: | ||
| + | name: nginx-config | ||
| + | items: | ||
| + | - key: nginx | ||
| + | path: default.conf | ||
| + | </ | ||
| + | Ejemplo con variables y volúmenes | ||
| + | <sxh yaml> | ||
| apiVersion: v1 | apiVersion: v1 | ||
| kind: ConfigMap | kind: ConfigMap | ||
| Línea 13: | Línea 69: | ||
| app: front | app: front | ||
| data: | data: | ||
| - | | + | nginx: | #Definimos la primera llave de nuestro ConfigMap |
| - | | + | |
| server { | server { | ||
| listen | listen | ||
| Línea 27: | Línea 82: | ||
| } | } | ||
| } | } | ||
| + | --- | ||
| + | apiVersion: v1 | ||
| + | kind: ConfigMap | ||
| + | metadata: | ||
| + | name: vars | ||
| + | labels: | ||
| + | app: front | ||
| + | data: # | ||
| + | db_host: dev.host.local | ||
| + | db_user: dev_user | ||
| + | script: | # | ||
| + | echo DB host es $DB_HOST y DB user es $DB_USER > / | ||
| --- | --- | ||
| apiVersion: apps/v1 | apiVersion: apps/v1 | ||
| Línea 47: | Línea 114: | ||
| - name: nginx | - name: nginx | ||
| image: nginx: | image: nginx: | ||
| + | env: | ||
| + | - name: DB_HOST | ||
| + | valueFrom: | ||
| + | configMapKeyRef: | ||
| + | name: vars | ||
| + | key: db_host | ||
| + | - name: DB_USER | ||
| + | valueFrom: | ||
| + | configMapKeyRef: | ||
| + | name: vars | ||
| + | key: db_user | ||
| volumeMounts: | volumeMounts: | ||
| - name: nginx-vol | - name: nginx-vol | ||
| mountPath: / | mountPath: / | ||
| + | - name: script-vol | ||
| + | mountPath: /opt | ||
| volumes: | volumes: | ||
| - name: nginx-vol | - name: nginx-vol | ||
| Línea 57: | Línea 137: | ||
| - key: nginx | - key: nginx | ||
| path: default.conf | path: default.conf | ||
| - | </ | + | - name: script-vol |
| + | configMap: | ||
| + | name: vars | ||
| + | items: | ||
| + | - key: script | ||
| + | path: script.sh | ||
| + | </ | ||
| + | ==== Referencias ==== | ||
| + | * https:// | ||
| + | * https:// | ||