1. 程式人生 > >k8s-17-k8s PV-PVC

k8s-17-k8s PV-PVC

1.NFS-PV-PVC  192.168.56.12上面跑著

[[email protected] pv]# cat pv.yaml 
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /opt/data
    server: 192.168.56.12
[
[email protected]
 pv]#  [[email protected] pv]# cat  pvc.yaml  apiVersion: v1 kind: PersistentVolumeClaim metadata:   name: pvc001 spec:   accessModes:   - ReadWriteMany   resources:     requests:       storage: 5Gi [
[email protected]
 pv]#  [[email protected] pv]# cat pod.yaml  apiVersion: v1 kind: Pod metadata:   name: mypod spec:   containers:     - name: nginx       image: nginx:latest       volumeMounts:       - mountPath: "/usr/share/nginx/html"         name: wwwroot   volumes:   - name: wwwroot     persistentVolumeClaim:       claimName: pvc001 [
[email protected]
 pv]#  kubectl  get pod  -o wide mypod                                         1/1       Running            0          22m       172.17.42.9    192.168.56.11 [[email protected] data]# curl  172.17.42.9 nfs-pvc [[email protected] data]#  檢視nfs  /opt/data下面檔案 [[email protected] data]# pwd /opt/data [[email protected] data]# cat  index.html  nfs-pvc [[email protected] data]#

2.glusterfs-PV-PVC  192.168.56.11和192.168.56.12上面跑著

[[email protected] gl]# cat pv.yaml 
apiVersion: v1
kind: PersistentVolume
metadata:
  name: gluster-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  glusterfs:
    endpoints: "glusterfs-cluster"          ####需要提前建立  16章節已經建立
    path: "nginx-volume"                    ############此處是gluster volume的名稱
    readOnly: false
[[email protected] gl]# 

[[email protected] gl]# cat  pvc.yaml 
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc001
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
[[email protected] gl]# 


[[email protected] gl]# cat pod.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
    - name: nginx
      image: nginx:latest
      volumeMounts:
      - mountPath: "/usr/share/nginx/html"
        name: wwwroot
  volumes:
  - name: wwwroot
    persistentVolumeClaim:
      claimName: pvc001
[[email protected] gl]# 

[[email protected] data]# curl 172.17.81.2
gluster-pvc
[[email protected] data]# 
[[email protected] data]# cat  index.html 
gluster-pvc
[[email protected] data]#