K8S集群中修改在线应用的存储卷信息-阿里云开发者社区

开发者社区> 阿里云容器服务 ACK> 正文

K8S集群中修改在线应用的存储卷信息

简介: 修改应用NAS版本:从v4到v3 1. 修改nfs版本,需要重挂载nas卷,则pod需要重启; 2. 如果使用deploy部署应用,参考下面示例,如果使用pod部署应用,下面示例中改为pod的部署模板; 修改前应用: pv.

修改应用NAS版本:从v4到v3

1. 修改nfs版本,需要重挂载nas卷,则pod需要重启;
2. 如果使用deploy部署应用,参考下面示例,如果使用pod部署应用,下面示例中改为pod的部署模板;

修改前应用:

pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-nas
  labels:
    alicloud-pvname: pv-nas
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  flexVolume:
    driver: "alicloud/nas"
    options:
      server: "2564f49129-ggu23.cn-shenzhen.nas.aliyuncs.com"
      path: "/k8sa"
      vers: "4.0"

pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-nas
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  selector:
    matchLabels:
      alicloud-pvname: pv-nas

deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nas-static
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
          - name: pvc-nas
            mountPath: "/data"
      volumes:
        - name: pvc-nas
          persistentVolumeClaim:
            claimName: pvc-nas

创建的资源如下显示:

# kubectl get pod | grep nas
nas-static-784496fbb9-8pd97   1/1     Running   0          33s

# kubectl get pvc | grep nas
pvc-nas                                    Bound    pv-nas                   5Gi        RWX                                  19s

# kubectl get pv | grep nas
pv-nas                   5Gi        RWX            Retain           Bound       default/pvc-nas                                                                   3m31s

检查挂载参数,挂载版本为:vers=4.0

# mount | grep nfs | grep pv-nas
2564f49129-ggu23.cn-shenzhen.nas.aliyuncs.com:/k8sa on /var/lib/kubelet/pods/0ce34c11-60f7-11e9-a545-00163e0eff42/volumes/alicloud~nas/pv-nas 
type nfs4 (rw,relatime,vers=4.0,rsize=1048576,wsize=1048576,namlen=255,hard,noresvport,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.0.10,local_lock=none,addr=192.168.0.11)

更新应用nfs版本:

创建新pv:pv-new.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-nas-new
  labels:
    alicloud-pvname: pv-nas-new
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  flexVolume:
    driver: "alicloud/nas"
    options:
      server: "2564f49129-ggu23.cn-shenzhen.nas.aliyuncs.com"
      path: "/k8sa"
      vers: "3"

创建新pvc:pvc-new.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-nas-new
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  selector:
    matchLabels:
      alicloud-pvname: pv-nas-new

修改deploy参数,使用新的nas pvc:

    kubectl edit deploy nas-static

修改下面volume配置,改claimName为pvc-nas-new;
      volumes:
      - name: pvc-nas
        persistentVolumeClaim:
          claimName: pvc-nas

==>

      volumes:
      - name: pvc-nas
        persistentVolumeClaim:
          claimName: pvc-nas-new

检查资源:

# kubectl get pod | grep nas
nas-static-5989b7cd64-cbqqc   1/1     Running   0          18m

# kubectl get pvc | grep nas
pvc-nas                                    Bound    pv-nas                   5Gi        RWX                                  26m
pvc-nas-new                                Bound    pv-nas-new               5Gi        RWX                                  19m

# kubectl get pv | grep nas
pv-nas                   5Gi        RWX            Retain           Bound       default/pvc-nas                                                                   27m
pv-nas-new               5Gi        RWX            Retain           Bound       default/pvc-nas-new                                                               19m

检查挂载参数,挂载版本为:vers=3,且验证参数中包含 noresvport参数;

# mount | grep nfs |grep pv-nas-new
2564f49129-ggu23.cn-shenzhen.nas.aliyuncs.com:/k8sa on /var/lib/kubelet/pods/2fddf3ad-60f8-11e9-a545-00163e0eff42/volumes/alicloud~nas/pv-nas-new 
type nfs (rw,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,hard,nolock,noresvport,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.0.11,mountvers=3,mountport=4002,mountproto=tcp,local_lock=all,addr=192.168.0.11)

版权声明:本文中所有内容均属于阿里云开发者社区所有,任何媒体、网站或个人未经阿里云开发者社区协议授权不得转载、链接、转贴或以其他方式复制发布/发表。申请授权请邮件developerteam@list.alibaba-inc.com,已获得阿里云开发者社区协议授权的媒体、网站,在转载使用时必须注明"稿件来源:阿里云开发者社区,原文作者姓名",违者本社区将依法追究责任。 如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:developer2020@service.aliyun.com 进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
阿里云容器服务 ACK
使用钉钉扫一扫加入圈子
+ 订阅

云端最佳容器应用运行环境,安全、稳定、极致弹性

官方博客
官网链接