【问题标题】:Configure spring cloud config uri in a kubernetes cluster在 kubernetes 集群中配置 spring cloud config uri
【发布时间】:2021-09-17 17:11:31
【问题描述】:

我正在部署我的配置服务器和使用它来初始化属性的应用程序。 我现在遇到的以下问题是指定config-server所在位置的URI。

以前很简单:

spring.config.import=optional:configserver:https://localhost:8888/

现在在集群中我尝试这样指定它

spring.config.import=optional:configserver:centralconfig-service:8888/

这是配置服务器的服务名称(部署名称是'centralconfig')。 每当我尝试此 URL 时,我都会收到 Invalid Url 异常。

Invalid URL: centralconfig-service:8888/

我已经建立了一个内部网络,因此他们应该能够相互通信。

有人知道如何在 kubernetes 环境中指定正确的 URI 吗?

centralconfig-deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: central-config
  labels:
    app: central-config
spec: 
  replicas: 1
  selector: 
    matchLabels: 
      app: central-config
  strategy: {}
  template:
    metadata:
      labels:
        app: central-config  
    spec: 
      containers: 
        - name: central-config
          image: "central-config:latest"
          imagePullPolicy: IfNotPresent
          ports: 
            - containerPort: 8888
          resources: {}
      restartPolicy: Always
      serviceAccountName: ""
      volumes: null
status: {}    
       

centralconfig.service.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: central-config
  labels:
    app: central-config
spec: 
  replicas: 1
  selector: 
    matchLabels: 
      app: central-config
  strategy: {}
  template:
    metadata:
      labels:
        app: central-config  
    spec: 
      containers: 
        - name: central-config
          image: "central-config:latest"
          imagePullPolicy: IfNotPresent
          ports: 
            - containerPort: 8888
          resources: {}
      restartPolicy: Always
      serviceAccountName: ""
      volumes: null
status: {}    

端点:

提前致谢

【问题讨论】:

  • 您的“已设置内部网络”是什么意思您是否使用服务公开了您的 centralconfig?如果可以,你能告诉我们服务定义和 kubectl get endpoints 的输出吗?
  • 请显示您的服务和部署的 YAML。
  • 提供了 yaml 文件
  • 服务和部署yaml是一样的,复制粘贴错误还是忘记创建服务?请参阅下面的答案以获取可能的解决方案,顺便说一句

标签: spring-boot kubernetes minikube spring-cloud-config


【解决方案1】:

我怀疑缺少“http://”或“https://”前缀是问题的实际原因。

所以试试这个:

spring.config.import=optional:configserver:https://centralconfig-service:8888/

【讨论】:

    猜你喜欢
    • 2019-03-20
    • 2019-11-02
    • 1970-01-01
    • 2018-05-30
    • 2022-12-04
    • 2017-06-23
    • 2016-08-23
    • 1970-01-01
    • 2016-07-06
    相关资源
    最近更新 更多