Kubernetes - Secrets vs ConfigMaps
Secret | ConfigMap | |
---|---|---|
What is? | Secrets are k8s object to manage small amount of sensitive data like password, keys and tokens with less than 1mb size. Secrets encoded and stored inside k8s master etcd data store. Since Secrets will be created outside of pods and containers, these can be used any number of times | ConfigMaps used to seperate container images and its custom configurations so that images are portable and can be run in any environment providing appropriate configuration. `ConfigMap` stores data in key, value format. If any configuration values are sensitive the use `Secret` instead `ConfigMap`. Its must to create `ConfigMap` before hand if we need to refer in pod spec |
Create using `kubectl` |
#syntax kubectl create secret echo -n ‘admin’ > ./username.txt echo -n ‘1f2d1e2e67df’ > ./password.txt kubectl create secret generic db-user-pass –from-file=./username.txt –from-file=./password.txt kubectl create secret generic dev-db-secret –from-literal=username=user –from-literal=password=’S!B\*d$zDsb=’ |
#syntax kubectl create configmap path/to/config/file/application.yaml path/to/config/file/application-prod.properties kubectl create configmap app-config –from-file=path/to/config/file/ #list the content of properties and yml file configuration kubectl get configmaps app-config -o wide kubectl create configmap custom-config –from-literal port=8080 –from-literal https=false |
Create using yaml manifesto files |
|
|
Deploy within Pods, Using Volumes |
|
|
Deploy within Pods, Using environment variables |
|
|