java - 如何连接我的 Spring Boot pod 以从 Kubernetes World 中的 Spring Cloud Config Server 获取配置
问题描述
顾名思义,我想让我的 Spring Boot pod 从 Spring Cloud Config Server pod 获取配置属性,所有这些都在 Kubernetes 的帮助下,但我被困在两件事上,我不知道该怎么做,我认为这与使用 Kubernetes Networking 错误有关:
我的第一个应用程序尝试从 Spring Cloud Config Server 获取属性:
spring.application.name=服务器
spring.cloud.config.uri= http://${CONFIG:localhost:3000}
我的 CONFIG 属性在我的部署清单中用作环境。多变的:
apiVersion: v1
kind: Service
metadata:
name: fotbalist-service
spec:
selector:
app: fotbalist
ports:
- protocol: 'TCP'
port: 2000
targetPort: 2000
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: fotbalist
spec:
replicas: 1
selector:
matchLabels:
app: fotbalist
template:
metadata:
labels:
app: fotbalist
spec:
containers:
- name: fotbalist-container
image: cinevacineva/fotbalist
imagePullPolicy: Always
ports:
- containerPort: 2000
env:
- name: CONFIG
valueFrom:
configMapKeyRef:
name: config-map
key: host
和我的 Spring Cloud Config Server 的 ConfigMap:
#Config ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: config-map
data:
host: CONFIG_SERVICE_HOST
当我尝试以这种方式使用它时得到下一个输出,并且没有连接到获取属性:
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://CONFIG_SERVICE_HOST
c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url -http://CONFIG_SERVICE_HOST. Will be trying the next url if available
我的另一个应用程序尝试不同的方法,连接到 Config 的 app.properties 是相同的,但使用的 ENV 不同:
env:
- name: CONFIG
value: CONFIG_SERVICE_HOST
输出:
c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: Invalid URL: http://CONFIG_SERVICE_HOST:tcp://10.101.163.39:3000
c.p.again.InfoEurekaServerApplication : No active profile set, falling back to default profiles: default
我的 Spring Cloud Config 应用程序清单/服务:
#service Config
apiVersion: v1
kind: Service
metadata:
name: config #DNS NAME
labels:
app: config
spec:
selector:
app: config
ports:
- protocol: 'TCP'
port: 3000
targetPort: 3000
type: ClusterIP
---
#Deployment Config
apiVersion: apps/v1
kind: Deployment
metadata:
name: config
spec:
selector:
matchLabels:
app: config
replicas: 1
template:
metadata:
labels:
app: config
spec:
containers:
- image: cinevacineva/config
name: config
imagePullPolicy: Always
ports:
- containerPort: 3000
name: config
我做错了什么?
解决方案
推荐阅读
- api - 如何使用按需付费模式基于 api 调用向用户收费
- javascript - 为什么在使用 passport.js 进行身份验证时,我收到 TypeError:无法读取未定义的属性“0”?
- node.js - 尝试运行“npm run serve:dev”时出现“错误:请手动安装 pg 包”?
- asp.net - 将其他文本框应用于文件上传
- python - 合并字符串检查器
- reactjs - 使用反应钩子操作数组
- c - 链接静态库与动态库的问题
- rust - 一揽子 impl、HRTB 和“impl”抽象返回类型:“预期绑定生命周期参数”
- android - 如何修复与十字路口地理编码反向地址相关的错误?
- javascript - 如何从当前 URL 获取路由名称