Kubernetes
When you are developing, you don't want to deliver your code of the deployment environment with your code together. The ConfigMap is the useful object to help you.
Once you deliver your code of the deployment environment with your code together, it will let your service expose in danger.
A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume.
Somebody will have question between Secret and ConfigMap. Usually, we save the data need to be encrypted in Secret such like password of database or password of API. However, in the ConfigMap we usually save the port number or config file of Redis.
We can use the literal to create the ConfigMap.
Use
kubectl get
to check our ConfigMap.
kubectl get configmap myconfig -o yaml
We can use yaml file to create ConfigMap.
Then create ConfigMap.
kubectl apply -f ./myconfig.yaml
Or you use file to create ConfigMap. First, create a file and write the value.
And, use
kubectl create configmap myconfigfromkey --from-key=[key]=[file path]
to create ConfigMap.
$ kubectl create configmap myconfigfromkey --from-file=fromfilekey=from-key
Create a Pod let ConfigMap as environment varible.
We can see the log of Pod. We will see like this.
We can see
MY_CONFIG_KEY=v1
. It is which we define in the yaml file.
https://kubernetes.io/docs/concepts/configuration/configmap/