【发布时间】:2023-01-05 08:06:44
【问题描述】:
不工作场景:
我正在尝试在 EKS 集群中部署 spring-boot 应用程序。
spring-config-server 帮助加载我的应用程序存储库中的(项目)属性
- 应用程序-dev.yml(来自存储库)
spring:
config:
import: optional:configtree:/usr/src/apps/secrets/database/postgresql/ # not effective while loading into application by configserver
datasource:
url: jdbc:postgresql://{xxxxxxxxxxxxxx}:{5444}/postgres
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
hikari:
schema: mydbschema
spring-config-server 已启动并运行! 当我尝试在 EKS 中使用 deployment.yaml 文件部署我的应用程序时,configtree:/usr/src/apps/secrets/database/postgresql/ 属性没有显示任何效果以设置 env 道具。
- 部署.yaml
volumes:
- name: tmpfs-1
emptyDir: {}
- name: secret-volume-postgresql
secret:
secretName: db_secrets
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- "--server.port=8080"
- {{ default "dev" .Values.applicationActiveProfiles }}
env:
- name: ACTIVE_PROFILES
value: {{ .Values.applicationActiveProfiles }}
- name: DB_USERNAME
value: {{ .Values.db.userName }}
- name: NAME_SPACE
value: {{ default "dev" .Values.selectedNamespace }}
ports:
- name: http
containerPort: {{ .Values.containerPort }}
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /actuator/health/readiness
port: http
scheme: HTTP
initialDelaySeconds: 15
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
livenessProbe:
failureThreshold: 3
httpGet:
path: /actuator/health/liveness
port: http
scheme: HTTP
initialDelaySeconds: 15
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
volumeMounts:
- name: secret-volume-postgresql
mountPath: /usr/src/apps/secrets/database/postgresql
- name: tmpfs-1
mountPath: /tmp
-
我的应用程序(项目)
- 应用.yml
---
spring:
application:
name: myapplication
config:
import: optional:configserver:http://config-server.dev.svc:8080/
cloud:
config:
label: develop
profiles:
active:
- dev
工作场景:
在 deployment.yaml 文件中进行一项额外更改,将 spring.config.import 设置为 arg。
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- "--server.port=8080"
- {{ default "dev" .Values.applicationActiveProfiles }}
# ******It's working after adding the below line******
- "--spring.config.import=optional:configtree:/usr/src/apps/secrets/database/postgresql/"
题:为什么它不考虑我设置的属性myapplication-dev.yml文件 ?这里缺少什么?
【问题讨论】:
标签: spring-boot kubernetes spring-cloud-config-server