6

Small question on how to disable Spring Cloud Kubernetes in local mode please.

The project is a simple SpringBoot + SpringCloud project deployed in Kubernetes. Hence, there is this dependency in the class path:

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-kubernetes-fabric8</artifactId>
        </dependency>

And when we deployed the app in a Kubernetes environment, everything is fine. However, the same app run in local mode will yield this warning, but most of all, a 20 seconds increased start time.

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)

In local, while removing the dependency entirely, things are "back to normal". The message disappears, and the start up time comes back down.

However, commenting and uncommenting the dependency based on the local environment might not be the best solution.

Is there a property to disable Spring Cloud Kubernetes entirely that I can configure in local please?

Thank you

Eugene
  • 117,005
  • 15
  • 201
  • 306
PatPanda
  • 3,644
  • 9
  • 58
  • 154

4 Answers4

8

As the documentation says, you can do that by adding:

spring.cloud.kubernetes.enabled=false

that, in turn, could be an environment property that you can enable/disable per environment.

Eugene
  • 117,005
  • 15
  • 201
  • 306
  • Indeed, I got confused trying all the combinations of spring.cloud.kubernetes.(config|secrets|...).enabled=false But actually, spring.cloud.kubernetes.enabled=false is simple and working. Thank you – PatPanda Jan 25 '21 at 02:24
  • 1
    @PatPatPat just a heads up, that this might be [auto-detectable](https://github.com/spring-cloud/spring-cloud-kubernetes/pull/884) in the future, though we do not know when or if. – Eugene Oct 17 '21 at 03:38
4

What worked for me was adding the spring.cloud.kubernetes.enabled=false property in the boostrap.properties/yaml file and not in the application.properties/yaml file.

JeyJ
  • 3,582
  • 4
  • 35
  • 83
0

Create the file "bootstrap.properties" into the resources folder

Then add the following lines:

spring.cloud.kubernetes.enabled=false
spring.cloud.kubernetes.discovery.enabled=false
Gustavo Marquez
  • 419
  • 4
  • 6
  • 1
    In versions of Spring Cloud Kubernetes prior to 3.0.x, Kubernetes awareness was implemented using spring.cloud.kubernetes.enabled property But now it has been removed. See this https://docs.spring.io/spring-cloud-kubernetes/docs/current/reference/html/#breaking-changes-in-3-0-x – Akshay Tyagi Jul 19 '23 at 14:58
0

In case using Spring Cloud Kubernetes 3.0.x, set property in application.properties/ bootstrap.yaml:

spring.main.cloud-platform: NONE

I built app successfully at LOCAL without above setup but SERVER failed. Because I upgraded to spring-cloud-kubernetes 3.0.x

Hai.Ngo
  • 21
  • 5