{"id":840,"date":"2025-12-22T08:41:59","date_gmt":"2025-12-22T00:41:59","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=840"},"modified":"2025-12-22T08:41:59","modified_gmt":"2025-12-22T00:41:59","slug":"kubernetes-ceph-rbd-%e5%9f%ba%e4%ba%8e-storageclass%e5%8a%a8%e6%80%81%e7%94%9f%e6%88%90pv-2","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/22\/kubernetes-ceph-rbd-%e5%9f%ba%e4%ba%8e-storageclass%e5%8a%a8%e6%80%81%e7%94%9f%e6%88%90pv-2\/","title":{"rendered":"Kubernetes ceph rbd \u57fa\u4e8e storageclass\u52a8\u6001\u751f\u6210pv"},"content":{"rendered":"\n<p>Kubernetes \u4e2d\u4f7f\u7528 Ceph RBD\uff08RADOS Block Device\uff09\u4f5c\u4e3a\u52a8\u6001\u5b58\u50a8\u540e\u7aef\uff0c\u901a\u8fc7 StorageClass \u5b9e\u73b0 PersistentVolumeClaim (PVC) \u7684\u52a8\u6001\u521b\u5efa PV\uff08PersistentVolume\uff09\uff0c\u8fd9\u662f\u6700\u5e38\u89c1\u7684\u751f\u4ea7\u7ea7\u5757\u5b58\u50a8\u65b9\u6848\u3002\u91cd\u8981\u63d0\u793a\uff082025 \u5e74\u73b0\u72b6\uff09\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Kubernetes in-tree\uff08\u5185\u7f6e\uff09RBD \u9a71\u52a8\uff08kubernetes.io\/rbd\uff09\u5df2\u5e9f\u5f03\uff0c\u4e0d\u518d\u7ef4\u62a4\u3002<\/li>\n\n\n\n<li>\u5b98\u65b9\u63a8\u8350\u4f7f\u7528 Ceph CSI \u9a71\u52a8\uff08rbd.csi.ceph.com\uff09\uff0c\u652f\u6301\u52a8\u6001 provisioning\u3001\u6269\u5c55\u3001\u5feb\u7167\u3001\u514b\u9686\u7b49\u9ad8\u7ea7\u529f\u80fd\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u4f7f\u7528 Rook-Ceph\uff0cCSI \u9a71\u52a8\u4f1a\u81ea\u52a8\u90e8\u7f72\u5e76\u96c6\u6210\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4e0b\u9762\u662f\u5b8c\u6574\u914d\u7f6e\u6b65\u9aa4\uff08\u4ee5 Ceph CSI \u9a71\u52a8\u4e3a\u4f8b\uff09\uff1a1. \u524d\u7f6e\u6761\u4ef6<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ceph \u96c6\u7fa4\u5df2\u8fd0\u884c\uff08\u81f3\u5c11 3 \u4e2a Monitor \u548c OSD\uff09\u3002<\/li>\n\n\n\n<li>Kubernetes \u96c6\u7fa4\u7248\u672c \u2265 1.21\uff08\u63a8\u8350 \u2265 1.25\uff09\u3002<\/li>\n\n\n\n<li>\u6240\u6709 Worker \u8282\u70b9\u5df2\u5b89\u88c5 Ceph \u5ba2\u6237\u7aef\uff08ceph-common \u5305\uff09\u3002<\/li>\n\n\n\n<li>\u521b\u5efa Ceph \u4e13\u7528 Pool \u5e76\u521d\u59cb\u5316\uff1abash<code>ceph osd pool create kubernetes 128 128 replicated rbd pool init kubernetes ceph osd pool application enable kubernetes rbd<\/code><\/li>\n<\/ul>\n\n\n\n<p>2. \u521b\u5efa Ceph \u7528\u6237\u6743\u9650\uff08\u63a8\u8350\u4f7f\u7528\u72ec\u7acb\u7528\u6237\uff09<\/p>\n\n\n\n<p>bash<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nceph auth get-or-create client.kubernetes mon &#039;profile rbd&#039; osd &#039;profile rbd pool=kubernetes&#039; mgr &#039;profile rbd pool=kubernetes&#039; -o \/etc\/ceph\/client.kubernetes.keyring\n<\/pre><\/div>\n\n\n<p>3. \u521b\u5efa Kubernetes Secret\uff08CSI \u8ba4\u8bc1\u7528\uff09<\/p>\n\n\n\n<p>yaml<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\napiVersion: v1\nkind: Secret\nmetadata:\n  name: csi-rbd-secret\n  namespace: default   # \u6216 kube-system\uff0c\u6839\u636e\u4f60\u7684 CSI \u90e8\u7f72\u547d\u540d\u7a7a\u95f4\nstringData:\n  userID: kubernetes\n  userKey: AQ...==   # \u4ece client.kubernetes.keyring \u4e2d\u63d0\u53d6 base64 \u7f16\u7801\u540e\u7684 key\ntype: kubernetes.io\/rbd\n<\/pre><\/div>\n\n\n<p>bash<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nkubectl apply -f csi-rbd-secret.yaml\n<\/pre><\/div>\n\n\n<p>4. \u521b\u5efa Ceph CSI ConfigMap\uff08\u8fde\u63a5 Ceph \u96c6\u7fa4\uff09<\/p>\n\n\n\n<p>yaml<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\napiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: ceph-csi-config\n  namespace: default\ndata:\n  config.json: |-\n    &#x5B;\n      {\n        &quot;clusterID&quot;: &quot;your-ceph-cluster-fsid&quot;,   # ceph fsid\n        &quot;monitors&quot;: &#x5B;\n          &quot;mon1:6789&quot;,\n          &quot;mon2:6789&quot;,\n          &quot;mon3:6789&quot;\n        ]\n      }\n    ]\n<\/pre><\/div>\n\n\n<p>bash<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nkubectl apply -f ceph-csi-config.yaml\n<\/pre><\/div>\n\n\n<p>5. \u521b\u5efa StorageClass\uff08\u52a8\u6001\u751f\u6210 PV \u7684\u6838\u5fc3\uff09<\/p>\n\n\n\n<p>yaml<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\napiVersion: storage.k8s.io\/v1\nkind: StorageClass\nmetadata:\n  name: ceph-rbd\n  annotations:\n    storageclass.kubernetes.io\/is-default-class: &quot;true&quot;   # \u53ef\u9009\uff1a\u8bbe\u4e3a\u9ed8\u8ba4 SC\nprovisioner: rbd.csi.ceph.com\nparameters:\n  clusterID: your-ceph-cluster-fsid                 # \u4e0e ConfigMap \u4e2d\u7684\u4e00\u81f4\n  pool: kubernetes                                  # \u4f60\u7684 Ceph Pool \u540d\u79f0\n  imageFeatures: layering                           # \u5fc5\u987b\u5305\u542b layering \u652f\u6301\u514b\u9686\n  csi.storage.k8s.io\/provisioner-secret-name: csi-rbd-secret\n  csi.storage.k8s.io\/provisioner-secret-namespace: default\n  csi.storage.k8s.io\/node-stage-secret-name: csi-rbd-secret\n  csi.storage.k8s.io\/node-stage-secret-namespace: default\n  csi.storage.k8s.io\/fstype: ext4                   # \u6216 xfs\nreclaimPolicy: Delete                               # \u6216 Retain\nallowVolumeExpansion: true                          # \u542f\u7528\u5728\u7ebf\u6269\u5c55 PVC\nmountOptions:\n  - discard                                         # \u53ef\u9009\uff1aTRIM \u652f\u6301\nvolumeBindingMode: Immediate                        # \u6216 WaitForFirstConsumer\uff08\u62d3\u6251\u611f\u77e5\uff09\n<\/pre><\/div>\n\n\n<p>bash<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nkubectl apply -f ceph-rbd-sc.yaml\n<\/pre><\/div>\n\n\n<p>6. \u521b\u5efa PVC\uff08\u81ea\u52a8\u89e6\u53d1\u52a8\u6001 PV \u521b\u5efa\uff09<\/p>\n\n\n\n<p>yaml<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\napiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n  name: ceph-rbd-pvc\nspec:\n  accessModes:\n    - ReadWriteOnce   # RBD \u53ea\u652f\u6301 RWO\n  resources:\n    requests:\n      storage: 10Gi\n  storageClassName: ceph-rbd\n<\/pre><\/div>\n\n\n<p>bash<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nkubectl apply -f ceph-rbd-pvc.yaml\n<\/pre><\/div>\n\n\n<p>7. \u4f7f\u7528 PVC \u521b\u5efa Pod<\/p>\n\n\n\n<p>yaml<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\napiVersion: v1\nkind: Pod\nmetadata:\n  name: ceph-rbd-pod\nspec:\n  containers:\n  - name: test-container\n    image: busybox\n    command: &#x5B;&quot;\/bin\/sh&quot;, &quot;-c&quot;, &quot;sleep 3600&quot;]\n    volumeMounts:\n    - mountPath: \/data\n      name: rbd-volume\n  volumes:\n  - name: rbd-volume\n    persistentVolumeClaim:\n      claimName: ceph-rbd-pvc\n<\/pre><\/div>\n\n\n<p>bash<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nkubectl apply -f ceph-rbd-pod.yaml\n<\/pre><\/div>\n\n\n<p>8. \u9a8c\u8bc1<\/p>\n\n\n\n<p>bash<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nkubectl get pv,pvc,sc\nkubectl get pod ceph-rbd-pod\nkubectl exec -it ceph-rbd-pod -- df -h \/data\n<\/pre><\/div>\n\n\n<p>\u5e38\u89c1\u95ee\u9898\u6392\u67e5<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>\u95ee\u9898<\/th><th>\u53ef\u80fd\u539f\u56e0<\/th><th>\u89e3\u51b3\u65b9\u6cd5<\/th><\/tr><tr><td>PVC \u5361\u5728 Pending<\/td><td>Provisioner \u672a\u5c31\u7eea\u3001Secret \u9519\u8bef\u3001Pool \u4e0d\u5b58\u5728<\/td><td>\u68c0\u67e5 kubectl get pod -n &lt;csi-ns&gt; \u65e5\u5fd7<\/td><\/tr><tr><td>\u6269\u5c55\u5931\u8d25<\/td><td>\u672a\u8bbe\u7f6e allowVolumeExpansion: true<\/td><td>\u4fee\u6539 SC \u5e76\u91cd\u542f CSI Pod<\/td><\/tr><tr><td>\u8282\u70b9\u65e0\u6cd5 mount<\/td><td>\u7f3a\u5c11 ceph-common \u6216\u5185\u6838\u6a21\u5757<\/td><td>\u786e\u4fdd\u8282\u70b9\u5b89\u88c5 ceph-common \u548c rbd \u6a21\u5757<\/td><\/tr><tr><td>\u6743\u9650\u95ee\u9898<\/td><td>userKey \u9519\u8bef\u6216\u6743\u9650\u4e0d\u8db3<\/td><td>\u68c0\u67e5 Ceph \u7528\u6237\u6743\u9650\uff08ceph auth get client.kubernetes\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u63a8\u8350\uff1a\u4f7f\u7528 Rook-Ceph \u7b80\u5316\u90e8\u7f72\u5982\u679c\u4f60\u7684 Ceph \u662f\u7528 Rook \u90e8\u7f72\u7684\uff0c\u53ea\u9700\u521b\u5efa CephBlockPool CRD\uff0cRook \u4f1a\u81ea\u52a8\u521b\u5efa StorageClass\uff1a &#8220;`yaml apiVersion: ceph.rook.io\/v1 kind: CephBlockPool metadata: name: kubernetes-pool namespace: rook-ceph spec: failureDomain: host replicated: size: 3Rook \u4f1a\u81ea\u52a8\u751f\u6210 StorageClass: rook-ceph-block<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\n\u7136\u540e\u76f4\u63a5\u5728 PVC \u4e2d\u5f15\u7528 `storageClassName: rook-ceph-block` \u5373\u53ef\u3002\n\n\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86\u57fa\u4e8e StorageClass \u7684 Ceph RBD \u52a8\u6001 PV \u751f\u6210\uff01\u5982\u679c\u6709\u5177\u4f53\u7684 Ceph \u7248\u672c\u3001Rook \u7248\u672c\u6216\u62a5\u9519\u4fe1\u606f\uff0c\u8d34\u51fa\u6765\u6211\u53ef\u4ee5\u5e2e\u4f60\u8fdb\u4e00\u6b65\u8c03\u8bd5\u3002\n<\/pre><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kubernetes \u4e2d\u4f7f\u7528 Ceph RBD\uff08RADOS Block Devi&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/22\/kubernetes-ceph-rbd-%e5%9f%ba%e4%ba%8e-storageclass%e5%8a%a8%e6%80%81%e7%94%9f%e6%88%90pv-2\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-840","post","type-post","status-publish","format-standard","hentry","category-12"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=840"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/840\/revisions"}],"predecessor-version":[{"id":841,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/840\/revisions\/841"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}