此版本仍在开发中,尚未被视为稳定版本。如需最新的稳定版本,请使用 Spring Cloud Kubernetes 3.1.4! |
Kubernetes 生态系统感知
本指南前面描述的所有功能都同样有效,无论您的应用程序是否在
Kubernetes 的 Kubernetes。这对于开发和故障排除非常有帮助。
从开发的角度来看,这允许您启动 Spring Boot 应用程序并调试一个
的模块。您无需在 Kubernetes 中部署它,
因为项目的代码依赖于 Fabric8 Kubernetes Java 客户端,它是一个流畅的 DSL,可以
使用http
协议添加到 Kubernetes 服务器的 REST API。
Kubernetes 感知基于 Spring Boot API,特别是 ConditionalOnCloudPlatform。
该属性将自动检测你的应用程序当前是否部署在 kubernetes 中。可以覆盖
该设置通过spring.main.cloud-platform
.
例如,如果你需要测试一些功能,但不想部署到集群,只需设置:spring.main.cloud-platform=KUBERNETES
.这将使spring-cloud-kubernetes
就像部署在真实集群中一样。
如果你有spring-cloud-starter-bootstrap 在你的 Classpath 上,或者正在设置spring.cloud.bootstrap.enabled=true 然后
您必须设置spring.main.cloud-platform 应该设置为bootstrap.{properties|yml} (或特定于配置文件的那个)。另请注意,这些属性:spring.cloud.kubernetes.config.enabled 和spring.cloud.kubernetes.secrets.enabled 仅在 中设置时生效bootstrap.{properties|yml} 当你有spring-cloud-starter-bootstrap 在你的 Classpath 上,或者正在设置spring.cloud.bootstrap.enabled=true . |
3.0.x 中的重大更改
在 Spring Cloud Kubernetes 之前的3.0.x
,Kubernetes 感知是使用spring.cloud.kubernetes.enabled
财产。这
属性已删除,因此不受支持。相反,我们使用 Spring Boot API:ConditionalOnCloudPlatform。
如果需要显式启用或禁用此感知,请使用spring.main.cloud-platform=NONE/KUBERNETES
.
-
另一个突破性的变化是额外的
list
加载 configmap/secrets 所需的动词。例如:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: cluster-role
rules:
- apiGroups: ["", "extensions", "apps", "discovery.k8s.io"]
resources: ["configmaps", "pods", "services", "endpoints", "secrets", "endpointslices"]
verbs: ["get", "list", "watch"]
Kubernetes 配置文件自动配置
当应用程序在 Kubernetes 中作为 Pod 运行时,一个名为kubernetes
自动激活。
这使您可以自定义配置,以定义在部署 Spring Boot 应用程序时应用的 bean
在 Kubernetes 平台中(例如,不同的开发和生产配置)。
Istio 感知
当您包含spring-cloud-kubernetes-fabric8-istio
module 中,将向应用程序添加新的配置文件
前提是应用程序在安装了 Istio 的 Kubernetes 集群中运行。然后,您可以使用
Spring@Profile("istio")
Bean 中的 annotations 和@Configuration
类。
Istio 感知模块使用me.snowdrop:istio-client
与 Istio API 交互,让我们发现流量规则、熔断器等,
使我们的 Spring Boot 应用程序能够轻松使用这些数据,以便根据环境动态配置自身。