azure - 从 Spring mvc 应用程序的已安装卷中读取秘密值
问题描述
我们在 AKS 中使用 tomcat 映像部署了一个 Spring MVC 应用程序。如何从安装为卷的秘密中获取值?
大多数示例仅指向 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
然后就可以看到path 中名为username
and的文件了,其值如下所示:password
/etc/app/secrets
/ # ls /etc/app/secrets
password user
/ # cat /etc/app/secrets/password
mysupersecurepassword
/ # cat /etc/app/secrets/username
jsmith
推荐阅读
- asynchronous - Async.StartChild 在子异步内部具有超时和同步等待
- node.js - React - PUBLIC_URL 设置后仍未定义
- css - 使用方向时媒体查询无法按预期工作
- javascript - 在 SVG 中嵌入工具提示的问题
- python - 我在使用 KPrototyping 聚类算法聚类分类和数值数据时遇到错误
- java - 将字符串拆分为第 n 个分隔符
- c - 从 MATLAB 命令 Maxon Motors EPOS2 电机控制器
- javascript - 我想根据我的过滤器更新面包屑
- javascript - 如何在带有 React Navigation 的 React Native 中以编程方式在 Android 上隐藏标签栏?
- azure-webjobs - ApplicationInsights customMetrics 数据不适用于 WebJob