- 0. 说明
- 涉及镜像
- 1. 部署RBAC
- 1.1. csi-attacher-rbac.yaml
- 1.2. csi-provisioner-rbac.yaml
- 1.3. csi-nodeplugin-rbac.yaml
- 2. 部署CSI sidecar containers
- 2.1. csi-cephfsplugin-provisioner.yaml
- 2.2. csi-cephfsplugin-attacher.yaml
- 3. 部署CSI-CephFS-driver(plugin)
- 3.1. csi-cephfsplugin.yaml
- 4. 确认部署结果
0. 说明
要求Kubernetes的版本在1.11及以上,k8s集群必须允许特权Pod(privileged pods),即apiserver和kubelet需要设置--allow-privileged为true。节点的Docker daemon需要允许挂载共享卷。
涉及镜像
- quay.io/k8scsi/csi-provisioner:v0.3.0
- quay.io/k8scsi/csi-attacher:v0.3.0
- quay.io/k8scsi/driver-registrar:v0.3.0
- quay.io/cephcsi/cephfsplugin:v0.3.0
1. 部署RBAC
部署service accounts, cluster roles 和 cluster role bindings,这些可供RBD和CephFS CSI plugins共同使用,他们拥有相同的权限。
$ kubectl create -f csi-attacher-rbac.yaml$ kubectl create -f csi-provisioner-rbac.yaml$ kubectl create -f csi-nodeplugin-rbac.yaml
1.1. csi-attacher-rbac.yaml
apiVersion: v1kind: ServiceAccountmetadata:name: csi-attacher---kind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1metadata:name: external-attacher-runnerrules:- apiGroups: [""]resources: ["events"]verbs: ["get", "list", "watch", "update"]- apiGroups: [""]resources: ["persistentvolumes"]verbs: ["get", "list", "watch", "update"]- apiGroups: [""]resources: ["nodes"]verbs: ["get", "list", "watch"]- apiGroups: ["storage.k8s.io"]resources: ["volumeattachments"]verbs: ["get", "list", "watch", "update"]---kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata:name: csi-attacher-rolesubjects:- kind: ServiceAccountname: csi-attachernamespace: defaultroleRef:kind: ClusterRolename: external-attacher-runnerapiGroup: rbac.authorization.k8s.io
1.2. csi-provisioner-rbac.yaml
apiVersion: v1kind: ServiceAccountmetadata:name: csi-provisioner---kind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1metadata:name: external-provisioner-runnerrules:- apiGroups: [""]resources: ["secrets"]verbs: ["get", "list"]- apiGroups: [""]resources: ["persistentvolumes"]verbs: ["get", "list", "watch", "create", "delete"]- apiGroups: [""]resources: ["persistentvolumeclaims"]verbs: ["get", "list", "watch", "update"]- apiGroups: ["storage.k8s.io"]resources: ["storageclasses"]verbs: ["get", "list", "watch"]- apiGroups: [""]resources: ["events"]verbs: ["list", "watch", "create", "update", "patch"]---kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata:name: csi-provisioner-rolesubjects:- kind: ServiceAccountname: csi-provisionernamespace: defaultroleRef:kind: ClusterRolename: external-provisioner-runnerapiGroup: rbac.authorization.k8s.io
1.3. csi-nodeplugin-rbac.yaml
apiVersion: v1kind: ServiceAccountmetadata:name: csi-nodeplugin---kind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1metadata:name: csi-nodepluginrules:- apiGroups: [""]resources: ["nodes"]verbs: ["get", "list", "update"]- apiGroups: [""]resources: ["namespaces"]verbs: ["get", "list"]- apiGroups: [""]resources: ["persistentvolumes"]verbs: ["get", "list", "watch", "update"]- apiGroups: ["storage.k8s.io"]resources: ["volumeattachments"]verbs: ["get", "list", "watch", "update"]---kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata:name: csi-nodepluginsubjects:- kind: ServiceAccountname: csi-nodepluginnamespace: defaultroleRef:kind: ClusterRolename: csi-nodepluginapiGroup: rbac.authorization.k8s.io
2. 部署CSI sidecar containers
通过StatefulSet的方式部署external-attacher和external-provisioner供CSI CephFS使用。
$ kubectl create -f csi-cephfsplugin-attacher.yaml$ kubectl create -f csi-cephfsplugin-provisioner.yaml
2.1. csi-cephfsplugin-provisioner.yaml
kind: ServiceapiVersion: v1metadata:name: csi-cephfsplugin-provisionerlabels:app: csi-cephfsplugin-provisionerspec:selector:app: csi-cephfsplugin-provisionerports:- name: dummyport: 12345---kind: StatefulSetapiVersion: apps/v1beta1metadata:name: csi-cephfsplugin-provisionerspec:serviceName: "csi-cephfsplugin-provisioner"replicas: 1template:metadata:labels:app: csi-cephfsplugin-provisionerspec:serviceAccount: csi-provisionercontainers:- name: csi-provisionerimage: quay.io/k8scsi/csi-provisioner:v0.3.0args:- "--provisioner=csi-cephfsplugin"- "--csi-address=$(ADDRESS)"- "--v=5"env:- name: ADDRESSvalue: /var/lib/kubelet/plugins/csi-cephfsplugin/csi.sockimagePullPolicy: "IfNotPresent"volumeMounts:- name: socket-dirmountPath: /var/lib/kubelet/plugins/csi-cephfspluginvolumes:- name: socket-dirhostPath:path: /var/lib/kubelet/plugins/csi-cephfsplugintype: DirectoryOrCreate
2.2. csi-cephfsplugin-attacher.yaml
kind: ServiceapiVersion: v1metadata:name: csi-cephfsplugin-attacherlabels:app: csi-cephfsplugin-attacherspec:selector:app: csi-cephfsplugin-attacherports:- name: dummyport: 12345---kind: StatefulSetapiVersion: apps/v1beta1metadata:name: csi-cephfsplugin-attacherspec:serviceName: "csi-cephfsplugin-attacher"replicas: 1template:metadata:labels:app: csi-cephfsplugin-attacherspec:serviceAccount: csi-attachercontainers:- name: csi-cephfsplugin-attacherimage: quay.io/k8scsi/csi-attacher:v0.3.0args:- "--v=5"- "--csi-address=$(ADDRESS)"env:- name: ADDRESSvalue: /var/lib/kubelet/plugins/csi-cephfsplugin/csi.sockimagePullPolicy: "IfNotPresent"volumeMounts:- name: socket-dirmountPath: /var/lib/kubelet/plugins/csi-cephfspluginvolumes:- name: socket-dirhostPath:path: /var/lib/kubelet/plugins/csi-cephfsplugintype: DirectoryOrCreate
3. 部署CSI-CephFS-driver(plugin)
csi-cephfs-plugin 的作用类似nfs-client,部署在所有node节点上,执行ceph的挂载等相关任务。
通过DaemonSet的方式部署,其中包括两个容器:CSI driver-registrar 和 CSI CephFS driver。
$ kubectl create -f csi-cephfsplugin.yaml
3.1. csi-cephfsplugin.yaml
kind: DaemonSetapiVersion: apps/v1beta2metadata:name: csi-cephfspluginspec:selector:matchLabels:app: csi-cephfsplugintemplate:metadata:labels:app: csi-cephfspluginspec:serviceAccount: csi-nodepluginhostNetwork: true# to use e.g. Rook orchestrated cluster, and mons' FQDN is# resolved through k8s service, set dns policy to cluster firstdnsPolicy: ClusterFirstWithHostNetcontainers:- name: driver-registrarimage: quay.io/k8scsi/driver-registrar:v0.3.0args:- "--v=5"- "--csi-address=$(ADDRESS)"- "--kubelet-registration-path=$(DRIVER_REG_SOCK_PATH)"env:- name: ADDRESSvalue: /var/lib/kubelet/plugins/csi-cephfsplugin/csi.sock- name: DRIVER_REG_SOCK_PATHvalue: /var/lib/kubelet/plugins/csi-cephfsplugin/csi.sock- name: KUBE_NODE_NAMEvalueFrom:fieldRef:fieldPath: spec.nodeNamevolumeMounts:- name: socket-dirmountPath: /var/lib/kubelet/plugins/csi-cephfsplugin- name: registration-dirmountPath: /registration- name: csi-cephfspluginsecurityContext:privileged: truecapabilities:add: ["SYS_ADMIN"]allowPrivilegeEscalation: trueimage: quay.io/cephcsi/cephfsplugin:v0.3.0args :- "--nodeid=$(NODE_ID)"- "--endpoint=$(CSI_ENDPOINT)"- "--v=5"- "--drivername=csi-cephfsplugin"env:- name: NODE_IDvalueFrom:fieldRef:fieldPath: spec.nodeName- name: CSI_ENDPOINTvalue: unix://var/lib/kubelet/plugins/csi-cephfsplugin/csi.sockimagePullPolicy: "IfNotPresent"volumeMounts:- name: plugin-dirmountPath: /var/lib/kubelet/plugins/csi-cephfsplugin- name: pods-mount-dirmountPath: /var/lib/kubelet/podsmountPropagation: "Bidirectional"- mountPath: /sysname: host-sys- name: lib-modulesmountPath: /lib/modulesreadOnly: true- name: host-devmountPath: /devvolumes:- name: plugin-dirhostPath:path: /var/lib/kubelet/plugins/csi-cephfsplugintype: DirectoryOrCreate- name: registration-dirhostPath:path: /var/lib/kubelet/plugins/type: Directory- name: pods-mount-dirhostPath:path: /var/lib/kubelet/podstype: Directory- name: socket-dirhostPath:path: /var/lib/kubelet/plugins/csi-cephfsplugintype: DirectoryOrCreate- name: host-syshostPath:path: /sys- name: lib-moduleshostPath:path: /lib/modules- name: host-devhostPath:path: /dev
4. 确认部署结果
$ kubectl get allNAME READY STATUS RESTARTS AGEpod/csi-cephfsplugin-attacher-0 1/1 Running 0 26spod/csi-cephfsplugin-provisioner-0 1/1 Running 0 25spod/csi-cephfsplugin-rljcv 2/2 Running 0 24sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/csi-cephfsplugin-attacher ClusterIP 10.104.116.218 <none> 12345/TCP 27sservice/csi-cephfsplugin-provisioner ClusterIP 10.101.78.75 <none> 12345/TCP 26s...
参考文档:
- https://github.com/ceph/ceph-csi
- https://github.com/ceph/ceph-csi/blob/master/docs/deploy-cephfs.md
- https://github.com/ceph/ceph-csi/tree/master/deploy/cephfs/kubernetes
