NFS 服务器配置
# yum install nfs-utils # vi /etc/exports /ifs/kubernetes *(rw,no_root_squash) # mkdir -p /ifs/kubernetes # systemctl start nfs # systemctl enable nfs
注意: 每个Node上都要安装nfs-utils包
创建Storage Class
k8s Maser节点操作
git clone https://github.com/kubernetes-incubator/external-storage cd externel-storage/nfs-client/deploy kubectl apply -f rbac.yaml # 授权访问apiserver kubectl apply -f deployment.yaml # 部署插件,需修改里面NFS服务器地址与共享目录 env: - name: PROVISIONER_NAME value: fuseim.pri/ifs - name: NFS_SERVER value: 172.16.0.11 - name: NFS_PATH value: /ifs/kubernetes volumes: - name: nfs-client-root nfs: server: 172.16.0.11 path: /ifs/kubernetes
kubectl apply -f class.yaml # 创建存储类
验证
### 查看POD [root@k8s-master03 deploy]# kubectl get pod | grep nfs nfs-client-provisioner-7b87dc5c48-rx7zd 1/1 Running 0 5h28m ### 查看storage class [root@k8s-master03 deploy]# kubectl get sc NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE managed-nfs-storage (default) fuseim.pri/ifs Delete Immediate false 5h30m ### 默认该sc不是默认 以下命令更改变为默认 kubectl patch storageclass managed-nfs-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
创建POD应用storage class
apiVersion: apps/v1 kind: Deployment metadata: name: deployment-sc spec: replicas: 3 selector: matchLabels: app: nginx-sc template: metadata: labels: app: nginx-sc spec: containers: - name: nginx image: nginx volumeMounts: - name: wwwroot mountPath: /usr/share/nginx/html ports: - containerPort: 80 volumes: - name: wwwroot persistentVolumeClaim: claimName: my-pvc --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-pvc spec: storageClassName: "managed-nfs-storage" accessModes: - ReadWriteMany resources: requests: storage: 1Gi
###查看 PVC
[root@k8s-master03 deploy]# kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE data-delightful-produce-mariadb-0 Bound pvc-987785b3-e0e2-4f09-ac53-00d1a284fe47 1Gi RWO managed-nfs-storage 5h5m data-four-bite-mariadb-0 Pending 6h58m data-irate-flowers-mariadb-0 Pending 5h24m data-keen-drink-mariadb-0 Bound pvc-669a7af3-c658-4313-828c-858901ce7827 8Gi RWO managed-nfs-storage 5h11m data-ludicrous-creature-mariadb-0 Pending 7h7m data-steady-rhythm-mariadb-0 Pending 5h31m delightful-produce-wordpress Bound pvc-36dbd750-0be5-405f-9bd4-1a845c18bf7d 1Gi RWO managed-nfs-storage 5h5m ### 查看PV
[root@k8s-master03 deploy]# kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-113b07e9-3b72-4a07-9150-d45e0988096a 10Gi RWX Delete Bound ops/prometheus managed-nfs-storage 160m pvc-36dbd750-0be5-405f-9bd4-1a845c18bf7d 1Gi RWO Delete Bound default/delightful-produce-wordpress managed-nfs-storage 5h5m pvc-669a7af3-c658-4313-828c-858901ce7827 8Gi RWO Delete Bound default/data-keen-drink-mariadb-0 managed-nfs-storage 5h11m pvc-7c357792-2c84-4397-872c-82f524adcdce 10Gi RWX Delete Bound ops/es-pvc managed-nfs-storage 57m pvc-987785b3-e0e2-4f09-ac53-00d1a284fe47 1Gi RWO Delete Bound default/data-delightful-produce-mariadb-0 managed-nfs-storage 5h5m pvc-e47138b2-708b-417c-8ac5-0819b3db02d6 5Gi RWX Delete Bound ops/grafana
[root@k8s-master03 deploy]# kubectl get pod | grep nfsnfs-client-provisioner-7b87dc5c48-rx7zd 1/1 Running 0 5h28m