kubernetes comfig subpath

本文探讨了Docker和Kubernetes在挂载volume时的不同行为。在Docker中,volume可以将文件挂载到特定目录且保留原有内容,而在Kubernetes中,使用subPath挂载可能导致原有目录内容被覆盖。通过一个配置示例,展示了如何在Kubernetes中挂载ConfigMap以避免影响原有目录结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 docker 中的 volume 可以 mount 文件到特定目录,同时保留原有目录不变;同样的 mount 放到 Kubernetes 却变成了:只是把 mount 的几个文件直接放到了根目录,原有目录中文件消失。在很多场景下,我们会希望只是挂载一个文件到容器内部某个目录,而不影响原有目录。

apiVersion: v1
kind: ConfigMap
metadata:
  name: special-config
  namespace: default
data:
  special.level: very
  special.type: |-
    property.1=value-1
    property.2=value-2
    property.3=value-3
---
apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
    - name: test-container
      image: busybox:latest
      imagePullPolicy: IfNotPresent
      command: [ "/bin/sh", "-c", "ls /etc/", "-c", "ls /usr" ]
      volumeMounts:
      - name: config-volume
        mountPath: /etc/special.level
        subPath: special.level
      - name: config-volume
        mountPath: /usr/special.type
        subPath: special.type
  volumes:
    - name: config-volume
      configMap:
        # Provide the name of the ConfigMap containing the files you want
        # to add to the container
        name: special-config
  restartPolicy: Never

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值