apiVersion: v1
kind: ConfigMap
metadata:
name: config-dev
namespace: default
data:
DB_URL: localhost
DB_USER: testuser
DB_PASS: dkagh1.
DEBUG_INFO: debug
root@instance-1:~/kubernetes-sample/configmap# kubectl describe configmaps config-dev
Name: config-dev
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
DB_PASS:
----
dkagh1.
DB_URL:
----
localhost
DB_USER:
----
testuser
DEBUG_INFO:
----
debug
Events: <none>
config-dev 라는 컨피그맵에는 .data의 하위 필드에 4가지의 키와 밸류가 있었다. 우리는 그 중 DEBUG_INFO란 변수를 가져와서 사용할 것이다. (일부만 가져옴)
# Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: configapp
labels:
app: configapp
spec:
replicas: 1
selector:
matchLabels:
app: configapp
template:
metadata:
labels:
app: configapp
spec:
containers:
- name: testapp
image: arisu1000/simple-container-app:latest
ports:
- containerPort: 8080
**env:
- name: DEBUG_LEVEL
valueFrom:
configMapKeyRef:
name: config-dev
key: DEBUG_INFO**
---
# Service
apiVersion: v1
kind: Service
metadata:
labels:
app: configapp
name: configapp-svc
namespace: default
spec:
ports:
- nodePort: 30800
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: configapp
type: NodePort