如何解决从 Spring mvc 应用程序中读取挂载卷的秘密值
我们在 AKS 中使用 tomcat 映像部署了一个 spring MVC 应用程序。 如何从作为卷安装的 Secrets 中获取值?
大多数示例仅指向 spring boot
我正在安装来自秘密商店的价值
kind: Pod
apiVersion: v1
metadata:
name: nginx
namespace: default
labels:
aadpodidbinding: pod-mi
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: foo
mountPath: "/mnt/secrets"
readOnly: true
volumes:
- name: foo
csi:
driver: secrets-store.csi.k8s.io
readOnly: true
volumeAttributes:
secretProviderClass: spc.
可以看到秘密被正确挂载:
kubectl -n default exec -it nginx -- bash
root@nginx:/# ls /mnt/secrets
service-one-secret
service-two-secret
Cat service-one-secret 不返回任何内容
有人可以建议一种从 spring mvc 应用程序读取其值的方法吗?
解决方法
当您将机密作为卷安装到容器时,它将显示该路径中的机密数据。例如,您使用以下命令创建机密:
kubectl create secret generic basic-secret \
--from-literal=username="jsmith" \
--from-literal=password="mysupersecurepassword"
然后您将密钥挂载为卷:
...
spec:
volumes:
- name: vol-secret
secret:
secretName: my-secret
containers:
...
volumeMounts:
- name: vol-secret
mountPath: /etc/app/secrets
然后可以在路径username
中看到名为password
和/etc/app/secrets
的文件,其值如下所示:
/ # ls /etc/app/secrets
password user
/ # cat /etc/app/secrets/password
mysupersecurepassword
/ # cat /etc/app/secrets/username
jsmith
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。