Skip to content

Commit

Permalink
VolumeSubpathEnvExpansion alpha feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Taylor committed Jun 8, 2018
1 parent 7549d77 commit b32b33f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions content/en/docs/concepts/storage/volumes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,51 @@ spec:
claimName: my-lamp-site-data
```

### Using subPath with expanded environment variables

{{< feature-state for_k8s_version="v1.11" state="alpha" >}}



You can use expanded environment variables in a subPath value. `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 within `/logs/pod1/`, using
the pod name. That directory is mounted at `/logs/` within the container.

From the container's point of view, logs are stored in `/logs/`, so the command does not need to change, but in the volume, each Pod will get its own separate log directory.


```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
```

On the host, the logs are written to `/var/log/pods/pod1/hello.txt`

## Resources

The storage media (Disk, SSD, etc.) of an `emptyDir` volume is determined by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b32b33f

Please sign in to comment.