本文指导您通过YAML模板配置部署阿里云Kubernetes存储插件。

说明 如果您的Kubernetes集群是在 2018年2月6日之前创建的,那么您使用数据卷之前需要先安装阿里云Kubernetes存储插件;如果您的Kubernetes集群是在2018年2月6日之后创建的,那么您可以直接使用数据卷,不需要再安装阿里云Kubernetes存储插件。

前提条件

使用限制

目前支持CentOS 7操作系统。

注意事项

  • 使用Flexvolume需要kubelet关闭--enable-controller-attach-detach选项。默认阿里云Kubernetes集群已经关闭此选项。
  • 在kube-system命名空间部署Flexvolume。

验证安装完成

在Master节点上:

  • 执行以下命令,输出若干(节点个数)Running状态的Pod列表。
    kubectl get pod -n kube-system | grep flexvolume
  • 执行以下命令,输出一个Running状态的Pod列表。
    kubectl get pod -n kube-system | grep alicloud-disk-controller

安装Flexvolume

Flexvolume在Kubernetes集群中已经默认安装。

如果您的集群中没有安装该插件 ,可以通过以下YAML模板手动安装。

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: flexvolume
  namespace: kube-system
  labels:
    k8s-volume: flexvolume
spec:
  selector:
    matchLabels:
      name: acs-flexvolume
  template:
    metadata:
      labels:
        name: acs-flexvolume
    spec:
      hostPID: true
      hostNetwork: true
      tolerations:
      - operator: Exists
      priorityClassName: system-node-critical
      containers:
      - name: acs-flexvolume
        image: registry.cn-hangzhou.aliyuncs.com/acs/flexvolume:v1.14.8.88-00a6585-aliyun
        imagePullPolicy: Always
        securityContext:
          privileged: true
        env:
        - name: ACS_DISK
          value: "true"
        - name: ACS_NAS
          value: "true"
        - name: ACS_OSS
          value: "true"
        livenessProbe:
          exec:
            command:
            - sh
            - -c
            - ls /acs/flexvolume
          failureThreshold: 8
          initialDelaySeconds: 15
          periodSeconds: 60
          successThreshold: 1
          timeoutSeconds: 15
        volumeMounts:
        - name: usrdir
          mountPath: /host/usr/
        - name: etcdir
          mountPath: /host/etc/
        - name: logdir
          mountPath: /var/log/alicloud/
        - mountPath: /var/lib/kubelet
          mountPropagation: Bidirectional
          name: kubeletdir
      volumes:
      - name: usrdir
        hostPath:
          path: /usr/
      - name: etcdir
        hostPath:
          path: /etc/
      - name: logdir
        hostPath:
          path: /var/log/alicloud/
      - hostPath:
          path: /var/lib/kubelet
          type: Directory
        name: kubeletdir
  updateStrategy:
    rollingUpdate:
      maxUnavailable: 10%
    type: RollingUpdate

安装Disk Controller

Disk Controller在Kubernetes集群中已经默认安装。

如果您的集群中没有安装该插件 ,可以通过以下YAML模板手动安装。
---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: alicloud-disk-essd
provisioner: alicloud/disk
parameters:
  type: cloud_essd

---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: alicloud-disk-efficiency
provisioner: alicloud/disk
parameters:
  type: cloud_efficiency

---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: alicloud-disk-ssd
provisioner: alicloud/disk
parameters:
  type: cloud_ssd

---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: alicloud-disk-available
provisioner: alicloud/disk
parameters:
  type: available

---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: alicloud-disk-controller
  namespace: kube-system
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: alicloud-disk-controller
    spec:
      tolerations:
      - operator: Exists
      priorityClassName: system-node-critical
      nodeSelector:
         node-role.kubernetes.io/master: 
      serviceAccount: admin
      serviceAccountName: admin
      containers:
        - name: alicloud-disk-controller
          image: registry.cn-hangzhou.aliyuncs.com/acs/alicloud-disk-controller:v1.12.6.21-54d91d6-aliyun
          volumeMounts:
            - name: cloud-config
              mountPath: /etc/kubernetes/
            - name: logdir
              mountPath: /var/log/alicloud/
          resources:
            limits:
              cpu: 200m
              memory: 200Mi
            requests:
              cpu: 100m
              memory: 100Mi
          livenessProbe:
            exec:
              command:
              - sh
              - -c
              - ps -ef | grep /alicloud-disk-controller | grep -v grep
            failureThreshold: 8
            initialDelaySeconds: 15
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 15
      volumes:
        - name: cloud-config
          hostPath:
            path: /etc/kubernetes/
        - name: logdir
          hostPath:
            path: /var/log/alicloud/

安装NAS Controller

NAS Controller默认不安装,您可以在使用时,通过以下YAML模板手动安装。
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: alicloud-nas-controller
  namespace: kube-system
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: alicloud-nas-controller
    spec:
      tolerations:
      - operator: Exists
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            preference:
              matchExpressions:
              - key: node-role.kubernetes.io/master
                operator: Exists
      priorityClassName: system-node-critical
      serviceAccount: admin
      hostNetwork: true
      containers:
        - name: nfs-provisioner
          image: registry.cn-hangzhou.aliyuncs.com/acs/alicloud-nas-controller:v1.14.3.8-58bf821-aliyun
          env:
          - name: PROVISIONER_NAME
            value: alicloud/nas
          securityContext:
            privileged: true
          volumeMounts:
          - mountPath: /var/log
            name: log
      volumes:
      - hostPath:
          path: /var/log
        name: log