今天就跟大家聊聊有关kubernetes中怎么利用StorageClass绑定ceph rbd,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
一、创建一个k8s
存储池,用于存放数据卷
# ceph osd pool create k8s 64 64
二、创建cephx用户,用于挂载由admin
创建好的rbd
# ceph auth get-or-create client.k8s mon 'allow r' osd 'allow * pool=k8s'
三、获取k8s
用户的key
,以base64
编码
# ceph auth get-key client.k8s|base64
记录输出的内容,如:QVFEQjlmcFpjUE5lS0JBQU40NnZxZ2dIT0dRTEtaeUx1blNjR1E9PQ==
四、获取admin
用户的key
,以base64
编码
# ceph auth get-key client.admin|base64
记录输出的内容,如:QVFDUDNrQllRRVBJR0JBQXFuVXJQbHZQaC9xZEQ2ZGVZOXRoVXc9PQ==
五、创建storage-class-rbd.yaml
---
apiVersion: v1
data:
key: QVFEQjlmcFpjUE5lS0JBQU40NnZxZ2dIT0dRTEtaeUx1blNjR1E9PQ==
kind: Secret
metadata:
name: ceph-secret-user
namespace: default
type: kubernetes.io/rbd
---
apiVersion: v1
data:
key: QVFDUDNrQllRRVBJR0JBQXFuVXJQbHZQaC9xZEQ2ZGVZOXRoVXc9PQ==
kind: Secret
metadata:
name: ceph-secret-admin
namespace: kube-system
type: kubernetes.io/rbd
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: rbd
provisioner: kubernetes.io/rbd
parameters:
monitors: 192.168.1.1:6789,192.168.1.2:6789,192.168.1.3:6789
adminId: admin
adminSecretName: ceph-secret-admin
adminSecretNamespace: kube-system
pool: k8s
userId: k8s
userSecretName: ceph-secret-user
fsType: xfs
imageFormat: "2"
imageFeatures: "layering"
六、创建StorageClass
# kubectl create -f ./storage-class-rbd.yaml
七、创建nginx-statefulset.yaml
, 通过StatefulSet
动态挂载卷
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 2
volumeClaimTemplates:
- metadata:
annotations:
volume.beta.kubernetes.io/storage-class: "rbd" # 这里配置 上面创建的 storageclass 的名称
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 2Gi
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
volumeMounts:
- mountPath: "/usr/share/nginx/html/"
name: html
StatefulSet
会为每个Pod
创建一个rbd
数据卷,并挂载到/usr/share/nginx/html/
目录中,数据卷会随着StatefulSet
的伸缩而动态创建和销毁。
看完上述内容,你们对kubernetes中怎么利用StorageClass绑定ceph rbd有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注天达云行业资讯频道,感谢大家的支持。