yum -y install nfs-utils rpcbind systemctl start rpcbind.service systemctl start nfs #配置 mkdir /data/nfs -p chow 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
yum install -y nfs-utils
github地址: https://github.com/kubernetes-retired/external-storage
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
kubectl apply -f class.yaml kubectl apply -f rbac.yaml
[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服务器的挂载目录
kubectl apply -f deployment.yaml
[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
修改/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