标签: spring-cloud-kubernetes

在本地禁用 Spring Cloud Kubernetes

关于如何在本地模式下禁用 Spring Cloud Kubernetes 的小问题。

该项目是一个部署在 Kubernetes 中的简单 SpringBoot + SpringCloud 项目。因此,类路径中存在这种依赖关系:

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-kubernetes-fabric8</artifactId>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

当我们在 Kubernetes 环境中部署应用程序时,一切都很好。然而,在本地模式下运行的同一个应用程序将产生此警告,但最重要的是,启动时间增加了 20 秒。

o.s.c.k.f.Fabric8AutoConfiguration       : No namespace has been detected. Please specify KUBERNETES_NAMESPACE env var, or use a later kubernetes version (1.3 or later)
Run Code Online (Sandbox Code Playgroud)

在本地,虽然完全消除了依赖关系,但一切都“恢复正常”。该消息消失,启动时间又缩短。

但是,根据本地环境注释和取消注释依赖项可能不是最好的解决方案。

是否有一个可以在本地配置的完全禁用 Spring Cloud Kubernetes 的属性?

谢谢

java spring kubernetes spring-cloud-kubernetes

7
推荐指数
2
解决办法
1万
查看次数

如何设置 Spring Cloud Gateway 应用程序以便它可以使用 Spring Cloud Kubernetes 的服务发现?

我创建了两个 Spring Boot 应用程序,它们都将部署在 Kubernetes 集群中。其中一个应用程序将充当网关,因此使用 Spring Cloud Gateway 作为依赖项。另外我想将服务发现与 Spring Cloud Kubernetes 集成,网关使用服务发现来自动生成相应的路由。但是,当我公开在本地 Minikube 集群中运行的网关应用程序并调用第二个应用程序/服务时,我收到 503 错误并显示以下消息:Unable to find instance for ...-service

目前我已经安装了以下内容:

  • Minikube
  • 虚拟盒子
  • Docker 工具箱

我创建了一个包含两个子项目(网关和另一个服务)的 Gradle 项目。所有项目都将在本地构建/部署。默认服务帐户具有读取 Kubernetes API 的权限。部署这些服务后,我向外部公开网关服务。在网关服务中,我实现了一些端点,其中

  1. 通过 DiscoveryClient 提供集群中所有服务的列表。
  2. 应用层根据 DiscoveryClient 提供的 URI 调用其他服务。

一切似乎都有效,但是当我使用其他服务调用时URI/serviceId,出现 503 错误...

使用以下 Spring Cloud 版本: spring-cloud-starter-kubernetes 1.0.1.RELEASE spring-cloud-starter-gateway 2.1.1.RELEASE

我的演示应用程序可从https://github.com/nmaoez/spring-cloud-gateway-kubernetes 获得,README.md 提供了在本地 Minikube 集群中部署这两种服务的步骤。还显示了所有可用的端点。但有趣的部分是 application.yaml 和网关的应用程序类。

应用程序.yaml:

spring:
  application:
    name: gateway-service
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          lower-case-service-id: true
management:
  endpoints: …
Run Code Online (Sandbox Code Playgroud)

service-discovery spring-boot spring-cloud spring-cloud-gateway spring-cloud-kubernetes

6
推荐指数
1
解决办法
4185
查看次数

Spring Cloud 负载均衡器和 Ribbon 有什么区别?

我们的团队正计划从

  1. Spring Cloud Netflix Ribbon 到 Spring Cloud LoadBalancer 并使用 spring-cloud-kubernetes 作为发现客户端。
  2. 使用 Spring Cloud Gateway 代替 Zuul
  3. 和 Resilience4j 而不是 Hystrix。

需要进行哪些必要的更改,我们是否需要更改等效的属性。你能帮我们从哪里开始吗?

java spring-cloud spring-cloud-kubernetes

5
推荐指数
1
解决办法
360
查看次数

Spring Cloud Kubernetes ConfigMap 重新加载不起作用

我在 Minikube 中玩 Kubernetes。我能够将 Spring Boot 示例应用程序部署到 Kubernetes 中。

\n\n

我正在探索 Kubernetes configMap。我可以使用 Spring Cloud Starter 成功运行 Spring Boot 应用程序,并从配置映射中选择属性键。到这里我就成功了。

\n\n

我当前面临的问题是 configmap 重新加载。

\n\n

这是我的配置图:

\n\n

配置映射.yaml

\n\n
 apiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: minikube-sample\n  namespace: default\ndata:\n  app.data.name: name\n  application.yml: |-\n    app:\n      data:\n        test: test\n
Run Code Online (Sandbox Code Playgroud)\n\n

bootstrap.yaml

\n\n
management:\n    endpoint:\n        health:\n            enabled: true\n        info:\n            enabled: true\n        restart:\n            enabled: true\nspring:\n    application:\n        name: minikube-sample\n    cloud:\n        kubernetes:\n            config:\n                enabled: true\n                name: ${spring.application.name}\n                namespace: default\n            reload:\n                enabled: true\n
Run Code Online (Sandbox Code Playgroud)\n\n

家庭控制器:

\n\n
package com.minikube.sample.rest.controller;\n\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport com.minikube.sample.properties.PropertiesConfig;\nimport …
Run Code Online (Sandbox Code Playgroud)

spring-boot kubernetes minikube configmap spring-cloud-kubernetes

5
推荐指数
1
解决办法
5469
查看次数

Spring Cloud Kubernetes 应用程序无法检测到它何时在 Pod 中运行

预期行为

根据 Spring Cloud Kubernetes 文档,Spring 应用程序检测其何时在 Pod 中运行所需要做的就是将 Spring Cloud Kubernetes 及其spring-cloud-kubernetes-all依赖项添加到类路径中。

这会触发两个事件:

  1. 如果存在,则application-kubernetes.yml加载配置文件。
  2. Kubernetes 实现DiscoveryClient用于服务发现,利用 KubeDNS 而不是默认的 Eureka。

这种环境意识在这里描述: https://cloud.spring.io/spring-cloud-static/spring-cloud-kubernetes/1.1.0.RELEASE/reference/html/#kubernetes-profile-autoconfiguration

和这里:

https://cloud.spring.io/spring-cloud-static/spring-cloud-kubernetes/1.1.0.RELEASE/reference/html/#discoveryclient-for-kubernetes

实际行为

使用以下 yaml 启动 Spring Cloud Kubernetes 应用程序并http://minikube-ip:port/actuator/env通过 NodePort 访问其执行器端点后,我发现没有活动配置文件集,即使文件夹application-kubernetes.yml中存在resources

{
"activeProfiles": [],
...
Run Code Online (Sandbox Code Playgroud)

经过对http://minikube-ip:port/actuator/info端点的进一步调查,我发现 Spring 应用程序根本不知道它位于 pod 中,如下所示:

{
    "kubernetes": {
        "inside": false
    }
}
Run Code Online (Sandbox Code Playgroud)

我的代码

SpringCloud网关

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableDiscoveryClient …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot spring-cloud spring-cloud-kubernetes

5
推荐指数
1
解决办法
9312
查看次数

Spring Cloud Kubernetes-启用配置重新加载后,Spring Boot无法启动

我有这个演示项目,该项目打印从配置读取的标签。

这是我的主要课程:

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class DemoApplication {

    private MyConfig config;
    private DiscoveryClient discoveryClient;

    @Autowired
    public DemoApplication(MyConfig config, DiscoveryClient discoveryClient) {
        this.config = config;
        this.discoveryClient = discoveryClient;
    }

    @RequestMapping("/")
    public String info() {
        return config.getMessage();
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @RequestMapping("/services")
    public String services() {
        StringBuilder b = new StringBuilder();
        discoveryClient.getServices().forEach((s) -> b.append(s).append(" , "));
        return b.toString();
    }

}
Run Code Online (Sandbox Code Playgroud)

MyConfig类是:

@Configuration
@ConfigurationProperties(prefix = "bean")
public class MyConfig {

    private String message = …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot kubernetes spring-boot-actuator spring-cloud-kubernetes

4
推荐指数
1
解决办法
1124
查看次数

Spring Cloud Kubernetes:什么是集群读取器权限?

根据Spring Cloud Kubernetes文档,为了在启用 RBAC 的 Kubernetes 发行版中发现服务/pod:

您需要确保使用 spring-cloud-kubernetes 运行的 pod 可以访问 Kubernetes API。对于您分配给部署/pod 的任何服务帐户,您需要确保它具有正确的角色。例如,您可以cluster-reader根据您所在的项目为您的默认服务帐户添加权限。

什么是cluster-reader发现服务/pod 的权限?

我收到的错误是:

io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: GET at: https://x.x.x.x/api/v1/namespaces/jx-staging/services. 
Message: Forbidden!Configured service account doesn't have access. 
Service account may have been revoked. services is forbidden: 
User "system:serviceaccount:jx-staging:default" cannot list services in the namespace "jx-staging"
Run Code Online (Sandbox Code Playgroud)

kubernetes spring-cloud spring-cloud-kubernetes

4
推荐指数
2
解决办法
1640
查看次数

Spring Cloud Kubernetes:等待通知者缓存准备就绪超时

我试图在基于 Spring Boot 的微服务中利用 Spring Cloud Kubernetes,即自动配置和服务发现。

但是,我在初始化期间收到一条错误消息(Timeout waiting for informers cache to be read to be read, is the kubernetes service up?),而且冗长,这两种情况我都无法在网上找到信息来帮助我查明原因。下面详细介绍了错误消息和过多的日志消息。对于缺乏上下文表示歉意,但我也很困惑!

该应用程序在服务帐户中运行,该帐户具有文档default中指定的所有权限:

$ kubectl describe serviceaccount default
Name:                default
Namespace:           joaomlneto
Labels:              <none>
Annotations:         <none>
Image pull secrets:  devspace-auth-rg-nl-ams-scw-cloud
Mountable secrets:   default-token-2sxvc
Tokens:              default-token-2sxvc
Events:              <none>

$ kubectl describe rolebinding namespace-reader-binding
Name:         namespace-reader-binding
Labels:       <none>
Annotations:  <none>
Role:
  Kind:  Role
  Name:  namespace-reader
Subjects:
  Kind            Name     Namespace
  ----            ----     ---------
  ServiceAccount  default  joaomlneto

$ …
Run Code Online (Sandbox Code Playgroud)

spring-boot kubernetes spring-cloud spring-cloud-kubernetes devspace

4
推荐指数
1
解决办法
4981
查看次数

Spring Cloud Kubernetes-Spring Boot不读取配置映射

我有一个Spring Boot Web应用程序,它简单地打印在Kubernetes的ConfigMap中传递的属性。

这是我的主要课程:

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class DemoApplication {

    private MyConfig config;
    private DiscoveryClient discoveryClient;

    @Autowired
    public DemoApplication(MyConfig config, DiscoveryClient discoveryClient) {
        this.config = config;
        this.discoveryClient = discoveryClient;
    }

    @RequestMapping("/")
    public String info() {
        return config.getMessage();
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @RequestMapping("/services")
    public String services() {
        StringBuilder b = new StringBuilder();
        discoveryClient.getServices().forEach((s) -> b.append(s).append(" , "));
        return b.toString();
    }

}
Run Code Online (Sandbox Code Playgroud)

MyConfig类是:

@Configuration
@ConfigurationProperties(prefix = "bean")
public class MyConfig {

    private String …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot kubernetes configmap spring-cloud-kubernetes

3
推荐指数
1
解决办法
871
查看次数

Spring Cloud Kubernetes + Spring Cloud Gateway:无法找到 k8s 服务的实例

我正在使用 Spring Cloud Kubernetes + Spring Cloud Gateway(SCG),但在 GKE 上部署我的应用程序时遇到了一些麻烦。SCG 没有找到 k8s 服务,我仍然收到这个错误:

There was an unexpected error (type=Service Unavailable, status=503).
Unable to find instance for uiservice
Run Code Online (Sandbox Code Playgroud)

uiservice 是 Angular 应用程序。

当我看一看时,.../actuator/gateway/routes我得到了这个结果:

[
  {
    "route_id": "CompositeDiscoveryClient_gateway",
    "route_definition": {
      "id": "CompositeDiscoveryClient_gateway",
      "predicates": [
        {
          "name": "Path",
          "args": {
            "pattern": "/gateway/**"
          }
        }
      ],
      "filters": [
        {
          "name": "RewritePath",
          "args": {
            "regexp": "/gateway/(?<remaining>.*)",
            "replacement": "/${remaining}"
          }
        }
      ],
      "uri": "lb://gateway",
      "order": 0
    },
    "order": 0
  },
  {
    "route_id": "CompositeDiscoveryClient_uiservice",
    "route_definition": …
Run Code Online (Sandbox Code Playgroud)

kubernetes spring-cloud spring-cloud-gateway spring-cloud-kubernetes

3
推荐指数
1
解决办法
2110
查看次数

Spring Actuator - 服务发现 - /health“描述”:“发现客户端未初始化”,“状态”:“未知”

有关使用 Spring Boot Actuator 进行服务发现的问题,请结合 Spring Cloud Kubernetes。

目前,我有一个 Web 应用程序,它同时具有执行器和 Spring Boot kubernetes 依赖项。我也在使用 kubernetes 提供的发现客户端,一切正常。

然而,当我卷曲我的健康终点时,我确实看到了那些奇怪的陈述:

discoveryComposite":{"description":"Discovery Client not initialized","status":"UNKNOWN","components":{"discoveryClient":{"description":"Discovery Client not initialized","status":"UNKNOWN"}}

"reactiveDiscoveryClients":{"description":"Discovery Client not initialized","status":"UNKNOWN","components":{"Kubernetes Reactive Discovery Client":{"description":"Discovery Client not initialized","status":"UNKNOWN"}

Simple Reactive Discovery Client":{"description":"Discovery Client not initialized","status":"UNKNOWN"}}}

"readinessState":{"status":"UP"},"refreshScope":{"status":"UP"}},"groups":["liveness","readiness"]}*
Run Code Online (Sandbox Code Playgroud)

请问为什么是“未知”?我预计这里的三个中至少有一个会出现问题,并且绝对不是“发现客户端未初始化”。

我是否忘记初始化某些东西?注册一些东西?配置一些东西?

顺便说一句,这确实是一个关于 kubernetes 发现的问题。与Eureka无关,与Consul等无关。

非常感谢

java spring-boot-actuator spring-cloud-kubernetes

2
推荐指数
1
解决办法
1万
查看次数