创建pv 创建pvc 创建pvc应用的pod pv无法删除

  1. 创建pv(nfs)
    要准备另一台机器上有nfs应用
    我这里准备的是192.168.10.203
yum install -y nfs-utils
mkdir /data/volumes -pv
mkdir /data/volumes/v{1,2,3,4,5}
vi /etc/exports

   /data/volumes/v1 192.168.10.0/24(rw,no_root_squash)
   /data/volumes/v2 192.168.10.0/24(rw,no_root_squash)
   /data/volumes/v3 192.168.10.0/24(rw,no_root_squash)
   /data/volumes/v4 192.168.10.0/24(rw,no_root_squash)
   /data/volumes/v5 192.168.10.0/24(rw,no_root_squash)

exportfs -arv
reboot showmount -e 
apiVersion: v1
kind: PersistentVolume
metadata: 
  name: pod-demo-pv001
  labels:
    name: pv001
spec: 
  nfs: 
    path: /data/volumes/v1
    server: 192.168.10.203
  accessModes: ["ReadWriteMany","ReadWriteOnce"]
  capacity:
    storage: 5Gi
---
apiVersion: v1
kind: PersistentVolume
metadata: 
  name: pod-demo-pv002
  labels:
    name: pv002
spec: 
  nfs: 
    path: /data/volumes/v2
    server: 192.168.10.203
  accessModes: ["ReadWriteMany","ReadWriteOnce"]
  capacity:
    storage: 2Gi
---
apiVersion: v1
kind: PersistentVolume
metadata: 
  name: pod-demo-pv003
  labels:
    name: pv003
spec: 
  nfs: 
    path: /data/volumes/v3
    server: 192.168.10.203
  accessModes: ["ReadWriteMany","ReadWriteOnce"]
  capacity:
    storage: 3Gi
---
apiVersion: v1
kind: PersistentVolume
metadata: 
  name: pod-demo-pv004
  labels:
    name: pv004
spec: 
  nfs: 
    path: /data/volumes/v4
    server: 192.168.10.203
  accessModes: ["ReadWriteMany","ReadWriteOnce"]
  capacity:
    storage: 4Gi
---
apiVersion: v1
kind: PersistentVolume
metadata: 
  name: pod-demo-pv005
  labels:
    name: pv005
spec: 
  nfs: 
    path: /data/volumes/v5
    server: 192.168.10.203
  accessModes: ["ReadWriteMany","ReadWriteOnce"]
  capacity:
    storage: 5Gi
  1. 创建pvc 和 pod
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mypvc
  namespace: default
spec:
  accessModes: ["ReadWriteMany"]
  resources:
    requests:
      storage: 2Gi
---
apiVersion: v1
kind: Pod
metadata: 
  name: pod-demo-mypvc
  namespace: default
spec: 
  containers:
  - name: myapp
    image: ikubernetes/myapp:v1 
    volumeMounts: 
    - name: html
      mountPath: /usr/share/nginx/html/
  volumes: 
  - name: html 
    persistentVolumeClaim: 
      claimName: mypvc
  1. 删除 pod–>pvc–>pv
    碰到有的pv删不掉
    如图所示
    在这里插入图片描述
kubectl describe pvc PVC_NAME | grep Finalizers
kubectl patch pv PVC_NAME -p '{"metadata":{"finalizers":null}}'

你可能感兴趣的:(kubernetes,docker,运维笔记,运维,kubernetes,云计算)