Using ConfigMaps

Here is an example of using ConfigMaps:

# cat configmap/2-7-4_configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: config-example
data:
app.properties: |
name=kubernetes-cookbook
port=443

// create configmap
# kubectl create -f configmap/2-7-4_configmap.yaml
configmap "config-example" created

Similar to Secret, ConfigMaps can be retrieved with environment variables or volumes:

# cat configmap/2-7-4_env.yaml
apiVersion: v1
kind: Pod
metadata:
name: configmap-env
spec:
containers:
- name: configmap
image: ubuntu
command: ["/bin/sh", "-c", "while : ;do echo $APP_NAME; sleep 10; done"]
env:
- name: APP_NAME
valueFrom:
configMapKeyRef:
name: config-example
key: app.properties

// create the pod
#kubectl create -f configmap/2-7-4_env.yaml
pod "configmap-env" created

Alternatively, you can use ConfigMaps volume to retrieve the configuration information:

// using configmap in a pod
# cat configmap/2-7-4_volumes.yaml
apiVersion: v1
kind: Pod
metadata:
name: configmap-volume
spec:
containers:
- name: configmap
image: ubuntu
command: ["/bin/sh", "-c", "while : ;do cat /src/app/config/app.properties; sleep 10; done"]
volumeMounts:
- name: config-volume
mountPath: /src/app/config
volumes:
- name: config-volume
configMap:
name: config-example
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.71.94