今天就跟大家聊聊有关kubernetes中ceph RBD如何使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
1.在Ceph存储集群中创建池
1.1 规划池
(OSD * 100)
PG总数= ------------
泳池大小
如:群集有9个 OSD,默认池大小为3。因此,PG为.
9 * 100
PG总数= ------------ = 300
3
1.2 创建pool
1.2.1 使用命令创建
创建一个名为kube的新池,其放置组数为100
ceph osd pool create kube 150
语法:
ceph osd pool create {pool-name} {pg-num}
{pool-name} – 池的名称。它必须是唯一的。
{pg-num} –池的放置组总数。
查看创建结果
ceph osd lspools
1 device_health_metrics
2 kube
1.2.2 使用web创建
略
1.3 关联pool到应用
ceph osd pool application enable kube rbd
补充:
--- Ceph Filesystem ---
$ sudo ceph osd pool application enable <pool-name> cephfs
--- Ceph Block Device ---
$ sudo ceph osd pool application enable <pool-name> rbd
--- Ceph Object Gateway ---
$ sudo ceph osd pool application enable <pool-name> rgw
1.4 适用于RBD的pool 需要初始化
rbd pool init kube
补充:
//要禁用应用程序,请使用:
ceph osd pool application disable <poolname> <app> {--yes-i-really-mean-it}
//获取特定池或全部池的I / O信息
ceph osd pool stats [{pool-name}]
//删除池,请执行:
ceph osd pool delete {pool-name} [{pool-name} --yes-i-really-really-mean-it]
2.在Kubernetes上部署Ceph Provisioner
2.1 创建资源文件
cat >external-storage-rbd-provisioner.yaml<<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
name: rbd-provisioner
namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: rbd-provisioner
rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "update", "patch"]
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: [""]
resources: ["services"]
resourceNames: ["kube-dns"]
verbs: ["list", "get"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: rbd-provisioner
subjects:
- kind: ServiceAccount
name: rbd-provisioner
namespace: kube-system
roleRef:
kind: ClusterRole
name: rbd-provisioner
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: rbd-provisioner
namespace: kube-system
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: rbd-provisioner
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: rbd-provisioner
subjects:
- kind: ServiceAccount
name: rbd-provisioner
namespace: kube-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: rbd-provisioner
namespace: kube-system
spec:
selector:
matchLabels:
app: rbd-provisioner
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
app: rbd-provisioner
spec:
containers:
- name: rbd-provisioner
image: "quay.io/external_storage/rbd-provisioner:v2.0.0-k8s1.11"
env:
- name: PROVISIONER_NAME
value: ceph.com/rbd
serviceAccount: rbd-provisioner
EOF
2.2 应用文件以创建资源
kubectl apply -f external-storage-rbd-provisioner.yaml
serviceaccount/rbd-provisioner created
clusterrole.rbac.authorization.k8s.io/rbd-provisioner created
clusterrolebinding.rbac.authorization.k8s.io/rbd-provisioner created
role.rbac.authorization.k8s.io/rbd-provisioner created
rolebinding.rbac.authorization.k8s.io/rbd-provisioner created
deployment.apps/rbd-provisioner created
2.3 确认RBD卷 pod正在运行
kubectl get pods -l app=rbd-provisioner -n kube-system
NAME READY STATUS RESTARTS AGE
rbd-provisioner-8ddb7f6c7-zssl5 1/1 Running 0 18s
3.创建配置storageclass的Secret
3.1 创建k8s访问ceph的用户 在ceph的mon或者admin节点
ceph auth get-or-create client.kube mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=kube' -o ceph.client.kube.keyring
3.2 查看key(在ceph的mon或者admin节点)
获取 admin
用户的 key
( ceph
的 admin
用户,非 kubernetes
的用户)
ceph auth get-key client.admin
AQAXcD9f2B24GhAA/RJvMLvnpO0zAb+XYQ2YuQ==
获取 kube
用户的 key
ceph auth get-key client.kube
AQC8fz9fNLGyIBAAyOu9bGSx7zA2S3b4Ve4vNQ==
3.3 密钥添加为Kubernetes中的secret
3.3.1 创建 admin secret
kubectl create secret generic ceph-secret --type="kubernetes.io/rbd" \
--from-literal=key=AQAXcD9f2B24GhAA/RJvMLvnpO0zAb+XYQ2YuQ== \
--namespace=kube-system
3.3.2 在 default 命名空间创建pvc用于访问ceph的 secret
kubectl create secret generic ceph-user-secret --type="kubernetes.io/rbd" \
--from-literal=key=AQC8fz9fNLGyIBAAyOu9bGSx7zA2S3b4Ve4vNQ== \
--namespace=default
3.3.3 查看创建结果
kubectl get secrets ceph-admin-secret -n kube-system
NAME TYPE DATA AGE
ceph-admin-secret kubernetes.io/rbd 1 22h
4. 配置StorageClass
4.1 创建资源文件
cat >storageclass-ceph-rdb.yaml<<EOF
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: kube-ceph-rdb
provisioner: ceph.com/rbd
parameters:
monitors: 172.27.9.211:6789,172.27.9.212:6789,172.27.9.215:6789
adminId: admin
adminSecretName: ceph-secret
adminSecretNamespace: kube-system
pool: kube
userId: kube
userSecretName: ceph-user-secret
fsType: ext4
imageFormat: "2"
imageFeatures: "layering"
EOF
4.2 创建yaml
kubectl apply -f storageclass-ceph-rdb.yaml
4.3 查看sc生效结果
kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
dynamic-ceph-rdb ceph.com/rbd Delete Immediate false 5m8s
6.测试使用 storageclass
6.1 创建测试PVC
cat >ceph-rdb-pvc-test.yaml<<EOF
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: ceph-rdb-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: kube-ceph-rdb
resources:
requests:
storage: 2Gi
EOF
kubectl apply -f ceph-rdb-pvc-test.yaml
6.2 查看PVC&PV
kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
ceph-rdb-claim Bound pvc-9eee5a95-7842-4356-af3d-562255a0d7ee 2Gi RWO kube-ceph-rdb 33s
kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-9eee5a95-7842-4356-af3d-562255a0d7ee 2Gi RWO Delete Bound default/ceph-rdb-claim kube-ceph-rdb 38s
6.3 创建 nginx pod 挂载测试
cat >nginx-pod.yaml<<EOF
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod1
labels:
name: nginx-pod1
spec:
containers:
- name: nginx-pod1
image: nginx:alpine
ports:
- name: web
containerPort: 80
volumeMounts:
- name: ceph-rdb
mountPath: /usr/share/nginx/html
volumes:
- name: ceph-rdb
persistentVolumeClaim:
claimName: ceph-rdb-claim
EOF
kubectl apply -f nginx-pod.yaml
6.4 查看部署结果
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-pod1 1/1 Running 0 39s 10.20.235.135 k8s03 <none> <none>
6.5 访问测试
6.5.1 创建访问内容
kubectl exec -ti nginx-pod1 -- /bin/sh -c 'echo This is from Ceph RBD!!! > /usr/share/nginx/html/index.html'
6.5.2 curl访问测试
curl http://10.20.235.135
This is from Ceph RBD!!!
6.6 清理测试的PVC
kubectl delete -f nginx-pod.yaml
kubectl delete -f ceph-rdb-pvc-test.yaml
看完上述内容,你们对kubernetes中ceph RBD如何使用有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注天达云行业资讯频道,感谢大家的支持。