Kubernetes ConfigMap
kubectl create -f web-cm.yaml
root@kuberm:~/kube1.6config/deploy/configmap# cat web-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: hadoop-env
data:
CORE_CONF_fs_defaultFS: "hdfs://namenode:8020"
CORE_CONF_hadoop_http_staticuser_user: "root"kubectl create -f web-cm2.yaml
root@kuberm:~/kube1.6config/deploy/configmap# cat web-cm2.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: special-config
namespace: default
data:
special.how: very
special.type: charm###kubectl create -f web-controller.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: webconfig
namespace: default
labels:
app: webconfig
spec:
replicas: 1
selector:
matchLabels:
app: webconfig
template:
metadata:
labels:
app: webconfig
group: lb
spec:
terminationGracePeriodSeconds: 60
containers:
- name: webconfig
# Any image is permissable as long as: 1. It serves a 404 page at /
# and 2. It serves 200 on a /healthz endpoint
image: 172.16.155.136:5000/uwebserverv6
env:
- name: SPECIAL_LEVEL_KEY
valueFrom:
configMapKeyRef:
name: special-config
key: special.how
- name: SPECIAL_TYPE_KEY
valueFrom:
configMapKeyRef:
name: special-config
key: special.type
envFrom:
- configMapRef:
name: hadoop-env
ports:
- containerPort: 8000
resources:
limits:
cpu: 10m
memory: 20Mi
requests:
cpu: 10m
memory: 20MiReuslt
You will see the result.
- if you use
envFrom, you can directly use the parameter mapped fromconfigmapyou defined - if you use
env, you can redefine the key to the value that you defined inconfigmap. It's quite convinuence, if every body defined in different key but with same value. You can now adding theenv and valuefromparameter to trasfer the key-value pair.
root@webconfig-3249689838-fglf7:/# env
HOSTNAME=webconfig-3249689838-fglf7
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT=tcp://172.18.0.1:443
CORE_CONF_fs_defaultFS=hdfs://namenode:8020
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_HOST=172.18.0.1
LS_COLORS=
SPECIAL_TYPE_KEY=charm
SPECIAL_LEVEL_KEY=very
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
SHLVL=1
HOME=/root
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_SERVICE_PORT_HTTPS=443
CORE_CONF_hadoop_http_staticuser_user=root
LESSOPEN=| /usr/bin/lesspipe %s
KUBERNETES_PORT_443_TCP_ADDR=172.18.0.1
KUBERNETES_PORT_443_TCP=tcp://172.18.0.1:443
LESSCLOSE=/usr/bin/lesspipe %s %s
_=/usr/bin/env
No comments:
Post a Comment