我在一个pod中创建了一个nfs服务器,将其用作卷。使用卷创建另一个pod时,卷装置可以使用nfs pod的ip。由于这个ip不保证保持不变,我为我的nfs pod添加了一项服务并添加了一个固定的集群ip。使用卷装入启动容器时,它始终失败并显示以下错误:
无法为pod“nginx_default(35ecd8ec-a077-11e8-b7bc-0cc47a9aec96)”安装卷:超时已过期,等待为“默认”/“nginx”pod附加或装入卷。未安装的卷列表= [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
有没有人知道为什么mount正在使用pod ip而不是服务ip?
我找到了解决这个问题的新方法,你可以设置nfs-server端口修复,然后按服务挂载nfs-server。你可以参考https://wiki.debian.org/SecuringNFS
尝试删除ClusterIP IP地址(让kube分配ip到nfs服务)并在卷安装定义中使用名称'nfs-service'。确保nginx pod和nfs服务位于同一名称空间中。
正如Bal Chua所提到的,您可能没有在nfs-server pod定义中导出nfs端口。
NFS服务器,pod.yaml
apiVersion: v1beta1
kind: Pod
id: nfs-server
desiredState:
manifest:
version: v1beta1
id: nfs-server
containers:
- name: nfs-server
image: jsafrane/nfs-data
privileged: true
ports:
- name: nfs
containerPort: 2049
protocol: tcp
labels:
name: nfs-server
NFS服务器,service.yaml
id: nfs-server
kind: Service
apiVersion: v1beta1
port: 2049
protocol: tcp
selector:
name: nfs-server
我找到了解决问题的方法:
我的服务中缺少端口,而不是pod。为了找到我需要的端口,我打开了一个控制台到我的pod(kubectl exec)并使用“rpcinfo -p”命令列出了服务所需的端口。
它确实解决了连接问题,但只是暂时的。这些端口不是静态的,因此它并不比使用端口IP本身好。我认为可以配置静态端口。
如果有类似问题的人需要进一步阅读:
http://tldp.org/HOWTO/NFS-HOWTO/security.html
https://wiki.debian.org/SecuringNFS
我遇到的第二个问题:只有当nfs-server pod和安装它的pod位于同一节点上时,mount才有效。我可以在更新到kubernetes 1.11版时修复它。
由于我的原始问题已经解决,我认为我的问题得到了解答。