目标
kubenets 通过调用 (mount 方法) cephfs 以静态 pvc 方法提供 pod 使用
环境
环境 | 版本 |
---|---|
ceph | ceph-12.2.0-0.el7 |
os | centos7.3 |
kernel | 3.10.0-862.9.1.el7.x86_64 |
参考
kubenetes yaml example 参考
手动创建 cephfs 方法
注意
kubenetes 中不可以直接使用 ceph 授权用户的 key
key 需要转换为 base64 格式
因为要使用了 xfs 文件系统格式,因此每个 pod 都需要有一个 cephfs 共享目录独享
cephfs 目录结构
我们需要有一个管理员可以访问 cephfs / 目录
计划在 cephfs / 下创建不通的目录,提供目录给不同的 pod 调用
ex:
# tree
.
├── podtest1 ( 给 testpod1 使用 )
├── podtest2 ( 给 testpod2 使用 )
├── podtest3 ( 给 testpod3 使用 )
├── podtest4 ( 给 testpod4 使用 )
├── podtest5 ( 给 testpod5 使用 )
└── podtest6 ( 给 testpod6 使用 )
cephfs 用户创建
说明
noah_fs 是 cephfs 卷
client.terry 中 terry 才是用户名
/podtest1 是 cephfs 共享中的指定目录
目录需要在共享前由有对 / 访问权限的用户先创建好, 否则会无法完成挂载
添加新用户及权限方法
# ceph fs authorize noah_fs client.pod /podtest1 rw /podtest2 rw /podtest3 rw /podtest4 rw /podtest5 rw
[client.pod]
key = AQCUxxxxxxxxxxxxxxxxxxxxxxxxxpBJA==
查询用户权限方法
# ceph auth get client.pod
exported keyring for client.pod
[client.pod]
key = AQCUxxxxxxxxxxxxxxxxxxxxxxxxxpBJA==
caps mds = "allow rw path=/podtest1, allow rw path=/podtest2, allow rw path=/podtest3, allow rw path=/podtest4, allow rw path=/podtest5"
caps mon = "allow r"
caps osd = "allow rw pool=cephfs_data"
假如用户已经存在, 需要为用户增加新目录读写权限,那么需要改成下面命令
切记要包含了之前的权限, 参考下面命令
# ceph auth caps client.pod mon "allow r" osd "allow rw pool=cephfs_data" mds "allow rw path=/podtest1, allow rw path=/podtest2, allow rw path=/podtest3, allow rw path=/podtest4, allow rw path=/podtest5, allow rw path=/padtest6"
updated caps for client.pod
再次参考用户权限
# ceph auth get client.pod
exported keyring for client.pod
[client.pod]
key = AQCUxxxxxxxxxxxxxxxxxxxxxxxxxpBJA==
caps mds = "allow rw path=/podtest1, allow rw path=/podtest2, allow rw path=/podtest3, allow rw path=/podtest4, allow rw path=/podtest5, allow rw path=/padtest6"
caps mon = "allow r"
caps osd = "allow rw pool=cephfs_data"
查询用户权限方法
检测测试用户权限
# ceph auth get client.terry
exported keyring for client.terry
[client.terry]
key = AQCUxxxxxxxxxxxxxxxxxxxxxxxxxpBJA==
caps mds = "allow rw path=/podtest1, allow rw path=/podtest2, allow rw path=/podtest3, allow rw path=/podtest4, allow rw path=/podtest5, allow rw path=/terry, allow rw path=/backupdata"
caps mon = "allow r"
caps osd = "allow rw pool=cephfs_data"
cephfs key 转换方法
参考命令即可获取 base64 格式 ceph secret key
# ceph auth get-key client.terry | base64
QVFxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzcWpVcXlRRkE9PQ==
kubenetes 参考
参考下面步骤可以完成 cephfs 挂载测试
1 创建 namespace
2 创建 secret key 用户验证 cephfs
3 创建 pv
4 创建 pvc
5 创建 pod 连接 pvc 使用
namespace 创建
kubectl create namespace cephfs
secret key
参考下面 yaml 文件 (注意使用了 base64 key)
apiVersion: v1
kind: Secret
metadata:
name: ceph-secret-terry
namespace: cephfs
data:
key: QVFxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzcWpVcXlRRkE9PQ==
create pv
参考下面 yaml 文件
针对不同的 cephfs / 目录下的子目录共享, 需要创建多个 pv 文件, 这里只做两个演示
ex1
# cat cephfs-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: cephfs-pv-podtest01
namespace: cephfs
spec:
capacity:
storage: 50Gi
accessModes:
- ReadWriteMany
cephfs:
monitors:
- 10.189.xx.100:6789
- 10.189.xx.101:6789
- 10.189.xx.102:6789
user: terry
path: /podtest1
secretRef:
name: ceph-secret-terry
readOnly: false
ex2
# cat cephfs-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: cephfs-pv-podtest02
namespace: cephfs
spec:
capacity:
storage: 50Gi
accessModes:
- ReadWriteMany
cephfs:
monitors:
- 10.189.xx.100:6789
- 10.189.xx.101:6789
- 10.189.xx.102:6789
user: terry
path: /podtest2
secretRef:
name: ceph-secret-terry
readOnly: false
应用上述 yaml 文件
# kubectl apply -f cephfs-pv-01.yaml
persistentvolume/cephfs-pv-podtest01 created
# kubectl apply -f cephfs-pv-02.yaml
persistentvolume/cephfs-pv-podtest02 created
create pvc
必须先创建 PV 才可以创建 pvc
一个 pvc 只可以对应一个 pv
pod 创建过程中,需要指定 pvc 名称
本文只用于测试,因此使用静态 PVC 进行 CEPHFS 连接
如需使用动态 PVC, 请执行参考其他信息
参考下面两个 pvc yaml 文件
ex1
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cephfs-pvc-podtest01
namespace: cephfs
spec:
accessModes:
- ReadWriteMany
volumeName: cephfs-pv-podtest01
resources:
requests:
storage: 20Gi
ex2
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cephfs-pvc-podtest02
namespace: cephfs
spec:
accessModes:
- ReadWriteMany
volumeName: cephfs-pv-podtest02
resources:
requests:
storage: 20Gi
应用上面上述两个 pvc 文件
# kubectl apply -f cephfs-pvc-01.yaml
persistentvolumeclaim/cephfs-pvc-podtest01 created
# kubectl apply -f cephfs-pvc-02.yaml
persistentvolumeclaim/cephfs-pvc-podtest02 created
检测对应的 pvc
# kubectl -n cephfs get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
cephfs-pvc-podtest01 Bound cephfs-pv-podtest01 50Gi RWX 60s
cephfs-pvc-podtest02 Bound cephfs-pv-podtest02 50Gi RWX 58s
create pod
参考下面 yaml 文件
apiVersion: v1
kind: Pod
metadata:
name: cephfs-podtest-01
namespace: cephfs
spec:
containers:
- name: cephfs-podtest-01
image: "centos7.3-base-7:last"
command: ["/bin/bash", "-c", "sleep 1000000000"]
volumeMounts:
- name: pod-mount-001
mountPath: "/media"
volumes:
- name: pod-mount-001
persistentVolumeClaim:
claimName: "cephfs-pvc-podtest01"
启动该 pod
# kubectl apply -f testpod-ceph-pv01.yaml
pod/cephfs-podtest-01 created
检测 pod 启动情况
# kubectl -n cephfs get pod
NAME READY STATUS RESTARTS AGE
cephfs-podtest-01 1/1 Running 0 94s
cephfs-podtest-02 1/1 Running 0 93s
登录 pod 进行测试
# kubectl -n cephfs -u root exec -it cephfs-podtest-01 /bin/bash
检测 cephfs
# mount | grep media
ceph-fuse on /media type fuse.ceph-fuse (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other)