我正在研究 Springboot 和 Kubernetes,我有一个连接到 Postgres 数据库的非常简单的应用程序。我想从 configmap 和密码中获取数据源的值作为挂载文件。
配置映射文件:
apiVersion: v1
kind: ConfigMap
metadata:
name: customer-config
data:
application.properties: |
server.forward-headers-strategy=framework
spring.datasource.url=jdbc:postgresql://test/customer
spring.datasource.username=postgres
secret 文件:apiVersion: v1
kind: Secret
metadata:
name: secret-demo
data:
spring.datasource.password: cG9zdGdyZXM=
部署文件:spec:
containers:
- name: customerc
image: localhost:8080/customer
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8282
volumeMounts:
- mountPath: /workspace/config/default
name: config-volume
- mountPath: /workspace/secret/default
name: secret-volume
volumes:
- name: config-volume
configMap:
name: customer-config
- name: secret-volume
secret:
secretName: secret-demo
items:
- key: spring.datasource.password
path: password
如果我将 spring.datasource.password Prop 从 secret 移动到 configmap 那么它可以正常工作,或者如果我将其值填充为 env 变量,那么它也可以正常工作。但正如我们所知,这两者都不是安全的方法,有人可以告诉我为 secret 文件挂载有什么问题吗?
最佳答案
默认情况下,出于安全原因,不启用通过 API 使用 secret 。Spring Cloud Kubernetes 需要访问 Kubernetes API,以便能够检索为单个服务运行的 pod 的地址列表。使用 Minikube 时最简单的方法是使用集群管理员权限创建默认的 ClusterRoleBinding。
关于如何创建一个的示例:-
$ kubectl create clusterrolebinding admin --clusterrole=cluster-admin --serviceaccount=default:default
关于spring-boot - 如何从安装为文件的 kubernetes Secrets 中填充 application.properties 文件值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66444197/