k8s 1.20.x版本NFS动态存储配置
一、nfs服务器安装nfs与配置
yum -y install nfs-utils rpcbind systemctl start rpcbind.service systemctl start nfs #配置 mkdir /data/nfs -p chown nfsnobody.nfsnobody /data/nfs cat>>/etc/exports<<EOF /data/nfs 172.16.208.0/20(rw,sync,no_root_squash,no_all_squash) EOF exportfs -arv
二、其它客户端服务器安装nfs-utils
yum install -y nfs-utils
三、master导入相应的nfs的yaml配置
github地址: https://github.com/kubernetes-retired/external-storage
1、下载yaml配置
wget https://raw.githubusercontent.com/kubernetes-retired/external-storage/master/nfs-client/deploy/rbac.yaml wget https://raw.githubusercontent.com/kubernetes-retired/external-storage/master/nfs-client/deploy/class.yaml wget https://raw.githubusercontent.com/kubernetes-retired/external-storage/master/nfs-client/deploy/deployment.yaml
2、导入rbac与class
kubectl apply -f class.yaml
kubectl apply -f rbac.yaml
3、修改deploymet文件
[root@master ~]# cat deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: nfs-client-provisioner labels: app: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: default spec: replicas: 1 strategy: type: Recreate selector: matchLabels: app: nfs-client-provisioner template: metadata: labels: app: nfs-client-provisioner spec: serviceAccountName: nfs-client-provisioner containers: - name: nfs-client-provisioner image: quay.io/external_storage/nfs-client-provisioner:latest volumeMounts: - name: nfs-client-root mountPath: /persistentvolumes env: - name: PROVISIONER_NAME value: fuseim.pri/ifs - name: NFS_SERVER value: 172.16.208.176 #nfs服务器ip - name: NFS_PATH value: /data/nfs #nfs服务器的挂载目录 volumes: - name: nfs-client-root nfs: server: 172.16.208.176 #nfs服务器ip path: /data/nfs #nfs服务器的挂载目录
4、导入deploy
kubectl apply -f deployment.yaml
5、查看
[root@master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE nfs-client-provisioner-dfb75c8bb-42p8l 1/1 Running 0 80s [root@master ~]# kubectl get sc NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE managed-nfs-storage fuseim.pri/ifs Delete Immediate false 5m56s
四、k8s1.20.1版本修改api-server配置
修改/etc/kubernetes/manifests/kube-apiserver.yaml 文件
添加添加- --feature-gates=RemoveSelfLink=false
[root@master ~]# grep -B 5 'feature-gates' /etc/kubernetes/manifests/kube-apiserver.yaml - --service-account-key-file=/etc/kubernetes/pki/sa.pub - --service-account-signing-key-file=/etc/kubernetes/pki/sa.key - --service-cluster-ip-range=10.96.0.0/12 - --tls-cert-file=/etc/kubernetes/pki/apiserver.crt - --tls-private-key-file=/etc/kubernetes/pki/apiserver.key - --feature-gates=RemoveSelfLink=false #添加内容
五、测试
[root@master ~]# cat test-pvc.yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: test-claim annotations: volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" spec: accessModes: - ReadWriteMany resources: requests: storage: 1Mi [root@master ~]# kubectl apply -f test-pvc.yaml persistentvolumeclaim/test-claim created [root@master ~]# kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE test-claim Bound pvc-eeb6dd0b-feb8-4884-999a-a15bcd27d7ea 1Mi RWX managed-nfs-storage 9m18s