是否有一种方法可以在Pod之间共享持久卷作为文件?对于我的应用程序,我需要在各个pod之间使用通用的/etc/hosts
。
我想在/ etc / hosts下的pod之间挂载放置在NFS卷文件上的主机文件。由于有状态限制,我在这里不能使用有状态指示。
答案 0 :(得分:3)
如果使用访问模式如ReadWriteMany
或ReadOnlyMany
和NFS supports that装入卷,则可以与卷共享。
但是我相信更好的共享/etc/hosts
的方法是在您的广告连播中使用HostAliases
。
K8s文档中的示例:
apiVersion: v1
kind: Pod
metadata:
name: hostaliases-pod
spec:
restartPolicy: Never
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "foo.local"
- "bar.local"
- ip: "10.1.2.3"
hostnames:
- "foo.remote"
- "bar.remote"
containers:
- name: cat-hosts
image: busybox
command:
- cat
args:
- "/etc/hosts"
✌️</ p>