根据文档,我在集群中安装了 Ganesha NFS 服务器配置程序作为STS。我只使用安装的块存储 PVC 来运行它。
我为每个命名空间部署一个单独的 NFS 服务器,并且希望限制命名空间中的哪些 pod 可以访问 NFS 服务器。name=nfs-server
我为入口创建以下网络策略,允许从具有标签(所有端口)的同一命名空间中的 Pod访问 NFS 服务器(标记为app-name=my-app
):
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
labels:
name: allow-ingress-nfs
name: allow-ingress-nfs
namespace: "my-namespace"
spec:
ingress:
- from:
- podSelector:
matchLabels:
app-name: my-app
podSelector:
matchLabels:
name: nfs-server
policyTypes:
- Ingress
这是 NFS 服务器 Pod(来自 STS):
apiVersion: v1
kind: Pod
metadata:
labels:
name: nfs-server
name: nfs-server-0
namespace: "my-namespace"
spec:
containers:
- args:
- -provisioner=my-namespace-nfs
env:
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: SERVICE_NAME
value: nfs-server
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
image: registry.k8s.io/sig-storage/nfs-provisioner:v4.0.8
name: nfs-server
volumeMounts:
- mountPath: /export
name: export
volumes:
- name: export
persistentVolumeClaim:
claimName: nfs-export
我尝试从以下 pod 挂载此 NFS 服务器的 PVC:
apiVersion: v1
kind: Pod
metadata:
labels:
app-name: my-app
name: nginx
name: nginx-74c5d976b7-g782p
namespace: "my-namespace"
spec:
containers:
image: my/image
imagePullPolicy: Always
name: nginx
volumeMounts:
- mountPath: /mnt/files
name: files
readOnly: true
volumes:
- name: files
persistentVolumeClaim:
claimName: files
这是PVC:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
finalizers:
- kubernetes.io/pvc-protection
name: files
namespace: "my-namespace"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
storageClassName: my-namespace-nfs
volumeMode: Filesystem
volumeName: pvc-uuid
这是 NFS 存储类别:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: my-namespace-nfs
mountOptions:
- vers=4.1
provisioner: my-namespace-nfs
reclaimPolicy: Delete
volumeBindingMode: Immediate
但是,pod 会陷入CreatingContainer
以下错误:
Mounting command: mount
Mounting arguments: -t nfs -o vers=4.1 10.245.245.191:/export/pvc-name /var/lib/kubelet/pods/id/volumes/kubernetes.io~nfs/pvc-name
Output: mount.nfs: Connection timed out
我在具有非共享 CPU 节点和 GKE 1.26 的 DigitalOcean Kubernetes 1.27(他们使用 Cilium)中观察到相同的行为
如果我删除所有网络策略,问题就会完全消失。
不确定这是否会影响任何东西,但我不在特权模式下运行 Ganesha,并且我通过内存/CPU 限制它。