From d234510a81765b8d273be7c8633c782e25891f04 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Thu, 31 May 2018 09:58:18 +0100 Subject: [PATCH] VolumeSubpathEnvExpansion alpha feature --- content/en/docs/concepts/storage/volumes.md | 37 +++++++++++++++++++ .../feature-gates.md | 1 + 2 files changed, 38 insertions(+) diff --git a/content/en/docs/concepts/storage/volumes.md b/content/en/docs/concepts/storage/volumes.md index 3011e897416c7..a44fc5ae704ec 100644 --- a/content/en/docs/concepts/storage/volumes.md +++ b/content/en/docs/concepts/storage/volumes.md @@ -1017,6 +1017,43 @@ spec: claimName: my-lamp-site-data ``` +### Using subPath with expanded environment variables + +{{< feature-state for_k8s_version="v1.11" state="alpha" >}} + + +`subPath` directory names can also be constructed from Downward API environment variables. +Before you use this feature, you must enable the `VolumeSubpathEnvExpansion`feature gate. + +In this example, a Pod uses `subPath` to create a directory `pod1` within the hostPath volume `/var/log/pods`, using the pod name from the Downward API. The host directory `/var/log/pods/pod1` is mounted at `/logs` in the container. + +```yaml +apiVersion: v1 +kind: Pod +metadata: + name: pod1 +spec: + containers: + - name: container1 + env: + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + image: busybox + command: [ "sh", "-c", "while [ true ]; do echo 'Hello'; sleep 10; done | tee -a /logs/hello.txt" ] + volumeMounts: + - name: workdir1 + mountPath: /logs + subPath: $(POD_NAME) + restartPolicy: Never + volumes: + - name: workdir1 + hostPath: + path: /var/log/pods +``` + ## Resources The storage media (Disk, SSD, etc.) of an `emptyDir` volume is determined by the diff --git a/content/en/docs/reference/command-line-tools-reference/feature-gates.md b/content/en/docs/reference/command-line-tools-reference/feature-gates.md index 43b22d1e4c8f6..9ffde371e3111 100644 --- a/content/en/docs/reference/command-line-tools-reference/feature-gates.md +++ b/content/en/docs/reference/command-line-tools-reference/feature-gates.md @@ -93,6 +93,7 @@ different Kubernetes components. | `TokenRequest` | `false` | Alpha | 1.10 | | | `VolumeScheduling` | `false` | Alpha | 1.9 | 1.9 | | `VolumeScheduling` | `true` | Beta | 1.10 | | +| `VolumeSubpathEnvExpansion` | `false` | Alpha | 1.11 | | ## Using a Feature