微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何连接我的 Spring Boot Pod 以从 Kubernetes World 中的 Spring Cloud Config Server 获取配置

如何解决如何连接我的 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

我做错了什么?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。