[k8s]subpath解决cm覆盖目录问题

时间:2021-02-05 19:06:21

参考

[k8s]subpath解决cm覆盖目录问题

发现cm老覆盖容器原有目录里的内容,后来不得不通过in -s的方式来搞cm, 先将cm挂到/tmp下,然后ln -s文件到指定目录.

后来发现个cm的subpath特性可以解决这个问题

写了busybox的cm和rc测试cm subpath

cat > busybox-cm.yaml <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: busybox-cm
labels:
addonmanager.kubernetes.io/mode: EnsureExists
data:
Corefile: |
.:53 {
errors
log stdout
health
kubernetes cluster.local 172.21.0.0/16
prometheus
proxy . /etc/resolv.conf
cache 30
}
EOF
cat > busybox.yaml <<EOF
apiVersion: v1
kind: ReplicationController
metadata:
name: busybox-cm
labels:
app: busybox-cm
spec:
replicas: 1
selector:
app: busybox-cm
template:
metadata:
name: busybox-cm
labels:
app: busybox-cm
spec:
containers:
- image: busybox
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
name: busybox
volumeMounts:
- name: config-volume
mountPath: /usr/Corefile
subPath: Corefile
restartPolicy: Always
volumes:
- name: config-volume
configMap:
name: busybox-cm
items:
- key: Corefile
path: Corefile
EOF

[k8s]subpath解决cm覆盖目录问题