My deployment cant find its persistent volume claim

Hello,

I’m trying to fire up my first application and I’m stuck! :slight_smile: I’m running minikube and the (minikube) documentation states that /data on the host i persistent.

So I put a index.html (Hello World) into /data/www.

For my first kubernetes thingy I’m trying to host this using nginx. As far as I can tell i need a persistent volume, a persistent volume claim, deployment and last a service.

Persistent volume yaml:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: small-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /data
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - my-node

I want to reuse my persistent volume (/data) for other apps so I went with a general name for it. I’m planning on installing nodered (automation app) & others, and nodered for instance could live under /data/nodered. Each app will have its own claim.

Nginx persistent volume claim:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-claim
spec:
  storageClassName: local-storage
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

And finally my deployment. I have not gotten to the service yet as something is wrong.

Deployment:

asd

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginxapp
  name: nginxapp
spec:
  replicas: 1
  volumes:
    - name: nginx-claim
      persistentVolumeClaim:
        claimName: nginx-claim
  selector:
    matchLabels:
      app: nginxapp
  template:
    metadata:
      labels:
        app: nginxapp
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
        volumeMounts:
        - name: nginx-claim
          mountPath: "/data/www"

When publishing the deployment yaml I get this error:

Deployment.apps "nginxapp" is invalid: spec.template.spec.containers[0].volumeMounts[0].name: Not found: "nginx-claim"

I’ve checked the dashboard and both the pv and pvc are green and good.

So now I need some help, I’m pretty new to kubernetes and ba-da-ba-ba-baaa… I’m not loving it :slight_smile:

Structure of the deployment seems to be incorrect. Please use below format, should work:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginxapp
  labels:
    name: nginxapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginxapp
  template:
    metadata:
      labels:
        app: nginxapp
    spec:
      containers:
      - image: nginx:latest
        name: nginx        
        ports:
        - containerPort: 80
          name: mysql
        volumeMounts:
        - name: nginx-claim
          mountPath: "/data/www"
      volumes:
      - name: nginx-claim
        persistentVolumeClaim:
          claimName: nginx-claim

hey, @TheYolo
You could find the same scenario from this link.
volumes field will come under the spec.template.spec.

1 Like

One of the basic mistakes I was doing that after creating the yaml file from the running POD, I again made an entry of volumes after contatner specs.
specs:
volumes:

  • name: pv-vol
    persistentVolumeClaim:
    claimName: pvc-vol
    containers:
  • name: test

When we create the yaml file from the running pod, there is already an entry of volumes.
And while creating the pod again with ‘kubeclt replace -f webpod.yaml --force’ it gives the error of
pod. containers[0].volumes.name: pv-vol not found.

Because the pod is still referring to the volume already defined. Logically it should throw the error duplicate volumes etc.

Please ensure you are also not doing the same mistake.