diff --git a/resource-definitions/template-driver/volumes/README.md b/resource-definitions/template-driver/volumes/README.md index ed4df2b..4406716 100644 --- a/resource-definitions/template-driver/volumes/README.md +++ b/resource-definitions/template-driver/volumes/README.md @@ -1,7 +1,13 @@ -This section contains Resource Definition examples for handling Kubernetes [Volumes](https://kubernetes.io/docs/concepts/storage/volumes) by using the [`template`](https://developer.humanitec.com/integration-and-extensions/drivers/generic-drivers/template/) Driver to configure your own `PersistentVolume` implementation. You can [see this other example](https://developer.humanitec.com/examples/resource-definitions/volume-pvc/volumes/) if you want to use the `volume-pvc` Driver. +This section contains Resource Definition examples for handling Kubernetes [Volumes](https://kubernetes.io/docs/concepts/storage/volumes) by using the [`Template`](https://developer.humanitec.com/integration-and-extensions/drivers/generic-drivers/template/) Driver to configure your own volume implementation. -You will find two examples: -- `volume-emptydir` - in order to inject an `emptyDir` `volume` in a Workload for any request of a `volume` resource with the `class` `ephemeral`. -- `volume-nfs` - in order to create the associated `PersistentVolumeClaim`, `PersistentVolume` and `volume` in a Workload for any request of a `volume` resource with the `class` `nfs`. +You will find these examples: -You can find a Score file example using the `volume` resource type [here](https://developer.humanitec.com/examples/score/volumes/). \ No newline at end of file +- `volume-configmap`: injects a [`configMap` volume](https://kubernetes.io/docs/concepts/storage/volumes/#configmap) into a Workload for any request of a `volume` resource with the `class` `config` +- `volume-dynamic-provisioning`: [dynamic provisioning](https://kubernetes.io/docs/concepts/storage/dynamic-provisioning/) of a PersistentVolume. Creates the associated `PersistentVolumeClaim` object, and injects the `volume` into a Workload for any request of a `volume` resource with the `class` `standard-rwo` +- `volume-emptydir`: injects an [`emptyDir` volume](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir) into a Workload for any request of a `volume` resource with the `class` `ephemeral` +- `volume-nfs`: [static provisioning](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#static) of a PersistentVolume. Creates the associated `PersistentVolumeClaim` and `PersistentVolume` objects, and injects the `volume` into a Workload for any request of a `volume` resource with the `class` `nfs` +- `volume-projected`: injects a [`projected` volume](https://kubernetes.io/docs/concepts/storage/projected-volumes/) into a Workload for any request of a `volume` with the `class` `projected` + +You can find a Score file example using the `volume` resource type [here](https://developer.humanitec.com/examples/score/volumes/). + +To see examples for the convenience Drivers, see the [`volume-pvc` Driver](https://developer.humanitec.com/examples/resource-definitions/volume-pvc/volumes/) and [`volume-nfs` Driver](https://developer.humanitec.com/examples/resource-definitions/volume-nfs/volumes/) examples. \ No newline at end of file diff --git a/resource-definitions/template-driver/volumes/volume-configMap.yaml b/resource-definitions/template-driver/volumes/volume-configMap.yaml new file mode 100644 index 0000000..5374c77 --- /dev/null +++ b/resource-definitions/template-driver/volumes/volume-configMap.yaml @@ -0,0 +1,25 @@ +# This Resource Definition uses the Template Driver to create a volume accessing a ConfigMap +apiVersion: entity.humanitec.io/v1b1 +kind: Definition +metadata: + id: volume-configmap +entity: + name: volume-configmap + type: volume + driver_type: humanitec/template + driver_inputs: + values: + templates: + manifests: + configmap.yaml: + location: volumes + data: | + name: ${context.res.guresid}-configmap + configMap: + # The ConfigMap named here needs to exist. The Resource Definition does not create it + name: log-config + items: + - key: log_level + path: log_level.conf + criteria: + - class: config diff --git a/resource-definitions/template-driver/volumes/volume-dynamic-provisioning.yaml b/resource-definitions/template-driver/volumes/volume-dynamic-provisioning.yaml new file mode 100644 index 0000000..41bdc21 --- /dev/null +++ b/resource-definitions/template-driver/volumes/volume-dynamic-provisioning.yaml @@ -0,0 +1,58 @@ +# Using the Template Driver for the dynamic provisioning of +# a Kubernetes PersistentVolume and PersistentVolumeClaim combination, +# then adding the volume into the Pod of the Workload. +# The PVC requests a storageClass "standard-rwo". +# The volumeMount in the container is defined in the "workload" type Resource Definition. +apiVersion: entity.humanitec.io/v1b1 +kind: Definition +metadata: + id: volume-standard-dynamic +entity: + name: volume-standard-dynamic + type: volume + driver_type: humanitec/template + driver_inputs: + values: + templates: + init: | + # Generate a unique id for each pv/pvc combination. + # Every Workload will have a separate pv and pvc created for it, + # but pointing to the same NFS server endpoint. + volumeUid: {{ randNumeric 4 }}-{{ randNumeric 4 }} + pvBaseName: pv-tmpl- + pvcBaseName: pvc-tmpl- + volBaseName: vol-tmpl- + manifests: + ######################################################################### + # This template creates the PersistentVolumeClaim in the target namespace + ######################################################################### + app-pvc-tmpl.yaml: + location: namespace + data: | + apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: {{ .init.pvcBaseName }}{{ .init.volumeUid }} + spec: + accessModes: + - ReadWriteOnce + storageClassName: "standard-rwo" + resources: + requests: + storage: 10Gi + volumeName: {{ .init.pvBaseName }}{{ .init.volumeUid }} + ######################################################## + # This template creates the volume in the Workload's Pod + ######################################################## + app-vol-tmpl.yaml: + location: volumes + data: | + name: {{ .init.volBaseName }}{{ .init.volumeUid }} + persistentVolumeClaim: + claimName: {{ .init.pvcBaseName }}{{ .init.volumeUid }} + # Make the volume name and pvc name available for other Resources + outputs: | + volumeName: {{ .init.volBaseName }}{{ .init.volumeUid }} + pvcName: {{ .init.pvcBaseName }}{{ .init.volumeUid }} + criteria: + - class: standard-rwo \ No newline at end of file diff --git a/resource-definitions/template-driver/volumes/volume-emptydir.yaml b/resource-definitions/template-driver/volumes/volume-emptydir.yaml index 799f49d..f4e0052 100644 --- a/resource-definitions/template-driver/volumes/volume-emptydir.yaml +++ b/resource-definitions/template-driver/volumes/volume-emptydir.yaml @@ -1,3 +1,4 @@ +# This Resource Definition uses the Template Driver to inject an emptyDir volume into the workload apiVersion: entity.humanitec.io/v1b1 kind: Definition metadata: diff --git a/resource-definitions/template-driver/volumes/volume-nfs.yaml b/resource-definitions/template-driver/volumes/volume-nfs.yaml index a08b37a..49c7d56 100644 --- a/resource-definitions/template-driver/volumes/volume-nfs.yaml +++ b/resource-definitions/template-driver/volumes/volume-nfs.yaml @@ -50,7 +50,6 @@ entity: path: "/" mountOptions: - nfsvers=4.2 - ######################################################################### # This template creates the PersistentVolumeClaim in the target namespace ######################################################################### @@ -69,7 +68,6 @@ entity: requests: storage: 1Mi volumeName: {{ .init.pvBaseName }}{{ .init.volumeUid }} - ######################################################## # This template creates the volume in the Workload's Pod ######################################################## @@ -79,7 +77,6 @@ entity: name: {{ .init.volBaseName }}{{ .init.volumeUid }} persistentVolumeClaim: claimName: {{ .init.pvcBaseName }}{{ .init.volumeUid }} - # Make the volume name and pvc name available for other Resources outputs: | volumeName: {{ .init.volBaseName }}{{ .init.volumeUid }} diff --git a/resource-definitions/template-driver/volumes/volume-projected.yaml b/resource-definitions/template-driver/volumes/volume-projected.yaml new file mode 100644 index 0000000..fa3b879 --- /dev/null +++ b/resource-definitions/template-driver/volumes/volume-projected.yaml @@ -0,0 +1,33 @@ +# This Resource Definition uses the Template Driver to create a projected volume +# accessing a ConfigMap and the downwardAPI +apiVersion: entity.humanitec.io/v1b1 +kind: Definition +metadata: + id: volume-projected +entity: + name: volume-projected + type: volume + driver_type: humanitec/template + driver_inputs: + values: + templates: + manifests: + projected.yaml: + location: volumes + data: | + name: ${context.res.guresid}-projected + projected: + sources: + - downwardAPI: + items: + - path: "labels" + fieldRef: + fieldPath: metadata.labels + - configMap: + # The ConfigMap named here needs to exist. The Resource Definition does not create it + name: log-config + items: + - key: log_level + path: log_level.conf + criteria: + - class: projected diff --git a/resource-definitions/volume-nfs/volumes/README.md b/resource-definitions/volume-nfs/volumes/README.md new file mode 100644 index 0000000..479a2bc --- /dev/null +++ b/resource-definitions/volume-nfs/volumes/README.md @@ -0,0 +1,3 @@ +This section contains Resource Definitions examples for handling Kubernetes [Volumes](https://kubernetes.io/docs/concepts/storage/volumes) by using the [`volume-nfs`](https://developer.humanitec.com/integration-and-extensions/drivers/volume-driver/network-file-system/) Driver. If you have special requirements for your `PersistentVolume` implementation, you can [see this other example using the `template` Driver](https://developer.humanitec.com/examples/resource-definitions/template-driver/volumes/). + +You can find a Score file example using the `volume` resource type [here](https://developer.humanitec.com/examples/score/volumes/). \ No newline at end of file diff --git a/resource-definitions/volume-nfs/volumes/volume-nfs.yaml b/resource-definitions/volume-nfs/volumes/volume-nfs.yaml new file mode 100644 index 0000000..27a0f7a --- /dev/null +++ b/resource-definitions/volume-nfs/volumes/volume-nfs.yaml @@ -0,0 +1,14 @@ +apiVersion: entity.humanitec.io/v1b1 +kind: Definition +metadata: + id: volume-nfs +entity: + type: volume + name: volume-nfs + driver_type: humanitec/volume-nfs + driver_inputs: + values: + path: "/" + server: nfs-server.default.svc.cluster.local + criteria: + - class: nfs \ No newline at end of file diff --git a/score/volumes/score.yaml b/score/volumes/score.yaml index 316798c..f79d741 100644 --- a/score/volumes/score.yaml +++ b/score/volumes/score.yaml @@ -5,23 +5,30 @@ containers: my-container: image: . volumes: - - source: ${resources.my-pvc} - target: /target/dir - - source: ${resources.my-ebs} - target: /ebs-target/dir - source: ${resources.my-ephemeral-volume} - target: /tmp/dir - - source: ${resources.my-nfs} - target: /nfs-target/dir + target: /tmp/ephemeral-dir + - source: ${resources.my-config-volume} + target: /var/config + - source: ${resources.my-projected-volume} + target: /var/all-in-one + readOnly: true + - source: ${resources.my-dynamic-provisioning-volume} + target: /var/dynamic + - source: ${resources.my-nfs-volume} + target: /var/nfs resources: - my-pvc: - type: volume - my-ebs: - type: volume - class: ebs my-ephemeral-volume: type: volume class: ephemeral - my-nfs: + my-config-volume: + type: volume + class: config + my-projected-volume: + type: volume + class: projected + my-dynamic-provisioning-volume: + type: volume + class: standard-rwo + my-nfs-volume: type: volume class: nfs \ No newline at end of file