Monday, August 26, 2024

Kubernetes - Volumes [Part 5]




The Kubernetes scheduler ensure that sum of all pod request will not exceed the node.  These containers are automatically restarted but with less available memory on the machine for the container to consume.

We can set the maximum limit of resources through limits.

Creating the persistence volume:

To add a volume to a Pod manifest, we need to define twice in our configuration file. We need to define first in spec.volume section where all the volumes are accessing by Pod and second section is the volumeMounts array in the container definition. This array defines the volumes that are mounted into  particular container.

Example:

apiVersion: v1

kind: Pod

metadata:

  name: kuard

spec:

  volumes:

    - name: "kuard-data"

      hostPath:

        path: "/var/lib/kuard"

  containers:

    - image: gcr.io/kuar-demo/kuard-amd64:blue

      name: kuard

      volumeMounts:

        - mountPath: "/data"

          name: "kuard-data"

      ports:

        - containerPort: 8080

          name: http

          protocol: TCP

Different way of volumes used by Pod:

emptyDir - It is scope of Pod life cycle. It will create a communication between two pods. It will use for cache purpose as well.

Persistent data - This volume is independent of life span of particular pod. Kubernetes supports a wide variety of remote network storage volumes including NFS, iSCSI and cloud provider such as Amazon's Elastic Block Store, Azure's file as well as Google's Persistent Disk.

Mounting the host filesystem : Some application is not require for the persistence data, but need to access of few files underlying worker node. Kubernetes support hostPath volume which mount arbitrary location on the worker node into container.

Persistence volume is defined inside of pod:

Example:

apiVersion: v1

kind: Pod

metadata:

  name: kuard

spec:

  volumes:

    - name: "kuard-data"

      nfs:

        server: my.nfs.server.local

        path: "/exports"

  containers:

    - image: gcr.io/kuar-demo/kuard-amd64:blue

      name: kuard

      ports:

        - containerPort: 8080

          name: http

          protocol: TCP

      resources:

        requests:

          cpu: "500m"

          memory: "128Mi"

        limits:

          cpu: "1000m"

          memory: "256Mi"

      volumeMounts:

        - mountPath: "/data"

          name: "kuard-data"

      livenessProbe:

        httpGet:

          path: /healthy

          port: 8080

        initialDelaySeconds: 5

        timeoutSeconds: 1

        periodSeconds: 10

        failureThreshold: 3

      readinessProbe:

        httpGet:

          path: /ready

          port: 8080

        initialDelaySeconds: 30

        timeoutSeconds: 1

        periodSeconds: 10

        failureThreshold: 3

No comments:

Post a Comment