Skip to content

Added examples on more volume types #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions resource-definitions/template-driver/volumes/README.md
Original file line number Diff line number Diff line change
@@ -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/).
- `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.
25 changes: 25 additions & 0 deletions resource-definitions/template-driver/volumes/volume-configMap.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 0 additions & 3 deletions resource-definitions/template-driver/volumes/volume-nfs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ entity:
path: "/"
mountOptions:
- nfsvers=4.2

#########################################################################
# This template creates the PersistentVolumeClaim in the target namespace
#########################################################################
Expand All @@ -69,7 +68,6 @@ entity:
requests:
storage: 1Mi
volumeName: {{ .init.pvBaseName }}{{ .init.volumeUid }}

########################################################
# This template creates the volume in the Workload's Pod
########################################################
Expand All @@ -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 }}
Expand Down
33 changes: 33 additions & 0 deletions resource-definitions/template-driver/volumes/volume-projected.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions resource-definitions/volume-nfs/volumes/README.md
Original file line number Diff line number Diff line change
@@ -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/).
14 changes: 14 additions & 0 deletions resource-definitions/volume-nfs/volumes/volume-nfs.yaml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 20 additions & 13 deletions score/volumes/score.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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