Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I have to explicitly create Persistent Volume when I am using Persistent Volume Claim?

I am new to Kubernetes, and I struggle to understand whol idea behind Persistent Storage in Kubernetes.

So is this enough or I have to create Persistent Volume and what will happen if I deploy only these two object without creating PV?

Storage should be on local machine.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  name: nginx-logs
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
status: {}
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: app-web
  name: app-web
spec:
  selector:
    matchLabels:
      app: app-web
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: app-web
    spec:
      containers:
        image: nginx:1.14.2
        imagePullPolicy: Always
        name: app-web
        volumeMounts:
        - mountPath: /var/log/nginx
          name: nginx-logs
      restartPolicy: Always
      volumes:
      - name: nginx-logs
        persistentVolumeClaim:
          claimName: nginx-logs
like image 981
Most31 Avatar asked Sep 17 '25 03:09

Most31


1 Answers

I struggle to understand whole idea behind Persistent Storage in Kubernetes

The idea is to separate the storage request that the app needs, and the physical storage - such that an app can be moved to e.g. other cloud provider that has a different storage system - but without needing any changes in the app. It also separates the responsibility for "requesting storage" and managing the underlying storage e.g. developers vs operations.

So is this enough or I have to create Persistent Volume and what will happen if I deploy only these two object without creating PV?

This depends on you environment. Most environments typically have Dynamic Volume Provisioning, e.g. the big cloud providers and now also Minikube has support for this.

When using dynamic volume provisioning, the developer only has to create a PersistentVolumeClaim - and no PersistentVolume, its instead dynamically provsioned.

like image 106
Jonas Avatar answered Sep 19 '25 19:09

Jonas