轉發 https://www.jianshu.com/p/cf3e2218f283 轉發 https://www.kubernetes.org.cn/3138.html 注意:configmap不用也罷 1、通過文件創建,把tomcat的配置文件catalina.sh掛到容器內 創建configmap 從文件中創建 [root@lab2 ceshi]# ls /usr/local/k8s/configmap/file/dandang/ catalina.sh [root@lab2 ceshi]# kubectl create configmap dandang-config -n development --from-file=/usr/local/k8s/configmap/file/dandang/catalina.sh [root@lab2 ceshi]# kubectl get configmap -n development NAME DATA AGE dandang-config 1 2m 獲得configmap的yaml文件 [root@lab2 ~]# kubectl get configmap dandang-config -n development -o yaml 從文本中創建,直接指定key的名字,創建后沒有yaml文件 [root@lab2 ~]# kubectl create configmap dandang-configmap -n development --from-file=game-special-key=/usr/local/k8s/configmap/dbconfig.properties 獲得configmap詳細信息 [root@lab2 ~]# kubectl describe configmap dandang-config -n development 創建服務,使用configmap [root@lab2 ceshi]# cat /yunwei/dandang/dandang.yaml apiVersion: v1 kind: ReplicationController metadata: name: dandang namespace: development spec: replicas: 1 template: metadata: labels: name: dandang spec: containers: - name: dandang image: 10.1.1.71:5000/library/dandang.ceshi:v2 ports: - containerPort: 8080 volumeMounts: - name: config-volume mountPath: /root/apache-tomcat-8.5.31/bin volumes: - name: config-volume configMap: name: dandang-config --- apiVersion: v1 kind: Service metadata: name: dandang namespace: development spec: type: NodePort ports: - port: 8080 targetPort: 8080 selector: name: dandang --- apiVersion: extensions/v1beta1 kind: Ingress metadata: name: dandang namespace: development spec: rules: - host: www.dandang.com http: paths: - path: / backend: serviceName: dandang servicePort: 8080 [root@lab2 ceshi]# kubectl create -f /yunwei/dandang/dandang.yaml replicationcontroller/dandang created service/dandang created ingress.extensions/dandang created 2、通過yaml創建 [root@lab2 ceshi]# pwd /yunwei/ceshi [root@lab2 ceshi]# ls configmap.yaml nginx.yaml 創建configmap [root@lab2 configmap]# cat configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: configmap-demo namespace: default data: index.html: | Hello Everyone 創建服務,使用configmap [root@lab2 configmap]# cat nginx.yaml apiVersion: v1 kind: ReplicationController metadata: name: configmap-demo2 spec: template: metadata: labels: app: configmap-demo2 spec: containers: - name: configmap-demo2 image: 192.168.43.65:5000/library/nginx/latest ports: - containerPort: 80 volumeMounts: - name: config-volume mountPath: /usr/share/nginx/html/ volumes: - name: config-volume configMap: name: configmap-demo [root@lab2 ceshi]# kubectl create -f . configmap/configmap-demo created [root@lab2 ceshi]# kubectl get po -o wide NAME READY STATUS RESTARTS AGE IP NODE configmap-demo2-5wkw6 1/1 Running 0 30s 10.244.5.19 lab3 訪問測試: [root@lab2 ceshi]# curl 10.244.5.19:80 Hello Everyone 更新配置文件 [root@lab2 ceshi]# vi configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: configmap-demo namespace: default data: index.html: | Hello World! 重新生成下nginx.yaml 注意:不是configmap.yaml [root@lab2 ceshi]# kubectl create -f nginx.yaml Error from server (AlreadyExists): error when creating "nginx.yaml": replicationcontrollers "configmap-demo2" already exists 訪問測試: [root@master change]# curl http://192.168.0.76 Hello World! 進容器里面看配置文件是否改掉 [root@lab2 ceshi]# kubectl exec -it configmap-demo2-5wkw6 sh # cd /usr/share/nginx/html/ # ls index.html # cat index.html Hello World!
單個文件掛在實例 volumeMounts: - name: gitlab-etc mountPath: "/etc/gitlab/gitlab.rb" subPath: gitlab.rb - name: gitlab-data mountPath: "/var/opt/gitlab" volumes: - name: gitlab-etc configMap: name: gitlab-etc-configmap #Add ConfigMap data to a specific path in the Volume items: - key: gitlab.rb path: gitlab.rb