kubernetes deployment.yaml - ephemeral storage error

854 Views Asked by At

I am trying to deploy a microservice in kubernetes with ephemeral storage. So the storage will be deleted at the end of the lifecycle of the pod.

I am getting errors with the below config in deployment.yaml:

deployment.yaml:

 volumeMounts:
    - name: storage-for-log-export
      mountPath: "/scratch"
  volumes:
    - name: storage-for-log-export
      ephemeral:
         volumeClaimTemplate:
              metadata:
                labels:
                  type: volume-for-log-export
              spec:
                accessModes: [ "ReadWriteOnce" ]
                storageClassName: "scratch-storage-class"
                resources:
                  requests:
                    storage: 1Gi

Error message : sync failed : Deployment.apps "csm" is invalid: [spec.template.spec.volumes[1]: Required value: must specify a volume type, spec.template.spec.containers[0].volumeMounts[0].name: Not found: "storage-for-log-export"]

1

There are 1 best solutions below

0
On

This feature is behind a feature gate. It might not be enabled in your cluster. According to the docs (https://kubernetes.io/docs/concepts/storage/ephemeral-volumes/#generic-ephemeral-volumes) it is stable in Kubernetes 1.23. It is enabled in Kubernetes 1.22 installed with kops by default. However, it does not work in Kubernetes 1.20 installed for instance. You can probably enable the feature gate in those version as well: https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/.