k8s-v1.25.0持久化存储ceph-csi方式(ceph-v17.2.3、rbd块存储)

ceph-v17.2.3对接k8s-v1.25.0(动态存储)

1、cephadm部署ceph-v17.2.3集群

2、k8s-v1.25.0部署ceph-csi-v3.7.0

ceph集群+k8s集群(ubuntu22.04)

ceph-v17.2.3

k8s-v1.25.0(containerd-1.6.8)

ceph-csi-v3.7.0

动态pvc

ceph集群操作

  1. ceph osd pool create kubernetes 8 8
  2. ceph osd pool application enable kubernetes rbd
  3. rbd pool init -p kubernetes
  4. ceph osd pool ls
  1. ceph mon dump
  1. ceph auth get client.admin 2>&1 |grep "key = " |awk '{print $3'}
  1. ceph auth add client.kube mon 'allow r' osd 'allow rwx pool=kubernetes'
  2. ceph auth get-key client.kube

k8s集群操作

  1. apt update
  2. apt install ceph-common=17.2.0-0ubuntu0.22.04.1 -y
  1. mkdir ~/{ceph-csi,000}
  2. git clone https://github.com/ceph/ceph-csi.git
  3. cd ~/000 && git clone https://hub.fastgit.xyz/ceph/ceph-csi.git
  1. kubectl create ns ceph-csi
  2. kubectl describe node master |grep Taint
  3. kubectl taint node master node-role.kubernetes.io/master-

1、csi-config-map.yaml

  1. # 1、csi-config-map.yaml
  2. cat > ~/ceph-csi/csi-config-map.yaml << 'EOF'
  3. ---
  4. apiVersion: v1
  5. kind: ConfigMap
  6. data:
  7. config.json: |-
  8. [
  9. {
  10. "clusterID": "4c4d9c82-267d-11ed-888e-000c29db6f93",
  11. "monitors": [
  12. "192.168.1.204:6789",
  13. "192.168.1.205:6789",
  14. "192.168.1.206:6789",
  15. "192.168.1.207:6789"
  16. ]
  17. }
  18. ]
  19. metadata:
  20. name: ceph-csi-config
  21. namespace: ceph-csi
  22. EOF

clusterID使用ceph mon dump命令在ceph集群上查看

2、csi-nodeplugin-rbac.yaml

3、csi-provisioner-rbac.yaml

4、csidriver.yaml

5、csi-rbdplugin-provisioner.yaml

6、csi-rbdplugin.yaml

  1. cat > ceph.yml < 'eof'
  2. # 2、csi-nodeplugin-rbac.yaml
  3. cat > ~/ceph-csi/csi-nodeplugin-rbac.yaml << 'EOF'
  4. ---
  5. apiVersion: v1
  6. kind: ServiceAccount
  7. metadata:
  8. name: rbd-csi-nodeplugin
  9. namespace: ceph-csi
  10. ---
  11. kind: ClusterRole
  12. apiVersion: rbac.authorization.k8s.io/v1
  13. metadata:
  14. name: rbd-csi-nodeplugin
  15. rules:
  16. - apiGroups: [""]
  17. resources: ["nodes"]
  18. verbs: ["get"]
  19. - apiGroups: [""]
  20. resources: ["secrets"]
  21. verbs: ["get"]
  22. - apiGroups: [""]
  23. resources: ["configmaps"]
  24. verbs: ["get"]
  25. - apiGroups: [""]
  26. resources: ["serviceaccounts"]
  27. verbs: ["get"]
  28. - apiGroups: [""]
  29. resources: ["persistentvolumes"]
  30. verbs: ["get"]
  31. - apiGroups: ["storage.k8s.io"]
  32. resources: ["volumeattachments"]
  33. verbs: ["list", "get"]
  34. - apiGroups: [""]
  35. resources: ["serviceaccounts/token"]
  36. verbs: ["create"]
  37. ---
  38. kind: ClusterRoleBinding
  39. apiVersion: rbac.authorization.k8s.io/v1
  40. metadata:
  41. name: rbd-csi-nodeplugin
  42. subjects:
  43. - kind: ServiceAccount
  44. name: rbd-csi-nodeplugin
  45. namespace: ceph-csi
  46. roleRef:
  47. kind: ClusterRole
  48. name: rbd-csi-nodeplugin
  49. apiGroup: rbac.authorization.k8s.io
  50. EOF
  51. # 3、csi-provisioner-rbac.yaml
  52. cat > ~/ceph-csi/csi-provisioner-rbac.yaml << 'EOF'
  53. ---
  54. apiVersion: v1
  55. kind: ServiceAccount
  56. metadata:
  57. name: rbd-csi-provisioner
  58. namespace: ceph-csi
  59. ---
  60. kind: ClusterRole
  61. apiVersion: rbac.authorization.k8s.io/v1
  62. metadata:
  63. name: rbd-external-provisioner-runner
  64. rules:
  65. - apiGroups: [""]
  66. resources: ["nodes"]
  67. verbs: ["get", "list", "watch"]
  68. - apiGroups: [""]
  69. resources: ["secrets"]
  70. verbs: ["get", "list", "watch"]
  71. - apiGroups: [""]
  72. resources: ["events"]
  73. verbs: ["list", "watch", "create", "update", "patch"]
  74. - apiGroups: [""]
  75. resources: ["persistentvolumes"]
  76. verbs: ["get", "list", "watch", "create", "update", "delete", "patch"]
  77. - apiGroups: [""]
  78. resources: ["persistentvolumeclaims"]
  79. verbs: ["get", "list", "watch", "update"]
  80. - apiGroups: [""]
  81. resources: ["persistentvolumeclaims/status"]
  82. verbs: ["update", "patch"]
  83. - apiGroups: ["storage.k8s.io"]
  84. resources: ["storageclasses"]
  85. verbs: ["get", "list", "watch"]
  86. - apiGroups: ["snapshot.storage.k8s.io"]
  87. resources: ["volumesnapshots"]
  88. verbs: ["get", "list", "patch"]
  89. - apiGroups: ["snapshot.storage.k8s.io"]
  90. resources: ["volumesnapshots/status"]
  91. verbs: ["get", "list", "patch"]
  92. - apiGroups: ["snapshot.storage.k8s.io"]
  93. resources: ["volumesnapshotcontents"]
  94. verbs: ["create", "get", "list", "watch", "update", "delete", "patch"]
  95. - apiGroups: ["snapshot.storage.k8s.io"]
  96. resources: ["volumesnapshotclasses"]
  97. verbs: ["get", "list", "watch"]
  98. - apiGroups: ["storage.k8s.io"]
  99. resources: ["volumeattachments"]
  100. verbs: ["get", "list", "watch", "update", "patch"]
  101. - apiGroups: ["storage.k8s.io"]
  102. resources: ["volumeattachments/status"]
  103. verbs: ["patch"]
  104. - apiGroups: ["storage.k8s.io"]
  105. resources: ["csinodes"]
  106. verbs: ["get", "list", "watch"]
  107. - apiGroups: ["snapshot.storage.k8s.io"]
  108. resources: ["volumesnapshotcontents/status"]
  109. verbs: ["update", "patch"]
  110. - apiGroups: [""]
  111. resources: ["configmaps"]
  112. verbs: ["get"]
  113. - apiGroups: [""]
  114. resources: ["serviceaccounts"]
  115. verbs: ["get"]
  116. - apiGroups: [""]
  117. resources: ["serviceaccounts/token"]
  118. verbs: ["create"]
  119. ---
  120. kind: ClusterRoleBinding
  121. apiVersion: rbac.authorization.k8s.io/v1
  122. metadata:
  123. name: rbd-csi-provisioner-role
  124. subjects:
  125. - kind: ServiceAccount
  126. name: rbd-csi-provisioner
  127. namespace: ceph-csi
  128. roleRef:
  129. kind: ClusterRole
  130. name: rbd-external-provisioner-runner
  131. apiGroup: rbac.authorization.k8s.io
  132. ---
  133. kind: Role
  134. apiVersion: rbac.authorization.k8s.io/v1
  135. metadata:
  136. namespace: ceph-csi
  137. name: rbd-external-provisioner-cfg
  138. rules:
  139. - apiGroups: [""]
  140. resources: ["configmaps"]
  141. verbs: ["get", "list", "watch", "create", "update", "delete"]
  142. - apiGroups: ["coordination.k8s.io"]
  143. resources: ["leases"]
  144. verbs: ["get", "watch", "list", "delete", "update", "create"]
  145. ---
  146. kind: RoleBinding
  147. apiVersion: rbac.authorization.k8s.io/v1
  148. metadata:
  149. name: rbd-csi-provisioner-role-cfg
  150. namespace: ceph-csi
  151. subjects:
  152. - kind: ServiceAccount
  153. name: rbd-csi-provisioner
  154. namespace: ceph-csi
  155. roleRef:
  156. kind: Role
  157. name: rbd-external-provisioner-cfg
  158. apiGroup: rbac.authorization.k8s.io
  159. EOF
  160. # 4、csidriver.yaml
  161. cat > ~/ceph-csi/csidriver.yaml << 'EOF'
  162. apiVersion: storage.k8s.io/v1
  163. kind: CSIDriver
  164. metadata:
  165. name: "rbd.csi.ceph.com"
  166. namespace: ceph-csi
  167. spec:
  168. attachRequired: true
  169. podInfoOnMount: false
  170. EOF
  171. # 5、csi-rbdplugin-provisioner.yaml
  172. cat > ~/ceph-csi/csi-rbdplugin-provisioner.yaml << 'EOF'
  173. ---
  174. kind: Service
  175. apiVersion: v1
  176. metadata:
  177. name: csi-rbdplugin-provisioner
  178. namespace: ceph-csi
  179. labels:
  180. app: csi-metrics
  181. spec:
  182. selector:
  183. app: csi-rbdplugin-provisioner
  184. ports:
  185. - name: http-metrics
  186. port: 8080
  187. protocol: TCP
  188. targetPort: 8680
  189. ---
  190. kind: Deployment
  191. apiVersion: apps/v1
  192. metadata:
  193. name: csi-rbdplugin-provisioner
  194. namespace: ceph-csi
  195. spec:
  196. replicas: 3
  197. selector:
  198. matchLabels:
  199. app: csi-rbdplugin-provisioner
  200. template:
  201. metadata:
  202. labels:
  203. app: csi-rbdplugin-provisioner
  204. spec:
  205. affinity:
  206. podAntiAffinity:
  207. requiredDuringSchedulingIgnoredDuringExecution:
  208. - labelSelector:
  209. matchExpressions:
  210. - key: app
  211. operator: In
  212. values:
  213. - csi-rbdplugin-provisioner
  214. topologyKey: "kubernetes.io/hostname"
  215. serviceAccountName: rbd-csi-provisioner
  216. priorityClassName: system-cluster-critical
  217. containers:
  218. - name: csi-provisioner
  219. image: dyrnq/csi-provisioner:v3.2.1
  220. args:
  221. - "--csi-address=$(ADDRESS)"
  222. - "--v=1"
  223. - "--timeout=150s"
  224. - "--retry-interval-start=500ms"
  225. - "--leader-election=true"
  226. - "--feature-gates=Topology=false"
  227. - "--feature-gates=HonorPVReclaimPolicy=true"
  228. - "--prevent-volume-mode-conversion=true"
  229. - "--default-fstype=ext4"
  230. - "--extra-create-metadata=true"
  231. env:
  232. - name: ADDRESS
  233. value: unix:///csi/csi-provisioner.sock
  234. imagePullPolicy: "IfNotPresent"
  235. volumeMounts:
  236. - name: socket-dir
  237. mountPath: /csi
  238. - name: csi-snapshotter
  239. image: dyrnq/csi-snapshotter:v6.0.1
  240. args:
  241. - "--csi-address=$(ADDRESS)"
  242. - "--v=1"
  243. - "--timeout=150s"
  244. - "--leader-election=true"
  245. - "--extra-create-metadata=true"
  246. env:
  247. - name: ADDRESS
  248. value: unix:///csi/csi-provisioner.sock
  249. imagePullPolicy: "IfNotPresent"
  250. volumeMounts:
  251. - name: socket-dir
  252. mountPath: /csi
  253. - name: csi-attacher
  254. image: dyrnq/csi-attacher:v3.5.0
  255. args:
  256. - "--v=1"
  257. - "--csi-address=$(ADDRESS)"
  258. - "--leader-election=true"
  259. - "--retry-interval-start=500ms"
  260. env:
  261. - name: ADDRESS
  262. value: /csi/csi-provisioner.sock
  263. imagePullPolicy: "IfNotPresent"
  264. volumeMounts:
  265. - name: socket-dir
  266. mountPath: /csi
  267. - name: csi-resizer
  268. image: dyrnq/csi-resizer:v1.5.0
  269. args:
  270. - "--csi-address=$(ADDRESS)"
  271. - "--v=1"
  272. - "--timeout=150s"
  273. - "--leader-election"
  274. - "--retry-interval-start=500ms"
  275. - "--handle-volume-inuse-error=false"
  276. - "--feature-gates=RecoverVolumeExpansionFailure=true"
  277. env:
  278. - name: ADDRESS
  279. value: unix:///csi/csi-provisioner.sock
  280. imagePullPolicy: "IfNotPresent"
  281. volumeMounts:
  282. - name: socket-dir
  283. mountPath: /csi
  284. - name: csi-rbdplugin
  285. image: quay.io/cephcsi/cephcsi:canary
  286. args:
  287. - "--nodeid=$(NODE_ID)"
  288. - "--type=rbd"
  289. - "--controllerserver=true"
  290. - "--endpoint=$(CSI_ENDPOINT)"
  291. - "--csi-addons-endpoint=$(CSI_ADDONS_ENDPOINT)"
  292. - "--v=5"
  293. - "--drivername=rbd.csi.ceph.com"
  294. - "--pidlimit=-1"
  295. - "--rbdhardmaxclonedepth=8"
  296. - "--rbdsoftmaxclonedepth=4"
  297. - "--enableprofiling=false"
  298. - "--setmetadata=true"
  299. env:
  300. - name: POD_IP
  301. valueFrom:
  302. fieldRef:
  303. fieldPath: status.podIP
  304. - name: NODE_ID
  305. valueFrom:
  306. fieldRef:
  307. fieldPath: spec.nodeName
  308. - name: POD_NAMESPACE
  309. valueFrom:
  310. fieldRef:
  311. fieldPath: metadata.namespace
  312. - name: CSI_ENDPOINT
  313. value: unix:///csi/csi-provisioner.sock
  314. - name: CSI_ADDONS_ENDPOINT
  315. value: unix:///csi/csi-addons.sock
  316. imagePullPolicy: "IfNotPresent"
  317. volumeMounts:
  318. - name: socket-dir
  319. mountPath: /csi
  320. - mountPath: /dev
  321. name: host-dev
  322. - mountPath: /sys
  323. name: host-sys
  324. - mountPath: /lib/modules
  325. name: lib-modules
  326. readOnly: true
  327. - name: ceph-csi-config
  328. mountPath: /etc/ceph-csi-config/
  329. - name: keys-tmp-dir
  330. mountPath: /tmp/csi/keys
  331. - name: oidc-token
  332. mountPath: /run/secrets/tokens
  333. readOnly: true
  334. - name: csi-rbdplugin-controller
  335. image: quay.io/cephcsi/cephcsi:canary
  336. args:
  337. - "--type=controller"
  338. - "--v=5"
  339. - "--drivername=rbd.csi.ceph.com"
  340. - "--drivernamespace=$(DRIVER_NAMESPACE)"
  341. - "--setmetadata=true"
  342. env:
  343. - name: DRIVER_NAMESPACE
  344. valueFrom:
  345. fieldRef:
  346. fieldPath: metadata.namespace
  347. imagePullPolicy: "IfNotPresent"
  348. volumeMounts:
  349. - name: ceph-csi-config
  350. mountPath: /etc/ceph-csi-config/
  351. - name: keys-tmp-dir
  352. mountPath: /tmp/csi/keys
  353. - name: liveness-prometheus
  354. image: quay.io/cephcsi/cephcsi:canary
  355. args:
  356. - "--type=liveness"
  357. - "--endpoint=$(CSI_ENDPOINT)"
  358. - "--metricsport=8680"
  359. - "--metricspath=/metrics"
  360. - "--polltime=60s"
  361. - "--timeout=3s"
  362. env:
  363. - name: CSI_ENDPOINT
  364. value: unix:///csi/csi-provisioner.sock
  365. - name: POD_IP
  366. valueFrom:
  367. fieldRef:
  368. fieldPath: status.podIP
  369. volumeMounts:
  370. - name: socket-dir
  371. mountPath: /csi
  372. imagePullPolicy: "IfNotPresent"
  373. volumes:
  374. - name: host-dev
  375. hostPath:
  376. path: /dev
  377. - name: host-sys
  378. hostPath:
  379. path: /sys
  380. - name: lib-modules
  381. hostPath:
  382. path: /lib/modules
  383. - name: socket-dir
  384. emptyDir: {
  385. medium: "Memory"
  386. }
  387. - name: ceph-csi-config
  388. configMap:
  389. name: ceph-csi-config
  390. - name: keys-tmp-dir
  391. emptyDir: {
  392. medium: "Memory"
  393. }
  394. - name: oidc-token
  395. projected:
  396. sources:
  397. - serviceAccountToken:
  398. path: oidc-token
  399. expirationSeconds: 3600
  400. audience: ceph-csi-kms
  401. EOF
  402. # 6、csi-rbdplugin.yaml
  403. cat > ~/ceph-csi/csi-rbdplugin.yaml << 'EOF'
  404. ---
  405. kind: DaemonSet
  406. apiVersion: apps/v1
  407. metadata:
  408. name: csi-rbdplugin
  409. namespace: ceph-csi
  410. spec:
  411. selector:
  412. matchLabels:
  413. app: csi-rbdplugin
  414. template:
  415. metadata:
  416. labels:
  417. app: csi-rbdplugin
  418. spec:
  419. serviceAccountName: rbd-csi-nodeplugin
  420. hostNetwork: true
  421. hostPID: true
  422. priorityClassName: system-node-critical
  423. dnsPolicy: ClusterFirstWithHostNet
  424. containers:
  425. - name: driver-registrar
  426. securityContext:
  427. privileged: true
  428. allowPrivilegeEscalation: true
  429. image: dyrnq/csi-node-driver-registrar:v2.5.1
  430. args:
  431. - "--v=1"
  432. - "--csi-address=/csi/csi.sock"
  433. - "--kubelet-registration-path=/var/lib/kubelet/plugins/rbd.csi.ceph.com/csi.sock"
  434. env:
  435. - name: KUBE_NODE_NAME
  436. valueFrom:
  437. fieldRef:
  438. fieldPath: spec.nodeName
  439. volumeMounts:
  440. - name: socket-dir
  441. mountPath: /csi
  442. - name: registration-dir
  443. mountPath: /registration
  444. - name: csi-rbdplugin
  445. securityContext:
  446. privileged: true
  447. capabilities:
  448. add: ["SYS_ADMIN"]
  449. allowPrivilegeEscalation: true
  450. image: quay.io/cephcsi/cephcsi:canary
  451. args:
  452. - "--nodeid=$(NODE_ID)"
  453. - "--pluginpath=/var/lib/kubelet/plugins"
  454. - "--stagingpath=/var/lib/kubelet/plugins/kubernetes.io/csi/"
  455. - "--type=rbd"
  456. - "--nodeserver=true"
  457. - "--endpoint=$(CSI_ENDPOINT)"
  458. - "--csi-addons-endpoint=$(CSI_ADDONS_ENDPOINT)"
  459. - "--v=5"
  460. - "--drivername=rbd.csi.ceph.com"
  461. - "--enableprofiling=false"
  462. env:
  463. - name: POD_IP
  464. valueFrom:
  465. fieldRef:
  466. fieldPath: status.podIP
  467. - name: NODE_ID
  468. valueFrom:
  469. fieldRef:
  470. fieldPath: spec.nodeName
  471. - name: POD_NAMESPACE
  472. valueFrom:
  473. fieldRef:
  474. fieldPath: metadata.namespace
  475. - name: CSI_ENDPOINT
  476. value: unix:///csi/csi.sock
  477. - name: CSI_ADDONS_ENDPOINT
  478. value: unix:///csi/csi-addons.sock
  479. imagePullPolicy: "IfNotPresent"
  480. volumeMounts:
  481. - name: socket-dir
  482. mountPath: /csi
  483. - mountPath: /dev
  484. name: host-dev
  485. - mountPath: /sys
  486. name: host-sys
  487. - mountPath: /run/mount
  488. name: host-mount
  489. - mountPath: /etc/selinux
  490. name: etc-selinux
  491. readOnly: true
  492. - mountPath: /lib/modules
  493. name: lib-modules
  494. readOnly: true
  495. - name: ceph-csi-config
  496. mountPath: /etc/ceph-csi-config/
  497. - name: plugin-dir
  498. mountPath: /var/lib/kubelet/plugins
  499. mountPropagation: "Bidirectional"
  500. - name: mountpoint-dir
  501. mountPath: /var/lib/kubelet/pods
  502. mountPropagation: "Bidirectional"
  503. - name: keys-tmp-dir
  504. mountPath: /tmp/csi/keys
  505. - name: ceph-logdir
  506. mountPath: /var/log/ceph
  507. - name: oidc-token
  508. mountPath: /run/secrets/tokens
  509. readOnly: true
  510. - name: liveness-prometheus
  511. securityContext:
  512. privileged: true
  513. allowPrivilegeEscalation: true
  514. image: quay.io/cephcsi/cephcsi:canary
  515. args:
  516. - "--type=liveness"
  517. - "--endpoint=$(CSI_ENDPOINT)"
  518. - "--metricsport=8680"
  519. - "--metricspath=/metrics"
  520. - "--polltime=60s"
  521. - "--timeout=3s"
  522. env:
  523. - name: CSI_ENDPOINT
  524. value: unix:///csi/csi.sock
  525. - name: POD_IP
  526. valueFrom:
  527. fieldRef:
  528. fieldPath: status.podIP
  529. volumeMounts:
  530. - name: socket-dir
  531. mountPath: /csi
  532. imagePullPolicy: "IfNotPresent"
  533. volumes:
  534. - name: socket-dir
  535. hostPath:
  536. path: /var/lib/kubelet/plugins/rbd.csi.ceph.com
  537. type: DirectoryOrCreate
  538. - name: plugin-dir
  539. hostPath:
  540. path: /var/lib/kubelet/plugins
  541. type: Directory
  542. - name: mountpoint-dir
  543. hostPath:
  544. path: /var/lib/kubelet/pods
  545. type: DirectoryOrCreate
  546. - name: ceph-logdir
  547. hostPath:
  548. path: /var/log/ceph
  549. type: DirectoryOrCreate
  550. - name: registration-dir
  551. hostPath:
  552. path: /var/lib/kubelet/plugins_registry/
  553. type: Directory
  554. - name: host-dev
  555. hostPath:
  556. path: /dev
  557. - name: host-sys
  558. hostPath:
  559. path: /sys
  560. - name: etc-selinux
  561. hostPath:
  562. path: /etc/selinux
  563. - name: host-mount
  564. hostPath:
  565. path: /run/mount
  566. - name: lib-modules
  567. hostPath:
  568. path: /lib/modules
  569. - name: ceph-csi-config
  570. configMap:
  571. name: ceph-csi-config
  572. - name: keys-tmp-dir
  573. emptyDir: {
  574. medium: "Memory"
  575. }
  576. - name: oidc-token
  577. projected:
  578. sources:
  579. - serviceAccountToken:
  580. path: oidc-token
  581. expirationSeconds: 3600
  582. audience: ceph-csi-kms
  583. ---
  584. apiVersion: v1
  585. kind: Service
  586. metadata:
  587. name: csi-metrics-rbdplugin
  588. namespace: ceph-csi
  589. labels:
  590. app: csi-metrics
  591. spec:
  592. ports:
  593. - name: http-metrics
  594. port: 8080
  595. protocol: TCP
  596. targetPort: 8680
  597. selector:
  598. app: csi-rbdplugin
  599. EOF
  600. eof

7、secret.yaml

  1. # 7、secret.yaml
  2. cat > ~/ceph-csi/secret.yaml << 'EOF'
  3. ---
  4. apiVersion: v1
  5. kind: Secret
  6. metadata:
  7. name: csi-rbd-secret
  8. namespace: ceph-csi
  9. stringData:
  10. userID: kube
  11. userKey: AQD/4gpjDnt0KhAANfaKRnFlXIXVqPdf1IHOUA==
  12. EOF

userID就是ceph auth add client.kube mon ‘allow r’ osd ‘allow rwx pool=kubernetes’创建的kube

userKey使用ceph auth get-key client.kube命令在ceph集群上查看

8、storageclass.yaml

  1. # 8、storageclass.yaml
  2. cat > ~/ceph-csi/storageclass.yaml << 'EOF'
  3. ---
  4. apiVersion: storage.k8s.io/v1
  5. kind: StorageClass
  6. metadata:
  7. name: csi-rbd-sc
  8. provisioner: rbd.csi.ceph.com
  9. parameters:
  10. clusterID: 4c4d9c82-267d-11ed-888e-000c29db6f93
  11. pool: kubernetes
  12. imageFeatures: layering
  13. csi.storage.k8s.io/provisioner-secret-name: csi-rbd-secret
  14. csi.storage.k8s.io/provisioner-secret-namespace: ceph-csi
  15. csi.storage.k8s.io/controller-expand-secret-name: csi-rbd-secret
  16. csi.storage.k8s.io/controller-expand-secret-namespace: ceph-csi
  17. csi.storage.k8s.io/node-stage-secret-name: csi-rbd-secret
  18. csi.storage.k8s.io/node-stage-secret-namespace: ceph-csi
  19. csi.storage.k8s.io/fstype: ext4
  20. reclaimPolicy: Delete
  21. allowVolumeExpansion: true
  22. mountOptions:
  23. - discard
  24. EOF

clusterID在ceph集群上用ceph mon dump命令查看

pool使用ceph osd pool create kubernetes 8 8命令在ceph集群上创建的kubernetes

下载镜像

  1. # 1、master上操作
  2. # 查看镜像
  3. find ./ -type f |xargs grep 'image: '|sort|uniq|awk '{print $3}'|grep ^[a-zA-Z]|grep -Evw 'error|kubeRbacProxy'|sort -rn|uniq |grep -n ".*"
  4. 1:quay.io/cephcsi/cephcsi:canary
  5. 2:dyrnq/csi-snapshotter:v6.0.1
  6. 3:dyrnq/csi-resizer:v1.5.0
  7. 4:dyrnq/csi-provisioner:v3.2.1
  8. 5:dyrnq/csi-node-driver-registrar:v2.5.1
  9. 6:dyrnq/csi-attacher:v3.5.0
  10. #在线预拉取镜像
  11. find ./ -type f |xargs grep 'image: '|sort|uniq|awk '{print $3}'|grep ^[a-zA-Z]|grep -Evw 'error|kubeRbacProxy'|sort -rn|uniq |xargs -i docker pull {}
  12. find ./ -type f |xargs grep 'image: '|sort|uniq|awk '{print $3}'|grep ^[a-zA-Z]|grep -Evw 'error|kubeRbacProxy'|sort -rn|uniq |xargs -i ctr -n k8s.io i pull {}
  13. #2、node上操作
  14. cat > pull.sh << 'EOF'
  15. quay.io/cephcsi/cephcsi:canary
  16. dyrnq/csi-snapshotter:v6.0.1
  17. dyrnq/csi-resizer:v1.5.0
  18. dyrnq/csi-provisioner:v3.2.1
  19. dyrnq/csi-node-driver-registrar:v2.5.1
  20. dyrnq/csi-attacher:v3.5.0
  21. EOF
  22. cat pull.sh |xargs -i docker pull {}
  23. cat pull.sh |xargs -i crictl pull {}
  1. kubectl apply \
  2. -f csi-config-map.yaml \
  3. -f csi-nodeplugin-rbac.yaml \
  4. -f csi-provisioner-rbac.yaml \
  5. -f csidriver.yaml
  6. kubectl apply \
  7. -f csi-rbdplugin-provisioner.yaml \
  8. -f csi-rbdplugin.yaml
  9. kubectl apply \
  10. -f secret.yaml \
  11. -f storageclass.yaml
  1. kubectl delete \
  2. -f storageclass.yaml \
  3. -f secret.yaml
  4. kubectl delete \
  5. -f csi-rbdplugin.yaml \
  6. -f csi-rbdplugin-provisioner.yaml
  7. kubectl delete \
  8. -f csidriver.yaml \
  9. -f csi-provisioner-rbac.yaml \
  10. -f csi-nodeplugin-rbac.yaml \
  11. -f csi-config-map.yaml

测试动态pvc

9、pvc.yaml

  1. cat > ~/000/pvc.yaml << 'EOF'
  2. ---
  3. apiVersion: v1
  4. kind: PersistentVolumeClaim
  5. metadata:
  6. name: rbd-pvc
  7. spec:
  8. accessModes:
  9. - ReadWriteOnce
  10. resources:
  11. requests:
  12. storage: 1Gi
  13. storageClassName: csi-rbd-sc
  14. EOF

10、pod.yaml

  1. cat > ~/000/pod.yaml << 'EOF'
  2. ---
  3. apiVersion: v1
  4. kind: Pod
  5. metadata:
  6. name: csi-rbd-demo-pod
  7. spec:
  8. containers:
  9. - name: web-server
  10. image: nginx:alpine
  11. imagePullPolicy: IfNotPresent
  12. volumeMounts:
  13. - name: mypvc
  14. mountPath: /var/lib/www/html
  15. volumes:
  16. - name: mypvc
  17. persistentVolumeClaim:
  18. claimName: rbd-pvc
  19. readOnly: false
  20. EOF