场景:挂载 ConfigMap 中的 config.json 到容器 /app/config.json,不影响 /app/ 路径下的其他文件

configMap 配置

apiVersion: v1
kind: ConfigMap
metadata:
  name: xxx-config
data:
  config.json: |
    {
      "port": "3000"
    }

deployment 配置

apiVersion: apps/v1
kind: Deployment
metadata:
  ***
spec:
  ***
  template:
    spec:
      containers:
      - name: xxx
        ***
        volumeMounts:
          - mountPath: /app/config.json
            name: conf
            subPath: config.json
      volumes:
        - name: conf
          configMap:
            name: xxx-config

例二、将宿主机目录/home/busybox/busybox.conf挂载到容器到/home目录

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: busybox-deploy
spec:
  replicas: 1
  template:
    metadata:
      labels:
        deploy: busybox
    spec:
      containers:
      - name: busybox
        image: hub.docker.com/google_containers/busybox:latest
        command:
        - sleep
        - "3600"
        volumeMounts:
        - mountPath: /home/busybox.conf
          name: conf
          subPath: busybox.conf
      volumes:
      - name: conf
        hostPath:
          path: /home/busybox/
最后修改:2022 年 01 月 20 日 10 : 56 AM
如果觉得我的文章对你有用,请随意赞赏