1. What is a ConfigMap ?
a) Decouples configuration from pods and components.
b) Stores configuration data as key-value pairs.
i)
configuration files.
ii) command line arguments.
iii)
Environment variables.
c) Similar to Secrets but don’t contain sensitive
information.
d) You must create a ConfigMap before referencing it in a
Pod spec.
configFile/properties file -- configMap -- used pods.
(yaml/cmd) (yaml)
2. Create a ConfigMap command.
# kubectl create configmap <map-name> <data-source>
3. Three type of data source.
4. There are two operators used in configmap command.
5. Data source Use Literal :-
i)
Create
configmap a single parameter. (manual parameter defined).
# kubectl create cm firstconfigmap --from-literal=database_ip="192.168.0.21"
ii) Create configmap multiple parameter use literal. (manual parameter defined).
# kubectl create cm secondconfigmap --from-literal=database_ip="192.168.0.21" --from-literal=database_username="root" --from-literal=database_password="sagh12"
# kubectl get cm
NAME DATA
AGE
firstconfigmap 1
3m9s
kube-root-ca.crt
1 42h
NAME :- Created ConfigMap name
DATA :- How many parameter in Configmap file.
AGE :- total create time.
# kubectl describe cm firstconfigmap
How to apply configmap in nginx pods.
# vim firstcontainer.yaml
# kubectl apply -f firstcontainer.yaml
Verify key variable in container environment.
# kubectl exec nginxpod -c ngxcontainer -it bash --> for login container
or
# kubectl exec nginxpod -c ngxcontainer -it env --> for check system variable
6. Create ConfigMaps from directories.
# mkdir -p configure-pod-container/configmap/
# wget https://kubernetes.io/examples/configmap/game.properties -O configure-pod-container/configmap/game.properties
# wget https://kubernetes.io/examples/configmap/ui.properties -O configure-pod-container/configmap/ui.properties
# Create the configmap
# kubectl create configmap game-config --from-file=configure-pod-container/configmap/
# kubectl describe cm game-config
Create a yaml file for directory.
# kubectl get cm game-config -o yaml
7.Creating ConfigMaps from -file.
# curl -OL https://k8s.io/examples/pods/config/redis-config
# cat redis-config
maxmemory 2mb
maxmemory-policy allkeys-lru
# kubectl create configmap example-redis-config --from-file=redis-config
Accessing ConfigMaps in Pods. (use both dierctory and file)
# kubectl apply -f first_pod.yaml
# kubectl exec nginxpod -it bash
# kubectl exec nginxpod -- ls /redis-master (check file)
No comments:
Post a Comment