A pod references a ConfigMap that doesn't exist or is in a different namespace. ConfigMaps are namespace-scoped; pods can only access ConfigMaps in their own namespace. Fix by creating the ConfigMap in the correct namespace or marking the reference as optional to allow pod startup.
ConfigMaps are Kubernetes configuration objects that store non-sensitive configuration data as key-value pairs. When a pod spec references a ConfigMap for environment variables or volume mounts, Kubernetes expects to find that ConfigMap in the pod's namespace. ConfigMaps are namespace-scoped resources—there is no built-in cross-namespace access mechanism. If the ConfigMap doesn't exist or is in a different namespace, the kubelet cannot mount the config volume or inject the environment variables. The error blocks pod startup entirely unless the ConfigMap reference is marked as optional.
List all ConfigMaps in the namespace:
kubectl get configmap -n <pod-namespace>
kubectl describe configmap <configmap-name> -n <pod-namespace>The ConfigMap name and namespace must match exactly. If missing, move to the next step.
Examine how the pod references the ConfigMap:
kubectl get pod <pod-name> -n <pod-namespace> -o yaml | grep -A10 configMapLook for:
- volumeMounts[].name and volumes[].configMap.name (for config volumes)
- env[].valueFrom.configMapKeyRef.name (for environment variables)
- envFrom[].configMapRef.name (for bulk env import)
Verify the referenced ConfigMap name matches exactly (case-sensitive).
Create the ConfigMap using YAML or kubectl:
Using kubectl with individual values:
kubectl create configmap app-config \
--from-literal=DATABASE_HOST=localhost \
--from-literal=DATABASE_PORT=5432 \
--from-literal=APP_ENV=production \
-n <pod-namespace>Using kubectl from a file:
kubectl create configmap app-config \
--from-file=config.properties \
-n <pod-namespace>Using YAML manifest:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
namespace: production
data:
DATABASE_HOST: localhost
DATABASE_PORT: "5432"
APP_ENV: production
config.ini: |
[database]
host=localhost
port=5432Apply the manifest:
kubectl apply -f configmap.yamlVerify creation:
kubectl get configmap -n <pod-namespace>
kubectl describe configmap app-config -n <pod-namespace>ConfigMaps cannot be referenced across namespaces. You must either copy or move it:
Copy to pod's namespace:
kubectl get configmap <name> -n <source-namespace> -o yaml | \
sed 's/namespace: <source-namespace>/namespace: <pod-namespace>/' | \
kubectl apply -f -Verify:
kubectl get configmap -n <pod-namespace>Alternative: Move pod to ConfigMap's namespace (if appropriate)
Edit the pod namespace in its manifest and redeploy.
After creating the ConfigMap, the pod should start automatically:
kubectl get pod <pod-name> -n <pod-namespace>
kubectl describe pod <pod-name> -n <pod-namespace>Pod status should transition from Pending to Running. Check logs:
kubectl logs <pod-name> -n <pod-namespace>Verify ConfigMap environment variables were injected:
kubectl exec <pod-name> -n <pod-namespace> -- env | grep -i configIf ConfigMap is optional (not critical for startup), mark it as optional to allow pod startup even if ConfigMap is missing:
For environment variables:
env:
- name: CONFIG_SETTING
valueFrom:
configMapKeyRef:
name: app-config
key: config-setting
optional: true # Pod starts even if ConfigMap or key is missingFor bulk import:
envFrom:
- configMapRef:
name: app-config
optional: trueFor volume mounts:
volumes:
- name: config
configMap:
name: app-config
optional: true # Mount proceeds even if ConfigMap is missingWhen optional is true, the pod starts without the ConfigMap data. Environment variables won't be set, and volume mount paths may be empty.
Ensure ConfigMap keys match what the application expects:
View ConfigMap keys:
kubectl get configmap app-config -n <pod-namespace> -o yamlVerify environment variable names:
kubectl exec <pod-name> -n <pod-namespace> -- env | sortCheck volume mount:
kubectl exec <pod-name> -n <pod-namespace> -- ls -la /etc/config/If using envFrom, invalid environment variable names (e.g., with hyphens or spaces) are silently skipped. Check pod events:
kubectl describe pod <pod-name> -n <pod-namespace> | grep -A5 EventsConfigMaps have a 1 MiB size limit; use external configuration management (Consul, etcd, git-based tools like Flux) for larger configs. Immutable ConfigMaps (immutable: true) cannot be updated once created; deploy new ConfigMap versions and update pod references in your manifests. Volume mount behavior: if mounting ConfigMap to a directory containing application files, those files are hidden/inaccessible (replaced by ConfigMap content). Mount to subdirectories instead (e.g., /etc/config/). For binary or non-string config, use binary fields or store as base64 in stringData. kubelet caches ConfigMaps; updates take 10+ seconds to propagate to pods (depending on kubelet sync period). For immediate config reloads without pod restart, use a sidecar container that watches ConfigMap changes and reloads the application. YAML indentation matters for multi-line config values; test with dry-run before applying. Size considerations: 10,000+ keys in a single ConfigMap may cause performance issues; split into multiple ConfigMaps if needed.
Failed to connect to server: connection refused (HTTP/2)
How to fix "HTTP/2 connection refused" error in Kubernetes
missing request for cpu in container
How to fix "missing request for cpu in container" in Kubernetes HPA
error: invalid configuration
How to fix "error: invalid configuration" in Kubernetes
etcdserver: cluster ID mismatch
How to fix "etcdserver: cluster ID mismatch" in Kubernetes
running with swap on is not supported
How to fix "running with swap on is not supported" in kubeadm