我创建了一个 nfs 服务器作为卷,并将其放入一个 pod 中使用。当创建另一个带卷的 pod 时,卷挂载使用 nfs pod 的 ip 工作。由于此 ip 不保证始终相同,我为我的 nfs pod 添加了一个服务并添加了一个固定的集群 ip。但是,在使用卷挂载启动容器时,它总是会因为以下错误而失败:
无法为 pod "nginx_default(35ecd8ec-a077-11e8-b7bc-0cc47a9aec96)" 挂载卷: 超时等待卷附加或安装 pod "default"/"nginx" 的挂载. 未挂载的卷列表=[nfs-demo]。未连接的卷列表=[nfs-demo nginx-test-account-token-2dpgg]
apiVersion: v1
kind: Pod
metadata:
name: nfs-server
labels:
name: nfs-server
spec:
containers:
- name: nfs-server
image: my-nfs-server:v1
args: ["/exports"]
securityContext:
privileged: true
---
kind: Service
apiVersion: v1
metadata:
name: nfs-service
spec:
selector:
name: nfs-server
clusterIP: "10.96.0.3"
ports:
- name: nfs
port: 2049
protocol: UDP
- name: mountd
port: 20048
protocol: UDP
- name: rpcbind
port: 111
protocol: UDP
- name: nfs-tcp
port: 2049
protocol: TCP
- name: mountd-tcp
port: 20048
protocol: TCP
- name: rpcbind-tcp
port: 111
protocol: TCP
我的Pod正在尝试挂载服务器:
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- mountPath: "/exports"
name: nfs-demo
securityContext:
privileged: true
securityContext:
supplementalGroups: [100003]
serviceAccountName: nginx-test-account
volumes:
- name: nfs-demo
nfs:
server: 10.96.0.3
path: "/exports"
readOnly: false
我将这个作为我的NFS服务器镜像的基础:
https://github.com/cpuguy83/docker-nfs-server
https://medium.com/@aronasorman/creating-an-nfs-server-within-kubernetes-e6d4d542bbb9
有人知道为什么挂载在Pod IP上可以工作,但挂载在Service IP上却不行吗?