Kubernetes NFS 服务器 pod 挂载适用于 pod ip,但不适用于 kubernetes 服务

alb*_*brr 6 nfs kubernetes

我在 pod 中创建了一个 nfs 服务器以将其用作卷。使用卷创建另一个 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
Run Code Online (Sandbox Code Playgroud)

我的 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
Run Code Online (Sandbox Code Playgroud)

我用它作为我的 nfs 服务器镜像的基础:

https://github.com/cpuguy83/docker-nfs-server

https://medium.com/@aronasorman/creating-an-nfs-server-within-kubernetes-e6d4d542bbb9

有谁知道为什么挂载与 pod ip 一起工作而不是与服务 ip 一起工作?

alb*_*brr 0

我找到了解决我的问题的方法:

我的服务中缺少端口,而不是 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 版本时修复它。

由于我原来的问题已经解决,我认为我的问题得到了解答。