管理文件权限
JuiceFS 完全兼容 POSIX 接口,可以直接使用类 Unix 系统的 UID、GID 对文件权限进行管理。
部署
以动态配置为例,先创建 Secret:
apiVersion: v1
kind: Secret
metadata:
name: juicefs-secret
type: Opaque
stringData:
name: <NAME>
metaurl: redis://[:<PASSWORD>]@<HOST>:6379[/<DB>]
storage: s3
bucket: https://<BUCKET>.s3.<REGION>.amazonaws.com
access-key: <ACCESS_KEY>
secret-key: <SECRET_KEY>
创建 StorageClass 和 PersistentVolumeClaim(PVC):
kubectl apply -f - <<EOF
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: juicefs-sc
provisioner: csi.juicefs.com
parameters:
csi.storage.k8s.io/provisioner-secret-name: juicefs-secret
csi.storage.k8s.io/provisioner-secret-namespace: default
csi.storage.k8s.io/node-publish-secret-name: juicefs-secret
csi.storage.k8s.io/node-publish-secret-namespace: default
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: juicefs-pvc
namespace: default
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Pi
storageClassName: juicefs-sc
EOF
在 Pod 中设置权限
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: juicefs-app
spec:
template:
spec:
containers:
- name: owner
image: centos
command: ["/bin/sh"]
args: ["-c", "while true; do echo $(date -u) >> /data/out-$(POD).txt; sleep 5; done"]
env:
- name: POD
valueFrom:
fieldRef:
fieldPath: metadata.name
securityContext:
runAsUser: 1000
runAsGroup: 3000
resources:
limits:
cpu: "20m"
memory: "55M"
volumeMounts:
- name: data
mountPath: /data
- name: group
image: centos
command: ["/bin/sh"]
args: ["-c", "tail -f /data/out-$(POD).txt"]
env:
- name: POD
valueFrom:
fieldRef:
fieldPath: metadata.name
securityContext:
runAsUser: 2000
runAsGroup: 3000
resources:
limits:
cpu: "20m"
memory: "55M"
volumeMounts:
- name: data
mountPath: /data
- name: other
image: centos
command: ["/bin/sh"]
args: ["-c", "while true; do echo $(date -u) >> /data/out-$(POD).txt; sleep 5; done"]
env:
- name: POD
valueFrom:
fieldRef:
fieldPath: metadata.name
securityContext:
runAsUser: 3000
runAsGroup: 4000
resources:
limits:
cpu: "20m"
memory: "55M"
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: juicefs-pvc
EOF