[5] MicroK8s – Magazyny
21 lutego 2021Aby włączyć wbudowane w MicroK8s magazyny skonfiguruj go tak jak poniżej.
[1] Włącz wbudowany magazyn na pierwszym/głównym węźle
[root@vlsr01 ~]# export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/lib64"
[root@vlsr01 ~]# microk8s enable storage
Enabling default storage class
deployment.apps/hostpath-provisioner created
storageclass.storage.k8s.io/microk8s-hostpath created
serviceaccount/microk8s-hostpath created
clusterrole.rbac.authorization.k8s.io/microk8s-hostpath created
clusterrolebinding.rbac.authorization.k8s.io/microk8s-hostpath created
Storage will be available soon
# uruchomiony zostaje pods [hostpath-provisioner]
[root@vlsr01 ~]# microk8s kubectl -n kube-system get pods
NAME READY STATUS RESTARTS AGE
calico-node-vq9h7 1/1 Running 0 2d1h
metrics-server-8bbfb4bdb-x2rrq 1/1 Running 2 2d2h
calico-kube-controllers-847c8c99d-mv2g6 1/1 Running 2 2d3h
calico-node-574jj 1/1 Running 2 2d3h
kubernetes-dashboard-7ffd448895-fq852 1/1 Running 0 6h57m
dashboard-metrics-scraper-6c4568dc68-mh6jd 1/1 Running 0 6h57m
hostpath-provisioner-5c65fbdb4f-5qm5d 1/1 Running 0 6h57m
coredns-86f78bb79c-kptf4 1/1 Running 0 6h57m
[2] W tym przykładzie użyjemy magazynu do zdefiniowania obiektu PVC (Persistent Volume Claim)
[root@vlsr01 ~]# mcedit zl-pvc.yml apiVersion: v1 kind: PersistentVolumeClaim metadata: # dowolna nazwa name: zl-pvc spec: # tryby dostępu: # - ReadWriteMany (RW z wielu węzłów) # - ReadWriteOnce (RW z węzła) # - ReadOnlyMany (R z wielu węzłów) accessModes: - ReadWriteMany # sprecyzuj microk8s-hostpath storageClassName: microk8s-hostpath resources: requests: # rozmiar magazynu do użycia storage: 1Gi [root@vlsr01 ~]# microk8s kubectl create -f zl-pvc.yml persistentvolumeclaim/zl-pvc created [root@vlsr01 ~]# microk8s kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-e5ee45b5-83e0-4c6d-a2c1-688357e58aaf 1Gi RWX Delete Bound default/zl-pvc microk8s-hostpath 8s [root@vlsr01 ~]# microk8s kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE zl-pvc Bound pvc-e5ee45b5-83e0-4c6d-a2c1-688357e58aaf 1Gi RWX microk8s-hostpath 26s # dla przykładu stwórzmy kapsułę nginx # UWAGA NA WCIĘCIA!!! [root@vlsr01 ~]# mcedit nginx-zl.yml apiVersion: v1 kind: Pod metadata: name: nginx-zl labels: name: nginx-zl spec: containers: - name: nginx-zl image: fedora/nginx ports: - name: web containerPort: 80 volumeMounts: - name: zl-persistent-volume mountPath: /usr/share/nginx/html volumes: - name: zl-persistent-volume persistentVolumeClaim: # wpisz nazwę utworzonego wcześniej PVC claimName: zl-pvc [root@vlsr01 ~]# microk8s kubectl create -f nginx-zl.yml pod/nginx-zl created [root@vlsr01 ~]# microk8s kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-zl 1/1 Running 0 81s 10.1.86.210 vlsr01.zicher.lab <none> <none> # potwierdź ścieżkę PVC [root@vlsr01 ~]# microk8s kubectl describe -n kube-system pod/hostpath-provisioner-5c65fbdb4f-5qm5d | grep PV_DIR PV_DIR: /var/snap/microk8s/common/default-storage [root@vlsr01 ~]# microk8s kubectl describe pvc/zl-pvc | grep ^Volume: Volume: pvc-e5ee45b5-83e0-4c6d-a2c1-688357e58aaf # stwórz testową stronę [root@vlsr01 ~]# echo "MicroK8s - ZICHER.LAB" > /var/snap/microk8s/common/default-storage/default-zl-pvc-pvc-e5ee45b5-83e0-4c6d-a2c1-688357e58aaf/index.html # sprawdź czy to działa [root@vlsr01 ~]# curl 10.1.86.210 MicroK8s - ZICHER.LAB