AVa*_*arf 5 storage nfs kubernetes
我们有一个在裸机上运行的内部 Kubernetes 集群,我可以在集群中的一个节点(工作节点或主节点)上设置 NFS 服务器吗?如果是,我需要更改集群中的任何内容吗?
小智 7
您可以设置一个pod充当 NFS 服务器。
Docker Hub cpuguy83/nfs-server上有一个准备好的镜像。
要使用它,您需要创建一个服务来将 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
Run Code Online (Sandbox Code Playgroud)
以及pod将运行该图像的 a :
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
Run Code Online (Sandbox Code Playgroud)
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"]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9495 次 |
| 最近记录: |