Set Permissions on an emptyDir Volume
Kubernetes Docs · نسخهٔ f284a9e7c87f · CC BY 4.0 برای مستندات و مجوزهای همراه
<!-- overview -->
{{< feature-state feature_gate_name="EmptyDirVolumeMode" >}}
This page shows how to set Unix permission bits on an emptyDir volume directory using the mode field.
{{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
You need to have the EmptyDirVolumeMode feature gate enabled on the API server and the kubelet.
<!-- steps -->
Create a Pod that uses an emptyDir volume with custom permissions {#create-pod}
The emptyDir.mode field lets you set Unix permission bits (from 0000 to 01777 in octal) on the volume directory. If not specified, the directory is created with the default 0777 permissions.
For example, to create a shared /tmp directory with the sticky bit set so that only file owners can delete their own files:
{{% code_sample file="pods/emptydir-volume-mode.yaml" %}}
- Create the pod on your cluster:
kubectl apply -f https://k8s.io/examples/pods/emptydir-volume-mode.yaml- Verify the pod is running:
kubectl get pod emptydir-mode-demo- Check the permissions on the mounted volume:
kubectl exec emptydir-mode-demo -- ls -ld /tmpThe output is similar to:
drwxrwxrwt 2 root root 4096 Jul 28 00:00 /tmpThe t at the end confirms the sticky bit is set.
- Delete the Pod that you created for this exercise:
kubectl delete pod emptydir-mode-demo{{% heading "whatsnext" %}}
- Learn more about [
emptyDirvolumes](/docs/reference/storage/volume-types/#emptydir)