K8S 之 使用NFS卷作为POD存储卷

一、搭建NFS服务器

1、安装NFS服务
yum install nfs-utils -y

2、创建共享挂载目录
mkdir -p /data/nfs-volume

3、设置访问权限
[root@test-operator nfs-volume]# cat /etc/exports
/data/nfs-volume 10.3.153.0/24(rw,no_root_squash)
/data/nfs-volume/nginx_index 10.3.153.0/24(rw,no_root_squash)

4、在/data/nfs-volume/nginx_index下创建index.html文件
[root@test-operator nginx_index]# pwd
/data/nfs-volume/nginx_index
[root@test-operator nginx_index]# cat index.html 
Hello, This is NFS File

二、创建一个NGINX POD,并使用NFS服务器下的NGINX_INDEX静态文件

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: test
spec:
  containers:
    - image: nginx:alpine
      name: web-server
      volumeMounts:
        - mountPath: /usr/share/nginx/html
          name: html
          readOnly: true
      ports:
        - containerPort: 80
          protocol: TCP
  volumes:
    - name: html
      nfs:                   #nfs连接方式
        path: /data/nfs-volume/nginx-index       #把此目录挂载在/usr/share/nginx.html下
        server: test-operator.cedarhd.com        #服务器

三、查看效果

[root@test-nodes1 k8s-yaml-file]# kubectl get pod -o wide -n test
NAME    READY   STATUS    RESTARTS   AGE   IP           NODE                      NOMINATED NODE   READINESS GATES
nginx   1/1     Running   0          57s   172.7.22.6   test-nodes2.cedarhd.com   <none>           <none>
[root@test-nodes1 k8s-yaml-file]# curl 172.7.22.6
Hello, This is NFS File

猜你喜欢

转载自blog.51cto.com/12965094/2489006