修改应用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)