操作场景
为 TKE 集群挂载 CFS Turbo 类型存储,可以通过安装
kubernetes-csi-tencentloud
组件来实现。该组件基于私有协议将腾讯云 CFS Turbo 文件系统挂载到工作负载,目前仅支持静态配置。CFS 存储类型请参考 文件存储类型及性能规格。 前提条件
已创建 TKE 集群或已在腾讯云自建 Kubernetes 集群,集群版本 >=1.14。
操作步骤
创建文件系统
注意
部署 RBAC 策略
如果您需要挂载 CFS Turbo 存储卷,需执行
kubectl apply -f csi-node-rbac.yaml
命令在集群中先部署 RBAC 策略,csi-node-rbac.yaml 代码参考如下:apiVersion: v1kind: ServiceAccountmetadata:name: cfsturbo-csi-node-sanamespace: kube-system---kind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1metadata:name: cfsturbo-csi-node-rolerules:- apiGroups: [""]resources: ["persistentvolumes", "endpoints", "configmaps"]verbs: ["get", "list", "watch", "create", "delete", "update"]- apiGroups: [""]resources: ["persistentvolumeclaims", "nodes"]verbs: ["get", "list", "watch", "update"]- apiGroups: [""]resources: ["events"]verbs: ["get", "list", "watch", "create", "update", "patch"]- apiGroups: [""]resources: ["secrets", "namespaces"]verbs: ["get", "list"]- apiGroups: [""]resources: ["nodes", "pods"]verbs: ["get", "list", "watch", "update"]- apiGroups: ["storage.k8s.io"]resources: ["volumeattachments", "volumeattachments"]verbs: ["get", "list", "watch", "update", "patch"]- apiGroups: ["storage.k8s.io"]resources: ["storageclasses"]verbs: ["get", "list", "watch"]---kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata:name: cfsturbo-csi-node-rolebindingsubjects:- kind: ServiceAccountname: cfsturbo-csi-node-sanamespace: kube-systemroleRef:kind: ClusterRolename: cfsturbo-csi-node-roleapiGroup: rbac.authorization.k8s.io
部署 Node Plugin
1. 执行
kubectl apply -f csidriver.yaml
命令,csidriver.yaml 代码参考如下:apiVersion: storage.k8s.io/v1beta1kind: CSIDrivermetadata:name: com.tencent.cloud.csi.cfsturbospec:attachRequired: falsepodInfoOnMount: false
2. 执行
kubectl apply -f csi-node.yaml
命令,csi-node.yaml 代码参考如下:# This YAML file contains driver-registrar & csi driver nodeplugin API objects# that are necessary to run CSI nodeplugin for cfsturbokind: DaemonSetapiVersion: apps/v1metadata:name: cfsturbo-csi-nodenamespace: kube-systemspec:selector:matchLabels:app: cfsturbo-csi-nodetemplate:metadata:labels:app: cfsturbo-csi-nodespec:serviceAccount: cfsturbo-csi-node-sahostNetwork: truecontainers:- name: driver-registrarimage: ccr.ccs.tencentyun.com/tkeimages/csi-node-driver-registrar:v1.2.0lifecycle:preStop:exec:command: ["/bin/sh", "-c", "rm -rf /registration/com.tencent.cloud.csi.cfsturbo /registration/com.tencent.cloud.csi.cfsturbo-reg.sock"]args:- "--v=5"- "--csi-address=/plugin/csi.sock"- "--kubelet-registration-path=/var/lib/kubelet/plugins/com.tencent.cloud.csi.cfsturbo/csi.sock"env:- name: KUBE_NODE_NAMEvalueFrom:fieldRef:fieldPath: spec.nodeNamevolumeMounts:- name: plugin-dirmountPath: /plugin- name: registration-dirmountPath: /registration- name: cfsturbosecurityContext:privileged: truecapabilities:add: ["SYS_ADMIN"]allowPrivilegeEscalation: trueimage: ccr.ccs.tencentyun.com/tkeimages/csi-tencentcloud-cfsturbo:v1.2.2args :- "--nodeID=$(NODE_ID)"- "--endpoint=$(CSI_ENDPOINT)"env:- name: NODE_IDvalueFrom:fieldRef:fieldPath: spec.nodeName- name: CSI_ENDPOINTvalue: unix://plugin/csi.sockimagePullPolicy: "IfNotPresent"volumeMounts:- name: plugin-dirmountPath: /plugin- name: pods-mount-dirmountPath: /var/lib/kubelet/podsmountPropagation: "Bidirectional"- name: global-mount-dirmountPath: /etc/cfsturbo/globalmountPropagation: "Bidirectional"volumes:- name: plugin-dirhostPath:path: /var/lib/kubelet/plugins/com.tencent.cloud.csi.cfsturbotype: DirectoryOrCreate- name: pods-mount-dirhostPath:path: /var/lib/kubelet/podstype: Directory- name: registration-dirhostPath:path: /var/lib/kubelet/plugins_registrytype: Directory- name: global-mount-dirhostPath:path: /etc/cfsturbo/globaltype: DirectoryOrCreate
使用 CFS Turbo 存储卷
1. 创建 CFS Turbo 文件系统,具体操作请参见 创建文件系统。
2. 使用以下模板创建 CFS Turbo 类型的 PV。
apiVersion: v1kind: PersistentVolumemetadata:name: pv-cfsturbospec:accessModes:- ReadWriteManycapacity:storage: 10Gicsi:driver: com.tencent.cloud.csi.cfsturbo# volumeHandle in PV must be unique, use pv name is bettervolumeHandle: pv-cfsturbovolumeAttributes:# cfs turbo server iphost: 10.0.0.116# cfs turbo fsid (not cfs id)fsid: xxxxxxxx# cfs turbo rootdirrootdir: /cfs# cfs turbo subPathpath: /proto: lustrestorageClassName: ""
参数说明:
metadata.name: 创建 PV 名称。
spec.csi.volumeHandle: 与 PV 名称保持一致。
spec.csi.volumeAttributes.host: 文件系统 ip 地址,可在文件系统挂载点信息中查看。
spec.csi.volumeAttributes.fsid: 文件系统 fsid(非文件系统 id),可在文件系统挂载点信息中查看(挂载命令中 “tcp0:/” 之后 “/cfs” 之前的那一段字符串,如下图)。
spec.csi.volumeAttributes.rootdir: 文件系统根目录,不填写默认为 “/cfs”(挂载到 “/cfs” 目录可相对提高整体挂载性能)。如需指定根目录挂载,须确保该根目录在文件系统中存在。
spec.csi.volumeAttributes.path: 文件系统子目录,不填写默认为 “/”。如需指定子目录挂载,须确保该子目录在文件系统 rootdir 中存在。容器最终访问到的是文件系统中 rootdir+path 目录(默认为 “/cfs/” 目录)。
spec.csi.volumeAttributes.proto:文件系统默认挂载协议。
![](https://qcloudimg.tencent-cloud.cn/image/document/d0ea18807e541e9dde48612f7337f088.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/d0ea18807e541e9dde48612f7337f088.png)
注意
3. 使用以下模板创建 PVC 绑定 PV。
apiVersion: v1kind: PersistentVolumeClaimmetadata:name: pvc-cfsturbospec:storageClassName: ""volumeName: pv-cfsturboaccessModes:- ReadWriteManyresources:requests:storage: 10Gi
参数说明:
metadata.name: 创建 PVC 名称。
spec.volumeName: 与上一步中创建 PV 名称保持一致。
4. 使用以下模板创建 Pod 挂载 PVC。
apiVersion: v1kind: Podmetadata:name: nginxspec:containers:- image: ccr.ccs.tencentyun.com/qcloud/nginx:1.9imagePullPolicy: Alwaysname: nginxports:- containerPort: 80protocol: TCPvolumeMounts:- mountPath: /var/wwwname: datavolumes:- name: datapersistentVolumeClaim:claimName: pvc-cfsturbo