行业知识
k8s & ceph(静态pvc)
2026-11-12 11:25:52
来源:互联网转载
1.在 Kubernetes 节点上安装
ceph-common 包。这个包包含了连接到 Ceph 集群所需的工具和库。可以使用以下命令在每个节点上安装:
sudo apt-get install ceph-common
2.在 Kubernetes 中创建一个 Secret 对象,用于存储连接到 Ceph 集群所需的密钥和配置信息。可以通过编辑以下示例,并将其保存为
ceph-secret.yaml 文件来创建 Secret:
apiVersion: v1kind: Secretmetadata: name: ceph-secret namespace: your-namespacetype: Opaquedata: keyring: ceph.conf:
#在上面的示例中,keyring 和 ceph.conf 的值应该是经过 Base64 编码的字符串。使用以下命令将文件内容进行 Base64 编码:
cat /path/to/ceph-client-keyring | base64 -w 0cat /path/to/ceph-configuration-file.conf | base64 -w 0
3.应用 Secret 配置:
kubectl apply -f ceph-secret.yaml
4.创建一个 PersistentVolume (PV) 对象,用于描述连接到 Ceph 集群的存储资源。可以通过编辑以下示例,并将其保存为
ceph-pv.yaml 文件来创建 PV:
apiVersion: v1kind: PersistentVolumemetadata: name: ceph-pvspec: capacity: storage: 10Gi accessModes: - ReadWriteOnce cephfs: monitors: - your-ceph-monitor-ip:6789 user: your-ceph-client-user secretRef: name: ceph-secret readOnly: false
#在上面的示例中,monitors 应该填写 Ceph Monitor 的 IP 地址和端口号,user 应该填写连接到 Ceph 集群所使用的 Ceph 客户端用户名。
5.应用 PV 配置:
kubectl apply -f ceph-pv.yaml
6.创建一个 PersistentVolumeClaim (PVC) 对象,用于请求与之前创建的 PV 相匹配的存储资源。可以通过编辑以下示例,并将其保存为
ceph-pvc.yaml 文件来创建 PVC:
apiVersion: v1kind: PersistentVolumeClaimmetadata: name: ceph-pvcspec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi
7.应用 PVC 配置:
kubectl apply -f ceph-pvc.yaml
8.现在,可以在 Pod 中使用之前创建的 PVC 来挂载 Ceph 存储。在 Pod 配置中,将
volumeClaimTemplates 的 claimName 设置为之前创建的 PVC 的名称:
apiVersion: apps/v1kind: Deploymentmetadata: name: your-appspec: replicas: 1 selector: matchLabels: app: your-app template: metadata: labels: app: your-app spec: containers: - name: your-app image: your-image volumeMounts: - name: ceph-pv-mount mountPath: /path/to/mount volumes: - name: ceph-pv-mount persistentVolumeClaim: claimName: ceph-pvc
上一篇:免费下载电视剧大全的详细指南
下一篇:服务器怎么换背板图解?