[root@k8s-master pv]# kubectl create -f pv-01.yaml
persistentvolume/pv-01 created
3.3 查看PV的状态
Availabel:空闲,未被绑定
Bound:已经被PVC绑定
Released:PVC被删除,资源已回收,但是PV未被重新使用
Failed:自动回收失败
[root@k8s-master pv]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-015Gi RWX Retain Available slow 16s
[root@k8s-master sc]# kubectl apply -f nfs-provisioner-rbac.yaml
clusterrole.rbac.authorization.k8s.io/nfs-client-provisioner-runner created
clusterrolebinding.rbac.authorization.k8s.io/run-nfs-client-provisioner created
role.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner created
rolebinding.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner created
5.2.6 创建制备器 (provisioner)
[root@k8s-master sc]# kubectl apply -f nfs-provisioner-depolyment.yaml
serviceaccount/nfs-client-provisioner created
deployment.apps/nfs-client-provisioner created[root@k8s-master sc]# kubectl get serviceaccounts -n kube-system | grep nfs
nfs-client-provisioner 02m18s[root@k8s-master sc]# kubectl get deployments.apps -n kube-system
NAME READY UP-TO-DATE AVAILABLE AGE
coredns 2/2227d22h
metrics-server 1/1112d23h
nfs-client-provisioner 0/11025s
5.2.7 创建存储类 (Storageclass)
[root@k8s-master sc]# kubectl apply -f nfs-storage-class.yaml
storageclass.storage.k8s.io/managed-nfs-storage created
[root@k8s-master sc]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
managed-nfs-storage fuseim.pri/ifs Delete Immediate false 6s
5.2.8 创建应用nginx资源
[root@k8s-master sc]# kubectl create -f nfs-sc-demo-statefulset.yaml
service/nginx-sc created
statefulset.apps/nginx-sc created
[root@k8s-master sc]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
csdn-svc-external-domian ExternalName <none> www.lan-he.com.cn <none>2d7h
kubernetes ClusterIP 10.1.0.1<none>443/TCP 7d22h
nginx-sc NodePort 10.1.94.155<none>80:31819/TCP 7s
nginx-svc NodePort 10.1.224.211<none>80:31231/TCP 2d22h
nginx-svc-external ClusterIP 10.1.63.181<none>80/TCP 2d17h
[root@k8s-master sc]# kubectl get po
NAME READY STATUS RESTARTS AGE
configfile-po 0/1 Completed 023h
dns-test 1/1 Running 2(32h ago)3d17h
emptydir-volume-pod 2/2 Running 38(40m ago)19h
fluentd-59k8k 1/1 Running 1(32h ago)3d
fluentd-hhtls 1/1 Running 1(32h ago)3d
host-volume-pod 1/1 Running 020h
nfs-volume-pod-11/1 Running 018h
nfs-volume-pod-21/1 Running 018h
nginx-deploy-6fb8d6548-8khhv 1/1 Running 26(35m ago)26h
nginx-deploy-6fb8d6548-fd9tx 1/1 Running 26(35m ago)26h
nginx-sc-00/1 Pending 052s
5.2.9 pod和pvc的状态都是Pending,pv并没有被创建出来
#pod的状态是Pending[root@k8s-master sc]# kubectl get po | grep -E 'NAME|nginx-sc'
NAME READY STATUS RESTARTS AGE
nginx-sc-00/1 Pending 06m34s#pvc的状态也是Pending[root@k8s-master sc]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
nginx-sc-test-pvc-nginx-sc-0 Pending managed-nfs-storage 7m59s#pv是没有动态创建出来的[root@k8s-master sc]# kubectl get pv
No resources found
5.2.10 查看下pod的日志
[root@k8s-master sc]# kubectl describe po nginx-sc-0
Name: nginx-sc-0
Namespace:default
Priority:0
Service Account:default
Node:<none>
Labels: app=nginx-sccontroller-revision-hash=nginx-sc-865bd98db8statefulset.kubernetes.io/pod-name=nginx-sc-0
Annotations:<none>
Status: Pending
IP:
IPs:<none>
Controlled By: StatefulSet/nginx-sc
Containers:nginx-sc:Image: nginxPort:<none>Host Port:<none>Environment:<none>Mounts:/usr/share/nginx/html from nginx-sc-test-pvc(rw)/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-2kv55 (ro)
Conditions:Type StatusPodScheduled False
Volumes:nginx-sc-test-pvc:Type:PersistentVolumeClaim(a reference to a PersistentVolumeClaim in the same namespace)ClaimName: nginx-sc-test-pvc-nginx-sc-0ReadOnly: falsekube-api-access-2kv55:Type:Projected(a volume that contains injected data from multiple sources)TokenExpirationSeconds:3607ConfigMapName: kube-root-ca.crtConfigMapOptional:<nil>DownwardAPI: true
QoS Class: BestEffort
Node-Selectors:<none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for300snode.kubernetes.io/unreachable:NoExecute op=Exists for300s
Events:Type Reason Age From Message-------------------------Warning FailedScheduling 8m57s default-scheduler 0/3 nodes are available:3 pod has unbound immediate PersistentVolumeClaims. preemption:0/3 nodes are available:3 Preemption is not helpful for scheduling.Warning FailedScheduling 8m56s default-scheduler 0/3 nodes are available:3 pod has unbound immediate PersistentVolumeClaims. preemption:0/3 nodes are available:3 Preemption is not helpful for scheduling.
# 应用的状态
[root@k8s-master sc]# kubectl get po | grep -Ei 'name|nginx-sc'
NAME READY STATUS RESTARTS AGE
nginx-sc-01/1 Running 027m#pv的状态[root@k8s-master sc]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
nginx-sc-test-pvc-nginx-sc-0 Bound pvc-070c2e12-e5ef-47fe-bbbb-c5f864e311b5 1Gi RWX managed-nfs-storage 27m#pv的状态[root@k8s-master sc]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-070c2e12-e5ef-47fe-bbbb-c5f864e311b5 1Gi RWX Delete Bound default/nginx-sc-test-pvc-nginx-sc-0 managed-nfs-storage 119s# 制备器的状态
[root@k8s-master sc]# kubectl get po -n kube-system | grep -E 'NAME|nfs'
NAME READY STATUS RESTARTS AGE
nfs-client-provisioner-64f976f4cd-7gdq7 1/1 Running 04m36s