安裝NFS服務器
yum -y install nfs-common nfs-utils rpcbind
mkdir /nfsdata
chmod 666 /nfsdata
chown nfsnobody /nfsdata
cat /etc/exports
/nfsdata *(rw,no_root_squash,no_all_squash,sync)
systemctl start rpcbind
systemctl start nfs
所有節點服務器都安裝nfs
yum -y install nfs-common nfs-utils rpcbind
在節點服務器上檢測能否正常使用NFS服務器
[root@k8s-master01 /]
[root@k8s-master01 /]
Export list for 192.168.0.220:
/nfsdata *
[root@k8s-master01 /]
[root@k8s-master01 /]
[root@k8s-master01 test]
[root@k8s-master01 /]
部署PV
[root@k8s-master01 pv]
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs
nfs:
path: /nfsdata
server: 192.168.0.220
[root@k8s-master01 pv]
persistentvolume/nfs-pv created
[root@k8s-master01 pv]
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
nfs-pv 1Gi RWO Retain Available nfs 26s
創建服務並使用PVC
[root@k8s-master01 pv]
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx
serviceName: "nginx"
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: wangyanglinux/myapp:v1
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "nfs"
resources:
requests:
storage: 0.5Gi