Kubernetes文件挂载问题

当我们将应用打包成docker镜像并发布时,可能会有替换掉内部配置文件的需求,有别于docker中自带的文件挂载功能,Kubernetes挂载配置文件的时候会覆盖掉原有的文件。这里,我们可以通过创建一个符号链接来挂载宿主机上的配置文件。

首先,执行以下的命令来创建一个configmap

kubectl create configmap conf-config --from-file=application.properties

建立一个yaml启动脚本

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
     app: nginx    
spec:
     containers:
        - name: nginx
          image: nginx
          imagePullPolicy: IfNotPresent
          ports:
          - containerPort: 80
          volumeMounts:
          - name: html-volume
            mountPath: /usr/share/nginx/html
          - name: conf-volume
            mountPath: /etc/nginx/nginx.conf
            subPath: nginx.conf
     restartPolicy: Always
     volumes:
     - name: html-volume
       hostPath:
         path: /home/dx/docker/nginx/html
     - name: conf-volume
       configMap:
         name: conf-config
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort
  sessionAffinity: ClientIP
  selector:
    app: nginx
  ports:
    - port: 80
      nodePort: 31281

你可能感兴趣的:(容器技术,Kubernetes)