To create a ConfigMap in multiple namespaces, you can follow these steps:
-
Create a ConfigMap YAML file: Define your ConfigMap in a YAML file, for example,
configmap.yaml:apiVersion: v1 kind: ConfigMap metadata: name: my-config data: DATABASE_URL: postgres://user:password@host:port/dbname -
Use a script to apply the ConfigMap in multiple namespaces: You can use a shell script to loop through the desired namespaces and create the ConfigMap in each one. Here’s an example script:
#!/bin/bash # List of namespaces namespaces=("namespace1" "namespace2" "namespace3") # Loop through each namespace and create the ConfigMap for ns in "${namespaces[@]}"; do kubectl apply -f configmap.yaml -n "$ns" done -
Run the script: Make the script executable and run it:
chmod +x create-configmap.sh ./create-configmap.sh
This will create the same ConfigMap in each specified namespace. Make sure to replace namespace1, namespace2, and namespace3 with the actual names of the namespaces where you want to create the ConfigMap.
