Skip to content

Commit b0149ad

Browse files
authored
Added examples on more volume types (#156)
2 parents f11d354 + 153615b commit b0149ad

File tree

9 files changed

+165
-21
lines changed

9 files changed

+165
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
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.
1+
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.
22

3-
You will find two examples:
4-
- `volume-emptydir` - in order to inject an `emptyDir` `volume` in a Workload for any request of a `volume` resource with the `class` `ephemeral`.
5-
- `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`.
3+
You will find these examples:
64

7-
You can find a Score file example using the `volume` resource type [here](https://developer.humanitec.com/examples/score/volumes/).
5+
- `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`
6+
- `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`
7+
- `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`
8+
- `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`
9+
- `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`
10+
11+
You can find a Score file example using the `volume` resource type [here](https://developer.humanitec.com/examples/score/volumes/).
12+
13+
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This Resource Definition uses the Template Driver to create a volume accessing a ConfigMap
2+
apiVersion: entity.humanitec.io/v1b1
3+
kind: Definition
4+
metadata:
5+
id: volume-configmap
6+
entity:
7+
name: volume-configmap
8+
type: volume
9+
driver_type: humanitec/template
10+
driver_inputs:
11+
values:
12+
templates:
13+
manifests:
14+
configmap.yaml:
15+
location: volumes
16+
data: |
17+
name: ${context.res.guresid}-configmap
18+
configMap:
19+
# The ConfigMap named here needs to exist. The Resource Definition does not create it
20+
name: log-config
21+
items:
22+
- key: log_level
23+
path: log_level.conf
24+
criteria:
25+
- class: config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Using the Template Driver for the dynamic provisioning of
2+
# a Kubernetes PersistentVolume and PersistentVolumeClaim combination,
3+
# then adding the volume into the Pod of the Workload.
4+
# The PVC requests a storageClass "standard-rwo".
5+
# The volumeMount in the container is defined in the "workload" type Resource Definition.
6+
apiVersion: entity.humanitec.io/v1b1
7+
kind: Definition
8+
metadata:
9+
id: volume-standard-dynamic
10+
entity:
11+
name: volume-standard-dynamic
12+
type: volume
13+
driver_type: humanitec/template
14+
driver_inputs:
15+
values:
16+
templates:
17+
init: |
18+
# Generate a unique id for each pv/pvc combination.
19+
# Every Workload will have a separate pv and pvc created for it,
20+
# but pointing to the same NFS server endpoint.
21+
volumeUid: {{ randNumeric 4 }}-{{ randNumeric 4 }}
22+
pvBaseName: pv-tmpl-
23+
pvcBaseName: pvc-tmpl-
24+
volBaseName: vol-tmpl-
25+
manifests:
26+
#########################################################################
27+
# This template creates the PersistentVolumeClaim in the target namespace
28+
#########################################################################
29+
app-pvc-tmpl.yaml:
30+
location: namespace
31+
data: |
32+
apiVersion: v1
33+
kind: PersistentVolumeClaim
34+
metadata:
35+
name: {{ .init.pvcBaseName }}{{ .init.volumeUid }}
36+
spec:
37+
accessModes:
38+
- ReadWriteOnce
39+
storageClassName: "standard-rwo"
40+
resources:
41+
requests:
42+
storage: 10Gi
43+
volumeName: {{ .init.pvBaseName }}{{ .init.volumeUid }}
44+
########################################################
45+
# This template creates the volume in the Workload's Pod
46+
########################################################
47+
app-vol-tmpl.yaml:
48+
location: volumes
49+
data: |
50+
name: {{ .init.volBaseName }}{{ .init.volumeUid }}
51+
persistentVolumeClaim:
52+
claimName: {{ .init.pvcBaseName }}{{ .init.volumeUid }}
53+
# Make the volume name and pvc name available for other Resources
54+
outputs: |
55+
volumeName: {{ .init.volBaseName }}{{ .init.volumeUid }}
56+
pvcName: {{ .init.pvcBaseName }}{{ .init.volumeUid }}
57+
criteria:
58+
- class: standard-rwo

resource-definitions/template-driver/volumes/volume-emptydir.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This Resource Definition uses the Template Driver to inject an emptyDir volume into the workload
12
apiVersion: entity.humanitec.io/v1b1
23
kind: Definition
34
metadata:

resource-definitions/template-driver/volumes/volume-nfs.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ entity:
5050
path: "/"
5151
mountOptions:
5252
- nfsvers=4.2
53-
5453
#########################################################################
5554
# This template creates the PersistentVolumeClaim in the target namespace
5655
#########################################################################
@@ -69,7 +68,6 @@ entity:
6968
requests:
7069
storage: 1Mi
7170
volumeName: {{ .init.pvBaseName }}{{ .init.volumeUid }}
72-
7371
########################################################
7472
# This template creates the volume in the Workload's Pod
7573
########################################################
@@ -79,7 +77,6 @@ entity:
7977
name: {{ .init.volBaseName }}{{ .init.volumeUid }}
8078
persistentVolumeClaim:
8179
claimName: {{ .init.pvcBaseName }}{{ .init.volumeUid }}
82-
8380
# Make the volume name and pvc name available for other Resources
8481
outputs: |
8582
volumeName: {{ .init.volBaseName }}{{ .init.volumeUid }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This Resource Definition uses the Template Driver to create a projected volume
2+
# accessing a ConfigMap and the downwardAPI
3+
apiVersion: entity.humanitec.io/v1b1
4+
kind: Definition
5+
metadata:
6+
id: volume-projected
7+
entity:
8+
name: volume-projected
9+
type: volume
10+
driver_type: humanitec/template
11+
driver_inputs:
12+
values:
13+
templates:
14+
manifests:
15+
projected.yaml:
16+
location: volumes
17+
data: |
18+
name: ${context.res.guresid}-projected
19+
projected:
20+
sources:
21+
- downwardAPI:
22+
items:
23+
- path: "labels"
24+
fieldRef:
25+
fieldPath: metadata.labels
26+
- configMap:
27+
# The ConfigMap named here needs to exist. The Resource Definition does not create it
28+
name: log-config
29+
items:
30+
- key: log_level
31+
path: log_level.conf
32+
criteria:
33+
- class: projected
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
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/).
2+
3+
You can find a Score file example using the `volume` resource type [here](https://developer.humanitec.com/examples/score/volumes/).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: entity.humanitec.io/v1b1
2+
kind: Definition
3+
metadata:
4+
id: volume-nfs
5+
entity:
6+
type: volume
7+
name: volume-nfs
8+
driver_type: humanitec/volume-nfs
9+
driver_inputs:
10+
values:
11+
path: "/"
12+
server: nfs-server.default.svc.cluster.local
13+
criteria:
14+
- class: nfs

score/volumes/score.yaml

+20-13
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,30 @@ containers:
55
my-container:
66
image: .
77
volumes:
8-
- source: ${resources.my-pvc}
9-
target: /target/dir
10-
- source: ${resources.my-ebs}
11-
target: /ebs-target/dir
128
- source: ${resources.my-ephemeral-volume}
13-
target: /tmp/dir
14-
- source: ${resources.my-nfs}
15-
target: /nfs-target/dir
9+
target: /tmp/ephemeral-dir
10+
- source: ${resources.my-config-volume}
11+
target: /var/config
12+
- source: ${resources.my-projected-volume}
13+
target: /var/all-in-one
14+
readOnly: true
15+
- source: ${resources.my-dynamic-provisioning-volume}
16+
target: /var/dynamic
17+
- source: ${resources.my-nfs-volume}
18+
target: /var/nfs
1619
resources:
17-
my-pvc:
18-
type: volume
19-
my-ebs:
20-
type: volume
21-
class: ebs
2220
my-ephemeral-volume:
2321
type: volume
2422
class: ephemeral
25-
my-nfs:
23+
my-config-volume:
24+
type: volume
25+
class: config
26+
my-projected-volume:
27+
type: volume
28+
class: projected
29+
my-dynamic-provisioning-volume:
30+
type: volume
31+
class: standard-rwo
32+
my-nfs-volume:
2633
type: volume
2734
class: nfs

0 commit comments

Comments
 (0)