Pod使用块存储和文件系统

创建ceph密钥

获取ceph客户端用户密钥

ceph auth get-key client.admin |base64
QVFDYlpmUmpTUjhaSVJBQW1DTGlUa3YvMXA5Si95V05TNU9Zb2c9PQ==

创建密钥文件ceph-secret.yaml

apiVersion: v1
kind: Secret
metadata:
  name: ceph-secret
type: "kubernetes.io/rbd"
data:
  key: QVFDYlpmUmpTUjhaSVJBQW1DTGlUa3YvMXA5Si95V05TNU9Zb2c9PQ==

应用密钥

kubectl apply -f ceph-secret.yaml

确认RBD和Cephfs

# ceph osd pool create data 32
# rbd create rbd1 --size 1G -p data

# ceph osd pool create cephfs_data 32
# ceph osd pool create cephfs_metadata 32
# ceph fs new cephfs cephfs_metadata cephfs_data
# mkdir /mnt/cephfs
# mount -t ceph -o name=admin,secret=$(ceph auth get-key client.admin) 10.0.0.101:6789,10.0.0.102:6789,10.0.0.103:6789:/ /mnt/cephfs
# mkdir /mnt/cephfs/k8s-test

创建Pod

编辑yaml文件

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nginx-test-rbd-pv-01
  namespace: default
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  rbd:
    monitors:
      - 10.0.0.101:6789
      - 10.0.0.102:6789
      - 10.0.0.103:6789
    pool: data
    image: rbd1
    user: admin
    secretRef:
      name: ceph-secret
    fsType: ext4
    readOnly: false
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nginx-test-rbd-pvc-01
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nginx-test-cephfs-pv-01
  namespace: default
spec:
  capacity:
    storage: 100Mi
  accessModes:
    - ReadWriteMany
  cephfs:
    monitors:
    - 10.0.0.101:6789
    - 10.0.0.102:6789
    - 10.0.0.102:6789
    path: /k8s-test # 已在文件存储目录中创建该目录
    user: admin
    secretRef:
      name: ceph-secret
    readOnly: false
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nginx-test-cephfs-pvc-01
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 100Mi
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx-test-cephfs-01
spec:
  containers:
  - name: nginx-test-cephfs
    image: hub.linx.com/k8s/nginx-test:latest
    volumeMounts:
    - name: cephfs-vol1
      mountPath: "/conf"
    - name: ceph-rbd1
      mountPath: "/data"
  volumes:
  - name: cephfs-vol1
    persistentVolumeClaim:
      claimName: nginx-test-cephfs-pvc-01
  - name: ceph-rbd1
    persistentVolumeClaim:
      claimName: nginx-test-rbd-pvc-01
kubectl apply -f ceph-test.yaml
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值