基於k8s的DEVOPS Part1 ---- 建立基於NFS的Storage Class
阿新 • • 發佈:2021-01-02
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