Skip to main content

⚙️ Configuration (ConfigMap)

An application usually needs adjustments: language, run mode, the address of another service. The ConfigMap stores these settings outside the application, like a "settings file" separate from the program. This way you change a value without rebuilding the container image.

warning

ConfigMap is for non-sensitive data. For passwords, tokens and keys, use Secrets.

info

ConfigMaps are created with kubectl. The Nuvion Panel does not have a screen for this feature.


🚀 Before you start​

🚀 1. Create a ConfigMap​

kubectl create configmap app-config --from-literal=APP_MODE=producao --from-literal=APP_IDIOMA=pt-BR

Expected output: configmap/app-config created

🚀 2. Verify the ConfigMap​

kubectl get configmap app-config
kubectl describe configmap app-config

describe shows the keys (APP_MODE, APP_IDIOMA) and their values.

🚀 3. Use the ConfigMap as environment variables​

Create the file pod-config.yaml:

apiVersion: v1
kind: Pod
metadata:
name: pod-config
spec:
containers:
- name: app
image: busybox
command: ["sh", "-c", "echo Modo: $APP_MODE; echo Idioma: $APP_IDIOMA; sleep 3600"]
envFrom:
- configMapRef:
name: app-config

Apply it and see the result:

kubectl apply -f pod-config.yaml
kubectl logs pod-config

Expected output:

Modo: producao
Idioma: pt-BR

🚀 4. Use the ConfigMap as a file​

Some applications read a configuration file. Create a local file called app.properties with this content:

cor=azul
logo=ativo

Create the ConfigMap from the file:

kubectl create configmap app-file --from-file=app.properties

Create the file pod-config-arquivo.yaml, which mounts the ConfigMap in the /config folder:

apiVersion: v1
kind: Pod
metadata:
name: pod-config-arquivo
spec:
containers:
- name: app
image: busybox
command: ["sh", "-c", "sleep 3600"]
volumeMounts:
- name: config
mountPath: /config
volumes:
- name: config
configMap:
name: app-file
kubectl apply -f pod-config-arquivo.yaml
kubectl exec pod-config-arquivo -- cat /config/app.properties

🚀 5. Change a value​

kubectl edit configmap app-config

Change the desired value, save and close the editor.

warning

Environment variables only change when the pod is recreated. Mounted files, on the other hand, are updated automatically, with a few seconds of delay.

✅ How to know it worked​

The logs from step 3 show the values you defined, and the cat from step 4 shows the file content.

❗ Common problems​

SymptomCauseSolution
Pod with CreateContainerConfigErrorThe referenced ConfigMap does not existCheck the name with kubectl get configmap
Old value in the podEnvironment variable does not reloadDelete and recreate the pod
configmap already existsName already in useUse another name or delete the existing one

🧹 Cleanup​

kubectl delete pod pod-config pod-config-arquivo
kubectl delete configmap app-config app-file

➡️ Next step: Secrets

🧠 Questions?​

Talk to our SaveinCloud technical support team!