Kubernetes NFS 服务器 pod 挂载适用于 pod ip 但不适用于 kubernetes 服务
Kubernetes NFS server pod mount works with pod ip but not with kubernetes service
我在 pod 中创建了一个 nfs 服务器以将其用作卷。使用卷创建另一个 pod 时,卷挂载确实与 nfs pod 的 ip 一起工作。由于这个ip不能保证保持不变,所以我为我的nfs pod添加了一个服务,并添加了一个固定的集群ip。使用卷装载启动容器时,它总是失败并出现以下错误:
Unable to mount volumes for pod "nginx_default(35ecd8ec-a077-11e8-b7bc-0cc47a9aec96)": timeout expired waiting for volumes to attach or mount for pod "default"/"nginx". list of unmounted volumes=[nfs-demo]. list of unattached volumes=[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 ist 使用 pod ip 而不是服务 ip?
尝试删除 ClusterIP ip 地址(让 kube 为 nfs 服务分配一个 ip)并在卷装载定义中使用名称 '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
摘自 example of NFS volume 页。
我找到了问题的解决方案:
我的 服务 中缺少端口,而不是 pod。为了找到我需要的端口,我打开了一个控制台到我的 pod (kubectl exec) 并使用“rpcinfo -p”命令列出服务所需的端口。
它确实解决了连接问题,但只是暂时的。这些端口不是静态的,所以并不比使用端口 IP 本身好。
我确实认为可以配置静态端口。
如有类似问题需要进一步阅读:
http://tldp.org/HOWTO/NFS-HOWTO/security.html
https://wiki.debian.org/SecuringNFS
我遇到的第二个问题:只有当nfs-server pod和挂载它的pod在同一个节点上时,挂载才有效。我可以在更新到 kubernetes 版本 1.11 时修复它。
由于我原来的问题已经解决,所以我认为我的问题已经得到解答。
我找到了解决这个问题的新方法,可以设置nfs-server端口固定,然后通过服务挂载nfs-server。可以参考https://wiki.debian.org/SecuringNFS
我在 pod 中创建了一个 nfs 服务器以将其用作卷。使用卷创建另一个 pod 时,卷挂载确实与 nfs pod 的 ip 一起工作。由于这个ip不能保证保持不变,所以我为我的nfs pod添加了一个服务,并添加了一个固定的集群ip。使用卷装载启动容器时,它总是失败并出现以下错误:
Unable to mount volumes for pod "nginx_default(35ecd8ec-a077-11e8-b7bc-0cc47a9aec96)": timeout expired waiting for volumes to attach or mount for pod "default"/"nginx". list of unmounted volumes=[nfs-demo]. list of unattached volumes=[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 ist 使用 pod ip 而不是服务 ip?
尝试删除 ClusterIP ip 地址(让 kube 为 nfs 服务分配一个 ip)并在卷装载定义中使用名称 '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
摘自 example of NFS volume 页。
我找到了问题的解决方案:
我的 服务 中缺少端口,而不是 pod。为了找到我需要的端口,我打开了一个控制台到我的 pod (kubectl exec) 并使用“rpcinfo -p”命令列出服务所需的端口。
它确实解决了连接问题,但只是暂时的。这些端口不是静态的,所以并不比使用端口 IP 本身好。 我确实认为可以配置静态端口。
如有类似问题需要进一步阅读:
http://tldp.org/HOWTO/NFS-HOWTO/security.html
https://wiki.debian.org/SecuringNFS
我遇到的第二个问题:只有当nfs-server pod和挂载它的pod在同一个节点上时,挂载才有效。我可以在更新到 kubernetes 版本 1.11 时修复它。
由于我原来的问题已经解决,所以我认为我的问题已经得到解答。
我找到了解决这个问题的新方法,可以设置nfs-server端口固定,然后通过服务挂载nfs-server。可以参考https://wiki.debian.org/SecuringNFS