[英]Kubernetes NFS server pod mount works with pod ip but not with kubernetes service
我在一個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版時修復它。
由於我的原始問題已經解決,我認為我的問題得到了解答。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.