1

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"]

Raj kumar
  • 131
  • 1
  • 1
  • 10
  • Check the syntax, it seems like `yaml` is not valid. Here you can find a [working example](https://kubernetes.io/docs/concepts/storage/ephemeral-volumes/#generic-ephemeral-volumes). Or you may consider using [`emptyDir`](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir) as it was suggested in the answer. – moonkotte Dec 13 '21 at 10:11
  • I had the identical issue as OP. The yaml is from https://kubernetes.io/docs/concepts/storage/ephemeral-volumes/ and to me the yaml syntax seems error-free. Using emptyDir did the trick, but there should be a way to get `ephemeral` to work somehow. – Alexander Stumpf Jul 12 '22 at 16:52

1 Answers1

0

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/.

jankantert
  • 61
  • 5