K8s部署cephfs-provisioner —— 筑梦之路

K8s部署cephfs-provisioner —— 筑梦之路_第1张图片

cephfs-provisioner.go
是cephfs-provisioner(cephfs的storageclass)的核心,主要是 watch kubernetes中 PVC 资源的CURD事件,然后以命令行方式调用 cephfs_provisor.py脚本创建PV。

cephfs_provisioner.py
python 脚本实现的与cephfs交互的命令行工具。cephfs-provisioner 对cephfs端volume的创建都是通过该脚本实现。里面封装了volume的增删改查等功能。 

https://github.com/kubernetes-incubator/external-storage/tree/master/ceph/cephfs/deploy 

# 创建名空间

kubectl create ns cephfs

# 安装cephfs-provisioner

git clone https://github.com/kubernetes-retired/external-storage.git

cd external-storage/ceph/cephfs/deploy/

NAMESPACE=cephfs

sed -i "/PROVISIONER_SECRET_NAMESPACE/{n;s/value:.*/value: $NAMESPACE/;}" rbac/deployment.yaml

kubectl -n $NAMESPACE apply -f ./rbac

 

# 查看pod

kubectl get pods -n cephfs|grep 'cephfs-provisioner'

# 所有node节点安装cephfs客户端,主要用来和ceph集群挂载使用

yum install -y ceph-common

# 在ceph-manager节点查看ceph管理密钥

ceph auth get-key client.admin|base64

# 创建secret

apiVersion: v1
kind: Secret
metadata:
  name: cephfs-secret
  namespace: cephfs
data:
  key: xxxx==

# 为cephfs创建stoageclass资源

echo '''kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: cephfs
  namespace: cephfs
provisioner: ceph.com/cephfs
parameters:
    monitors: 192.168.100.11:6789,192.168.100.12:6789,192.168.100.13:6789
    adminId: admin
    adminSecretNamespace: "cephfs"
    adminSecretName: cephfs-secret'''>sc.yaml


# 创建pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: claim
  namespace: cephfs
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: cephfs
  resources:
    requests:
      storage: 100Gi

# 创建pod

kind: Pod
apiVersion: v1
metadata:
  name: test-pod
  namespace: cephfs
spec:
  containers:
  - name: test-pod
    image: ikubernetes/myapp:v4
    volumeMounts:
      - name: pvc
        mountPath: "/data/cephfs"
  volumes:
    - name: pvc
      persistentVolumeClaim:
        claimName: claim

你可能感兴趣的:(linux系统运维,云计算,虚拟化,kubernetes,容器,云原生)