A kube-api-access volume is a projected volume automatically added to almost every pod. It gives containers the files needed to access the Kubernetes API: a service-account token, the cluster CA certificate, and the pod's namespace. section 9.5.6
The volume combines three sources into one mounted directory:
- serviceAccountToken projects the API token as token. section 9.5.6
- The kube-root-ca.crt ConfigMap projects ca.crt. section 9.5.6
- The downward API projects metadata.namespace as namespace. section 9.5.6
Inspecting the generated volume
Run kubectl get pod <pod-name> -o yaml and inspect .spec.volumes. The generated entry has a projected type, a kube-api-access name, and sources for token, ca.crt, and namespace. section 9.5.6
Listing 9.16 The kube-api-access volume built into almost every pod
volumes:
- name: kube-api-access-gc7lf #1
projected: #1
defaultMode: 420
sources: #2
- serviceAccountToken: #3
expirationSeconds: 3607 #3
path: token #3
- configMap: #4
items: #4
- key: ca.crt #4
path: ca.crt #4
name: kube-root-ca.crt #4
- downwardAPI: #5
items: #5
- fieldRef: #5
apiVersion: v1 #5
fieldPath: metadata.namespace #5
path: namespace #5
The manifest shows how service-account, ConfigMap, and downward API sources create the built-in volume. section 9.5.6
Most pods do not need API access. Disable automatic mounting with spec.automountServiceAccountToken: false, or configure the same setting on the ServiceAccount, to follow least privilege. section 9.5.6
