Skip to content

Commit

Permalink
Update nfs-pv.md
Browse files Browse the repository at this point in the history
  • Loading branch information
unixhot authored Aug 27, 2019
1 parent e5a734f commit 32066a2
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions docs/nfs-pv.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
1.安装并配置NFS
# 使用NFS作为Kubernetes持久化存储PV/PVC

## 1.安装并配置NFS
```
[root@linux-node1 ~]# yum install -y nfs-utils rpcbind
[root@linux-node1 ~]# mkdir -p /data/k8s-nfs
Expand All @@ -12,7 +14,7 @@
[root@linux-node1 ~]# systemctl start rpcbind nfs
```

2.创建PV
## 2.创建PV
```
[root@linux-node1 ~]# vim nfs-pv.yaml
apiVersion: v1
Expand All @@ -38,3 +40,59 @@ persistentvolume "pv-demo" created
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-demo 1Gi RWO Recycle Available nfs 15s
```

## 3.创建PVC
```
[root@linux-node1 ~]# vim nfs-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-demo
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: nfs
[root@linux-node1 ~]# kubectl create -f nfs-pvc.yaml
persistentvolumeclaim "pvc-demo" created
[root@linux-node1 ~]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-demo Bound pv-demo 1Gi RWO nfs 6s
```

## 4.使用PVC
```
[root@linux-node1 ~]# vim nginx-deployment-pvc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.13.12
ports:
- containerPort: 80
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: pvc-demo
volumes:
- name: pvc-demo
persistentVolumeClaim:
claimName: pvc-demo
```

0 comments on commit 32066a2

Please sign in to comment.