Home > Archives > ConfigMap示例

ConfigMap示例

Publish:

ConfigMap

development -> staging -> production

---
# my-redis.conf
bind 127.0.0.1
port 6379
maxclients 10000
maxmemory 50mb
maxmemory-policy volatile-lru
syslog-enabled yes
dir /var/lib/redis
dbfilename redis.dump.rdb
databases 1
appendfsync everysec
save 600 10

kubectl create configmap redis-config --from-file=my-reids.conf
kubectl get configmap
kubectl describe configmap redis-config

---
kubectl create configmap mysql-host --from-literal=ip=127.0.0.1
kubectl describe configmap mysql-host
kubectl delete configmap mysql-host

---
# my-nginx.conf
server {
    listen            80;
    server_name       localhost;

    location / {
        proxy_bind 127.0.0.1;
        proxy_pass http://127.0.0.1:3000;
    }

    error_page 500 502 503 504    /50x.html;
    location = /50x.html {
        root    /usr/share/nginx/html;
    }
}

kubectl create configmap nginx-conf --from-file=my-nginx.conf

---
# my-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: apiserver
  labels:
    app: webserver
	tier: backend
spec:
  containers:
  - name: nodejs-app
    image: baoguoding/demo
	ports:
	- containerPort: 3000
  - name: nginx
    image: nginx:1.13
	ports:
	- containerPort: 80
	volumeMounts:
	- name: nginx-conf-volume
	  mountPath: /etc/nginx/conf.d
  volumes:
  - name: nginx-conf-volume
    configmap:
	  name: nginx-conf
	  items:
	  - key: my-nginx.conf
	    path: my-nginx.conf

kubectl create -f my-pod.yaml

---
kubectl expose pod apiserver --port=80 --type=NodePort
kubectl get svc

参考

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo