configmap volume mount
Create ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: log-config
data:
log_level: info
YAML
복사
pod /etc/config/ 경로로 마운트
apiVersion: v1
kind: Pod
metadata:
name: configmap-pod
spec:
containers:
- name: test
image: busybox:1.28
command: ['sh', '-c', 'echo "The app is running!" && tail -f /dev/null']
volumeMounts:
- name: config-vol
mountPath: /etc/config
volumes:
- name: config-vol
configMap:
name: log-config
items:
- key: log_level
path: log_level
YAML
복사
kubectl apply -f log-config.yaml && kubectl apply -f log-pod.yaml
Shell
복사
k exec -it configmap-pod -- cat /etc/config/log_level
> info
Shell
복사
응용 - configmap으로 index.html 작성하고 nginx pod에 띄우기
Create ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
index.html: hello world
YAML
복사
pod /usr/share/nginx/html/ 경로로 마운트
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx-container
image: nginx:latest
volumeMounts:
- name: nginx-vol
mountPath: /usr/share/nginx/html/
volumes:
- name: nginx-vol
configMap:
name: nginx-config
items:
- key: index.html
path: index.html
YAML
복사
kubectl apply -f nginx-config.yaml && kubectl apply -f nginx-pod.yaml
Shell
복사
kubectl exec -it nginx-pods -- curl localhost
> hello world
Shell
복사