k8s使用外部供应商代理使用ceph

环境:
ubuntu 16.04
k8s 1.16.0

问题:
k8s已建立provisioner为kubernetes.io/rbd的StorageClass
在声明pvc时出现如下问题:
该pvc处于Pending状态
Message:Failed to provision volume with StorageClass “slow”: failed to create rbd image: executable file not found in $PATH, command output:

原因:
由于kube-controller-manager使用容器方式运行,gcr.io/google_containers/kube-controller-manager-amd64:v1.6.0而该容器不包含rbd,因此kube-controller-manager在创建pv时,无法调用rbd

解决方法:
1、添加 ceph-common 到 hyperkube image 中,具体就是构建一个新的安装了 ceph-common 的同名镜像 hyperkube-amd64 替换官方镜像即可(不建议)
2、使用扩展存储卷插件

$ cd /home/rbd
$ git clone https://github.com/kubernetes-incubator/external-storage.git
$ tree external-storage/ceph/rbd/deploy/
├── README.md
├── non-rbac
│ └── deployment.yaml
└── rbac
├── clusterrole.yaml
├── clusterrolebinding.yaml
├── deployment.yaml
└── serviceaccount.yaml

这里提供 rbac 和 no-rbac 两种方式,因为我们搭建的 k8s 集群时开启了 rbac 认证的,所以采用 rbac 方式来创建该 deployment。ClusterRoleBinding 默认绑定 namespace: default,如果要修改为其他 namespace,对应的 storageClass 中的adminSecretNamespace 也需要对应修改
$ kubectl apply -f rbac/
clusterrole “rbd-provisioner” created
clusterrolebinding “rbd-provisioner” created
deployment “rbd-provisioner” created
serviceaccount “rbd-provisioner” create

我们看到该 rbd-provisioner 的 Deployment 已经成功启动起来了,接下来,最重要的一步就是修改上边 rbd-storage-class.yaml 文件将 provisioner: kubernetes.io/rbd 修改为 provisioner: ceph.com/rbd,意思就是不使用 k8s 内部提供的 rbd 存储类型,而是使用我们刚创建的扩展 rbd 存储

$ vim ceph-class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: ceph-storage
provisioner: ceph.com/rbd
parameters:
monitors: 10.10.3.12:6789
adminId: admin
adminSecretName: ceph-secret
adminSecretNamespace: default
pool: rbd
userId: admin
userSecretName: ceph-secret

重新创建storageclass,使用静态PV创建pod,pod一直处于ContainerCreating状态:

$ kubectl get pod ceph-pod1
NAME READY STATUS RESTARTS AGE
ceph-pod1 0/1 ContainerCreating 0 10s

$ kubectl describe pod ceph-pod1
Warning FailedMount 41s (x8 over 1m) kubelet, node01 MountVolume.WaitForAttach failed for volume “ceph-pv” : fail to check rbd image status with: (executable file not found in $PATH), rbd output: ()
Warning FailedMount 0s kubelet, node01 Unable to mount volumes for pod “ceph-pod1_default(14e3a07d-93a8-11e8-95f6-000c29b1ec26)”: timeout expired waiting for volumes to attach or mount for pod “default”/“ceph-pod1”. list of unmounted volumes=[ceph-vol1]. list of unattached volumes=[ceph-vol1 default-token-v9flt]

问题:MountVolume.WaitForAttach failed for volume “ceph-pv” : fail to check rbd image status with: (executable file not found in $PATH), rbd output: ()
解决:node节点安装最新版的ceph-common解决该问题,ceph集群使用的是最新的mimic版本,而base源的版本太陈旧,故出现该问题

问题:rbd: create error: 2019-12-13 02:46:43.323 7fe2b20d5900 -1 librbd: Format 1 image creation unsupported.
(22) Invalid argument
解决:因为linux内核不支持 image format 1,所以我们要在sc中加入新建镜像时给他规定镜像的格式为2,将storageclass的parameters添加imageFormat: “2”,imageFeatures: “layering”。imageFormat参数默认为"1"。

$ vim ceph-class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: ceph-storage
provisioner: ceph.com/rbd
parameters:
monitors: 10.10.3.12:6789
adminId: admin
adminSecretName: ceph-secret
adminSecretNamespace: default
pool: rbd
userId: admin
userSecretName: ceph-secret
fsType: ext4
imageFormat: “2”
imageFeatures: “layering”

重新创建storageclass,使用静态PV创建pod成功。

参考帖子:https://blog.csdn.net/hxpjava1/article/details/79897240
参考帖子:https://blog.csdn.net/weixin_34345560/article/details/92348845
参考帖子:https://www.cnblogs.com/kuku0223/p/9232858.html
参考文档:https://kubernetes.io/docs/concepts/storage/storage-classes/
参考文档:https://akomljen.com/using-existing-ceph-cluster-for-kubernetes-persistent-storage/
参考文档:https://rootsongjc.gitbooks.io/kubernetes-handbook/content/practice/rbd-provisioner.html
外部存储代理:https://github.com/kubernetes-incubator/external-storage
问题描述:https://github.com/kubernetes/kubernetes/issues/38923

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐