How can I access several files / secrets using volumes and volumeMounts?

2/25/2021

I have several files stored as Kubernetes secrets. I can access one of them, but obviously I need them all. How do I access all of them? I tried this but they seem to be overwriting each other.

// In deployment
volumes:
- name: my-secret-volume
  secret:
    secretName: some-file.yaml
- name: my-secret-volume
  secret:
  	secretName: another-file.yaml
...
volumeMounts:
- name: my-secret-volume
  mountPath: /var/config
  readOnly: true
-- Martin01478
kubernetes
kubernetes-secrets

1 Answer

2/25/2021

Volumes names should be different. Also you should only give the secret name not the yaml. You can use like below:

volumes:
- name: my-secret-volume1
  secret:
    secretName: some-secret
- name: my-secret-volume2
  secret:
    secretName: another-secret
...
volumeMounts:
- name: my-secret-volume1
  mountPath: /var/config
  readOnly: true
- name: my-secret-volume2
  mountPath: /var/config
  readOnly: true
-- Sahadat Hossain
Source: StackOverflow