创建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