Modifying Volume Information for Online Applications in K8S Cluster

Keywords: Web Server Nginx kubelet

Modify NAS version: from v4 to v3

1. To modify the nfs version, the nas volume needs to be reloaded, and the pod needs to be restarted.
2. If deployment application is used, refer to the following example. If deployment application is used with pod, the deployment template of pod is changed in the following example.

Pre-modification application:

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

The resources created are shown below:

# 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

Check the mount parameters, the mount version is: 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)

Update the application nfs version:

Create a new 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"

Create a new 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

Modify the deploy parameter to use the new nas pvc:

    kubectl edit deploy nas-static

//Modify the volume configuration below and change claimName to pvc-nas-new.
      volumes:
      - name: pvc-nas
        persistentVolumeClaim:
          claimName: pvc-nas

==>

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

Check resources:

# 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

Check the mount parameters, the mount version is: vers=3, and the verification parameters include noresvport parameters;

# 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)

Posted by Stole on Thu, 18 Apr 2019 01:30:32 -0700