[root@k8s-master pv]# kubectl create -f pv-01.yaml
persistentvolume/pv-01 created
3.3 查看PV的状态
Availabel:空闲,未被绑定
Bound:已经被PVC绑定
Released:PVC被删除,资源已回收,但是PV未被重新使用
Failed:自动回收失败
c复制代码
[root@k8s-master pv]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-01 5Gi 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)
c复制代码
[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 0 2m18s
[root@k8s-master sc]# kubectl get deployments.apps -n kube-system
NAME READY UP-TO-DATE AVAILABLE AGE
coredns 2/2 2 2 7d22h
metrics-server 1/1 1 1 2d23h
nfs-client-provisioner 0/1 1 0 25s
5.2.7 创建存储类 (Storageclass)
c复制代码
[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资源
c复制代码
[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 0 23h
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 0 20h
nfs-volume-pod-1 1/1 Running 0 18h
nfs-volume-pod-2 1/1 Running 0 18h
nginx-deploy-6fb8d6548-8khhv 1/1 Running 26 (35m ago) 26h
nginx-deploy-6fb8d6548-fd9tx 1/1 Running 26 (35m ago) 26h
nginx-sc-0 0/1 Pending 0 52s
5.2.9 pod和pvc的状态都是Pending,pv并没有被创建出来
c复制代码
# pod的状态是Pending
[root@k8s-master sc]# kubectl get po | grep -E 'NAME|nginx-sc'
NAME READY STATUS RESTARTS AGE
nginx-sc-0 0/1 Pending 0 6m34s
# 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的日志
c复制代码
[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-sc
controller-revision-hash=nginx-sc-865bd98db8
statefulset.kubernetes.io/pod-name=nginx-sc-0
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: StatefulSet/nginx-sc
Containers:
nginx-sc:
Image: nginx
Port: <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 Status
PodScheduled False
Volumes:
nginx-sc-test-pvc:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: nginx-sc-test-pvc-nginx-sc-0
ReadOnly: false
kube-api-access-2kv55:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
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.