Kubernetes container VolumeMounts not found?

4/10/2020

I have been trying to create postgresdb with the below yaml in kubernetes but running into below error

The Deployment "postgres-airflow" is invalid: spec.template.spec.containers[0].volumeMounts[0].name: Not found: "postgres-vol"

can some please shed some light on this ? Not sure what i'm missing and it would be even more helpful if someone can let me know how to create dynamic volumes using azure fileshare as a storageClass. Any help would be greatly appreciated

Yaml file that i'm using to deploy postgres is below...

kind: Deployment
apiVersion: apps/v1 
metadata:
  name: postgres-airflow
spec:
  replicas: 1 
  selector:
    matchLabels:
      name: postgres-airflow
  template:
    metadata:
      labels:
        name: postgres-airflow
    spec:
      restartPolicy: Always
      containers:
      - name: postgres
        image: postgres
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 5432
            protocol: TCP
        volumeMounts:
        - mountPath: "/var/lib/postgresql/data/pgdata"
          name: postgres-vol
          subPath: pgdata
        env:
        - name: POSTGRES_USER
          value: root
        - name: POSTGRES_PASSWORD
          value: root
        - name: POSTGRES_DB
          value: airflow
        - name: PGDATA
          value: /var/lib/postgresql/data/pgdata
        - name: POD_IP
          valueFrom: { fieldRef: { fieldPath: status.podIP } }
        livenessProbe:
          initialDelaySeconds: 60
          timeoutSeconds: 5
          failureThreshold: 5
          exec:
            command:
            - /bin/sh
            - -c
            - exec pg_isready --host $POD_IP ||  if [[ $(psql -qtAc --host $POD_IP 'SELECT pg_is_in_recovery') != "f" ]]; then  exit 0 else; exit 1; fi
        readinessProbe:
          initialDelaySeconds: 5
          timeoutSeconds: 5
          periodSeconds: 5
          exec:
            command:
            - /bin/sh
            - -c
            - exec pg_isready --host $POD_IP
        resources:
          requests:
            ephemeral-storage: 5Gi
            memory: .5Gi
            cpu: .5
      volumes:
      - name: postgres-db-volume
        emptyDir: {}
-- Arun
kubernetes
podspec
yaml

1 Answer

4/10/2020

In volumes you have postgres-db-volume but in volume mounts you have given postgres-vol which is not matching and leading to this error.

Docs on how to use azure file share for dynamic PV provisioning.

-- Arghya Sadhu
Source: StackOverflow