创建ceph-secret这个k8s secret对象,这个secret对象用于k8s volume插件访问ceph集群

[root@node01 ~]# ceph auth get-key client.admin
AQDEVE1ckPIONRAAUQnbm9hfgweUjiHYo0mTcA==[root@node01 ~]# echo "AQDEVE1ckPIONRAAUQnbm9hfgweUjiHYo0mTcA==" |base64
QVFERVZFMWNrUElPTlJBQVVRbmJtOWhmZ3dlVWppSFlvMG1UY0E9PQo=

创建ceph-secret:

apiVersion: v1
kind: Secret
metadata:
  name: ceph-secret
data:
  key: QVFERVZFMWNrUElPTlJBQVVRbmJtOWhmZ3dlVWppSFlvMG1UY0E9PQo=

创建disk image (以jdk保存到ceph举例)

[root@node01 ~]# rbd create mysql-test -s 10G
[root@node01 ~]# rbd info mysql-test
rbd image 'mysql-test':
    size 2048 MB in 512 objects
    order 22 (4096 kB objects)
    block_name_prefix: rbd_data.372f6b8b4567
    format: 2
    features: layering
    flags:

创建pv

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-test-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  rbd:
    monitors:
      - 192.168.2.11:6789
      - 192.168.2.12:6789
      - 192.168.2.13:6789
    pool: rbd
    image: mysql-test
    user: admin
    secretRef:
       name: ceph-secret
    fsType: ext4
    readOnly: false
  persistentVolumeReclaimPolicy: Recycle

pvc

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mysql-test-pvc
spec:
  accessModes:
    - ReadWriteOnce
  volumeName: mysql-test-pv
  resources:
    requests:
      storage: 10Gi

测试pod:

apiVersion: v1
kind: Pod
metadata:
  name: ceph-mysql-test-pod
spec:
  containers:
  - name: mysql-test
    image: mysql:5.7
    env:
    - name: MYSQL_ROOT_PASSWORD
      value: "EFfDGGG1."
    volumeMounts:
    - name: ceph-mysql-test-vl
      mountPath: /var/lib/mysql
      readOnly: false
  volumes:
  - name: ceph-mysql-test-vl
    persistentVolumeClaim:
      claimName: mysql-test-pvc

ceph rbd 持久化只能同一node挂载,不能跨node,读写只能一个pod,其他pod只能读

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code