我们有一个在裸机上运行的内部 Kubernetes 集群,我可以在集群中的一个节点(工作节点或主节点)上设置 NFS 服务器吗?如果是,我需要在集群中更改任何内容吗?
答案1
您可以设置一个pod
作为 NFS 服务器。
Docker Hub 上有现成的镜像cpuguy83/nfs 服务器。
要使用它,你需要创建一个服务来将 NFS 服务器公开给集群内的 pod:
kind: Service
apiVersion: v1
metadata:
name: nfs-service
spec:
selector:
role: nfs
ports:
# Open the ports required by the NFS server
# Port 2049 for TCP
- name: tcp-2049
port: 2049
protocol: TCP
# Port 111 for UDP
- name: udp-111
port: 111
并将pod
运行该图像:
kind: Pod
apiVersion: v1
metadata:
name: nfs-server-pod
labels:
role: nfs
spec:
containers:
- name: nfs-server-container
image: cpuguy83/nfs-server
securityContext:
privileged: true
args:
# Pass the paths to share to the Docker image
- /exports
pod
使用 NFS 卷的示例:
kind: Pod
apiVersion: v1
metadata:
name: pod-using-nfs
spec:
# Add the server as an NFS volume for the pod
volumes:
- name: nfs-volume
nfs:
# URL for the NFS server
server: 10.108.211.244 # Change this!
path: /
# In this container, we'll mount the NFS volume
# and write the date to a file inside it.
containers:
- name: app
image: alpine
# Mount the NFS volume in the container
volumeMounts:
- name: nfs-volume
mountPath: /var/nfs
# Write to a file inside our NFS
command: ["/bin/sh"]
args: ["-c", "while true; do date >> /var/nfs/dates.txt; sleep 5; done"]
答案2
查看 NFS-Client Provisioner: https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client