Kubernetes 学习之路-存储卷资源
一 数据持久化介绍
我们知道,Pod是由容器组成的,而容器宕机或停止之后,数据就随之丢了,那么这也就意味着我们在做Kubernetes集群的时候就不得不考虑存储的问题,而存储卷就是为了Pod保存数据而生的。存储卷的类型有很多,我们常用到一般有以下几种:
1、emptyDir(临时目录):Pod删除,数据也会被清除,这种存储成为emptyDir,用于数据的临时存储。
2、hostPath(宿主机目录映射)
3、本地的SAN(iSCSI,FC)、NAS(nfs,cifs,http)存储
4、分布式存储(glusterfs,rbd,cephfs)
5、云存储(EBS,Azure Disk)
查看k8s支持的存储类型
[root@master01 ~]# kubectl explain pod.spec.volumes
PVC一直pendng问题解决
[root@homaybd03 storageclass]# kubectl describe pvc test-claim-xxx
Name: test-claim-xxx
Namespace: default
StorageClass: managed-nfs-storage
Status: Pending
Volume:
Labels: <none>
Annotations: volume.beta.kubernetes.io/storage-class: managed-nfs-storage
volume.beta.kubernetes.io/storage-provisioner: egon-nfs-storage
Finalizers: [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode: Filesystem
Used By: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ExternalProvisioning 2m52s (x62 over 18m) persistentvolume-controller waiting for a volume to be created, either by external provisioner "egon-nfs-storage" or manually created by system administrator
[root@homaybd03 storageclass]#
修改apiserver的配置:
[root@k8sm storage]# vi /etc/kubernetes/manifests/kube-apiserver.yaml
apiVersion: v1
···
- --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
- --feature-gates=RemoveSelfLink=false # 添加这个配置
重启下kube-apiserver.yaml
[root@k8sm manifests]# kubectl apply -f kube-apiserver.yaml
[root@k8sm storage]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
my-pvc Bound pvc-ae9f6d4b-fc4c-4e19-8854-7bfa259a3a04 1Mi RWX example-nfs 13m
由于我的 kube-apiserver 是通过二进制的方式安装的服务,则需要这样修改(需要再两个master节点上都要修改):
[root@homaybd03 ~]# vi /etc/systemd/system/kube-apiserver.service
[root@homaybd03 ~]#
修改之后重启服务:
systemctl daemon-reload
systemctl restart kube-apiserver
然后再查看绑定的PVC:
[root@homaybd03 ~]# systemctl daemon-reload
[root@homaybd03 ~]# systemctl restart kube-apiserver
[root@homaybd03 ~]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
test-claim-xxx Bound pvc-e14f7ed4-191d-4451-9805-09c89fbff315 10Mi RWX managed-nfs-storage 43m
[root@homaybd03 ~]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-e14f7ed4-191d-4451-9805-09c89fbff315 10Mi RWX Delete Bound default/test-claim-xxx managed-nfs-storage 4m13s
[root@homaybd03 ~]#
就正常了,查了下为什么?
因为原来是1.20版本(我的是1.23.4)默认禁止使用selfLink。
哦,那啥事selfLink?
selfLink:通过API访问资源自身的URL,例如一个Pod的link可能是/api/v1/namespaces/ns36aa8455/pods/sc-cluster-test-1-6bc58d44d6-r8hld
相关文章:
Kubernetes学习之路(十九)存储卷资源
Kubernetes PVC一直处于Pending状态
K8s 1.23.x版本nfs持久存储报错 persistentvolume-controller waiting for a volume to be created
为者常成,行者常至
自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)