一、搭建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