12 Temmuz 2022 Salı

local Volume - Pod Tekrar Başlarsa Volume'u Bulabilir

Giriş
Bazı notlar şöyle. Örnek video burada

local Volume vs hostpath
Açıklaması şöyle
Local volumes are not a hostPath. HostPath was invented for forwarding directories and files or sockets directly from the host. Local volumes were invented just for storing data.
Bir başka açıklama şöyle
Because programs running on your cluster aren’t guaranteed to run on a specific node, data can’t be saved to any arbitrary place in the file system. If a program tries to save data to a file for later, but is then relocated onto a new node, the file will no longer be where the program expects it to be. For this reason, the traditional local storage associated to each node is treated as a temporary cache to hold programs, but any data saved locally can not be expected to persist.


To store data permanently, Kubernetes uses Persistent Volumes. While the CPU and RAM resources of all nodes are effectively pooled and managed by the cluster, persistent file storage is not. Instead, local or cloud drives can be attached to the cluster as a Persistent Volume. This can be thought of as plugging an external hard drive in to the cluster. Persistent Volumes provide a file system that can be mounted to the cluster, without being associated with any particular node.
local Volume Nedir
Açıklaması şöyle. Yani local volume belirli bir worker node üzerindedir.
It remembers which node was used for provisioning the volume, thus making sure that a restarting POD always will find the data storage in the state it had left it before the reboot.
Açıklaması şöyle. Yani dinamik değildir
A local volume represents a mounted local storage device such as a disk, partition or directory.

Local volumes can only be used as a statically created PersistentVolume. Dynamic provisioning is not supported yet.

Compared to hostPath volumes, local volumes can be used in a durable and portable manner without manually scheduling Pods to nodes, as the system is aware of the volume's node constraints by looking at the node affinity on the PersistentVolume.
Worker Node Çökerse
Açıklaması şöyle
If you're using local volumes, and the node crashes, your pod cannot be rescheduled to a different node. It must be scheduled to the same node. That is the caveat of using local storage, your Pod becomes bound forever to one specific node.
Dezavantajları
1. Being tied to 1 specific node
2. surviving cluster crashes

Kullanım
POD claimName alanı ile PVC'ye atıfta bulunur. PVC ise storageClassName alanı ile PV'ye atıfta bulunur

Varsayılan (Default) PV'ler
Açıklaması şöyle
When you request storage, you can specify a StorageClass. If you do not specify a StorageClass, the default StorageClass is used. For example, suppose you create a PersistentVolumeClaim that does not specify a StorageClass. The volume controller will fulfill the claim according to the default StorageClass.
Açıklaması şöyle
If you set up a Kubernetes cluster on GCP, AWS, Azure, or any other cloud platform, a default StorageClass creates for you which uses the standard persistent disk type.
AWS'de görebiliriz. Şöyle yaparız. İsmi default
$ kubectl get storageclass
NAME PROVISIONER AGE
default (default) kubernetes.io/aws-ebs 3d
GCP'de görebiliriz. Şöyle yaparız. İsmi standard
$ kubectl get storageclass
NAME PROVISIONER AGE
standard (default) kubernetes.io/gce-pd 3d

Örnek - Worker Node Üzerinde
PersistentVolume yaratmak için şöyle yaparız. path ile yolunu belirtiriz.
apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-local-pv
spec:
  capacity:
    storage: 500Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: my-local-storage
  local:
    path: /mnt/disk/vol1
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - node1
Örnek - Worker Node Üzerinde
Şöyle yaparız
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-specific-node
  labels:
    type: local
spec:
  storageClassName: local-storage
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  local:
    path: "/mnt/data2"
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - alex-k8s-2.novalocal
Persistent Volume Claim için şöyle yaparız. storageClassName ile atıfta bulunuruz
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-specific-node
spec:
  storageClassName: local-storage
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 500M
Podda kullanmak için şöyle yaparız. claimName ile Persistent Volume Claim'ye atıfta bulunuruz
apiVersion: v1
kind: Pod
metadata:
  name: task-pv-pod
spec:
  volumes:
    - name: task-pv-storage
      persistentVolumeClaim:
        claimName: pvc-specific-node
  containers:
    - name: task-pv-container
      image: nginx
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: task-pv-storage
Kubernetes bize şunu gösterir
$ kcl get pv
NAME               CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                       STORAGECLASS    REASON   AGE
pv-specific-node   1Gi        RWO            Retain           Bound    default/pvc-specific-node   local-storage            9m28s

$ kcl get pvc
NAME                STATUS   VOLUME             CAPACITY   ACCESS MODES   STORAGECLASS    AGE
pvc-specific-node   Bound    pv-specific-node   1Gi        RWO            local-storage   6m53s



Hiç yorum yok:

Yorum Gönder

Cluster Propotional Autoscaler - ReplicaSet Ekler/Siler

Giriş Açıklaması şöyle CPA aims to horizontally scale the number of Pod replicas based on the cluster’s scale. A common example is DNS ser...