Projected Volumes非常适用于以下场景:
以下是一些使用Projected Volumes的示例:
组合Secret、downwardAPI和ConfigMap:在这个示例中,Pod使用Projected Volume将一个secret、downwardAPI数据和一个configMap组合到一个单一的卷中。每个数据源在卷配置的sources
下指定。每个源的数据可以放置在卷内的自定义路径中。
apiVersion: v1
kind: Pod
metadata:
name: volume-test
spec:
containers:
- name: container-test
image: busybox
command: ["sleep", "3600"]
volumeMounts:
- name: all-in-one
mountPath: "/projected-volume"
readOnly: true
volumes:
- name: all-in-one
projected:
sources:
- secret:
name: mysecret
items:
- key: username
path: my-group/my-username
- downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- configMap:
name: myconfigmap
items:
- key: config
path: my-group/my-config
服务账户令牌投影:这个示例展示了一个Pod,它有一个包含服务账户令牌的Projected Volume。该令牌用于认证Kubernetes API。
apiVersion: v1
kind: Pod
metadata:
name: sa-token-test
spec:
containers:
- name: container-test
image: busybox
command: ["sleep", "3600"]
volumeMounts:
- name: token-vol
mountPath: "/service-account"
readOnly: true
serviceAccountName: default
volumes:
- name: token-vol
projected:
sources:
- serviceAccountToken:
audience: api
expirationSeconds: 3600
path: token
这些示例说明了Kubernetes中Projected Volumes的灵活性,允许您在Pod内有效地组合和管理多个数据源。