先安装alicloud-nas-controller

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

新建nas,过载到ecs,在nas根目录创建子目录如k8s-nas

创建StorageClass

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nas
mountOptions:
- nolock,tcp,noresvport
- vers=4
parameters:
  server: "test1234-ejs14.cn-hongkong.nas.aliyuncs.com:/k8s-nas"
  driver: flexvolume
provisioner: alicloud/nas
reclaimPolicy: Retain

说明

mountOptions:表示生成的pv options 配置,挂载NAS卷时使用这个options挂载。
server:表示生成目标PV所使用NAS挂载点列表。格式为 nfsurl1:/path1,nfsurl2:/path2;当配置多个server时,通过此storageclass创建的PV会轮询使用上述server作为配置参数;极速NAS配置路径需要以/share开头。
driver:支持Flexvolume、NFS两种驱动,默认为NFS。
reclaimPolicy:PV的回收策略,建议配置为 Retain。
当配置为Delete时,删除PV后NAS文件系统中的对应目录会默认修改名字(例如,path-name会被修改为archived-path-name)。
如果需要删除文件系统中对应的存储目录,可在storageclass中配置archiveOnDelete为false。

test-pvc-nas

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  replicas: 5
  volumeClaimTemplates:
  - metadata:
      name: html
    spec:
      accessModes:
        - ReadWriteMany
      storageClassName: nas
      resources:
        requests:
          storage: 2Gi
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        volumeMounts:
        - mountPath: "/data"
          name: html

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code