zl程序教程

您现在的位置是:首页 >  后端

当前栏目

K8S使用CephFS进行数据持久化

k8s数据 进行 持久 使用
2023-09-14 09:01:48 时间

K8S结合CephFS使用

ceph查看密钥

ceph auth get-key client.admin |base64

在k8s-master上面创建secret

#vim ceph-secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: ceph-secret
data:
  key: QVFDa2R0cGhiZlZXRWhBQVd3VDAxWnl5OWlaU3BWN3NlcTk3bWc9PQ==

创建PV

#vim pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: cephfs-pv
  labels:
    pv: cephfs-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  cephfs:
    monitors:
      - 10.66.66.106:6789
    user: admin
    secretRef:
      name: ceph-secret
    readOnly: false
  persistentVolumeReclaimPolicy: Delete

创建PVC

#vim PVC.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: cephfs-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  selector:
    matchLabels:
      pv: cephfs-pv

创建测试pod

#vim nginx-pod.yaml
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: cephfs-pvc
    mountPath: /usr/share/nginx/html
volumes:
- name: cephfs-pvc
  persistentVolumeClaim:
    claimName: cephfs-pvc