diff --git a/multi/multi__building.html b/multi/multi__building.html index 6a489f0b..072816d8 100644 --- a/multi/multi__building.html +++ b/multi/multi__building.html @@ -1,6 +1,6 @@ - 12. Building

12. Building

12.1 Basic Compile and Test

To build the source you will need to install JDK 1.7.

Spring Cloud uses Maven for most build-related activities, and you + 13. Building

13. Building

13.1 Basic Compile and Test

To build the source you will need to install JDK 1.7.

Spring Cloud uses Maven for most build-related activities, and you should be able to get off the ground quite quickly by cloning the project you are interested in and typing

$ ./mvnw install
[Note]Note

You can also install Maven (>=3.3.3) yourself and run the mvn command in place of ./mvnw in the examples below. If you do that you also @@ -22,18 +22,18 @@ in Docker containers. See the README in the scripts demo repository for specific instructions about the common cases of mongo, rabbit and redis.

[Note]Note

If all else fails, build with the command from .travis.yml (usually -./mvnw install).

12.2 Documentation

The spring-cloud-build module has a "docs" profile, and if you switch +./mvnw install).

13.2 Documentation

The spring-cloud-build module has a "docs" profile, and if you switch that on it will try to build asciidoc sources from src/main/asciidoc. As part of that process it will look for a README.adoc and process it by loading all the includes, but not parsing or rendering it, just copying it to ${main.basedir} (defaults to ${basedir}, i.e. the root of the project). If there are any changes in the README it will then show up after a Maven build as -a modified file in the correct place. Just commit it and push the change.

12.3 Working with the code

If you don’t have an IDE preference we would recommend that you use +a modified file in the correct place. Just commit it and push the change.

13.3 Working with the code

If you don’t have an IDE preference we would recommend that you use Spring Tools Suite or Eclipse when working with the code. We use the m2eclipse eclipse plugin for maven support. Other IDEs and tools -should also work without issue as long as they use Maven 3.3.3 or better.

12.3.1 Importing into eclipse with m2eclipse

We recommend the m2eclipse eclipse plugin when working with +should also work without issue as long as they use Maven 3.3.3 or better.

13.3.1 Importing into eclipse with m2eclipse

We recommend the m2eclipse eclipse plugin when working with eclipse. If you don’t already have m2eclipse installed it is available from the "eclipse marketplace".

[Note]Note

Older versions of m2e do not support Maven 3.3, so once the projects are imported into Eclipse you will also need to tell @@ -42,6 +42,6 @@ see many different errors related to the POMs in the projects, check that you have an up to date installation. If you can’t upgrade m2e, add the "spring" profile to your settings.xml. Alternatively you can copy the repository settings from the "spring" profile of the parent -pom into your settings.xml.

12.3.2 Importing into eclipse without m2eclipse

If you prefer not to use m2eclipse you can generate eclipse project metadata using the +pom into your settings.xml.

13.3.2 Importing into eclipse without m2eclipse

If you prefer not to use m2eclipse you can generate eclipse project metadata using the following command:

$ ./mvnw eclipse:eclipse

The generated eclipse projects can be imported by selecting import existing projects -from the file menu.

\ No newline at end of file +from the file menu.

\ No newline at end of file diff --git a/multi/multi__contributing.html b/multi/multi__contributing.html index c55ce8d6..95d743a7 100644 --- a/multi/multi__contributing.html +++ b/multi/multi__contributing.html @@ -1,17 +1,17 @@ - 13. Contributing

13. Contributing

Spring Cloud is released under the non-restrictive Apache 2.0 license, + 14. Contributing

14. Contributing

Spring Cloud is released under the non-restrictive Apache 2.0 license, and follows a very standard Github development process, using Github tracker for issues and merging pull requests into master. If you want to contribute even something trivial please do not hesitate, but -follow the guidelines below.

13.1 Sign the Contributor License Agreement

Before we accept a non-trivial patch or pull request we will need you to sign the +follow the guidelines below.

14.1 Sign the Contributor License Agreement

Before we accept a non-trivial patch or pull request we will need you to sign the Contributor License Agreement. Signing the contributor’s agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. Active contributors might be asked to join the core team, and -given the ability to merge pull requests.

13.2 Code of Conduct

This project adheres to the Contributor Covenant code of +given the ability to merge pull requests.

14.2 Code of Conduct

This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report -unacceptable behavior to spring-code-of-conduct@pivotal.io.

13.3 Code Conventions and Housekeeping

None of these is essential for a pull request, but they will all help. They can also be +unacceptable behavior to spring-code-of-conduct@pivotal.io.

14.3 Code Conventions and Housekeeping

None of these is essential for a pull request, but they will all help. They can also be added after the original pull request but before a merge.

  • Use the Spring Framework code format conventions. If you use Eclipse you can import formatter settings using the eclipse-code-formatter.xml file from the @@ -25,7 +25,7 @@ in the project)
  • Add yourself as an Add some Javadocs and, if you change the namespace, some XSD doc elements.
  • A few unit tests would help a lot as well — someone has to do it.
  • If no-one else is using your branch, please rebase it against the current master (or other target branch in the main project).
  • When writing a commit message please follow these conventions, if you are fixing an existing issue please add Fixes gh-XXXX at the end of the commit -message (where XXXX is the issue number).

13.4 Checkstyle

Spring Cloud Build comes with a set of checkstyle rules. You can find them in the spring-cloud-build-tools module. The most notable files under the module are:

spring-cloud-build-tools/.  +message (where XXXX is the issue number).

14.4 Checkstyle

Spring Cloud Build comes with a set of checkstyle rules. You can find them in the spring-cloud-build-tools module. The most notable files under the module are:

spring-cloud-build-tools/. 

└── src
     ├── checkstyle
     │   └── checkstyle-suppressions.xml 1
@@ -33,7 +33,7 @@ message (where XXXX is the issue number).
2    └── checkstyle.xml 3

-

3

Default Checkstyle rules

2

File header setup

1

Default suppression rules

13.4.1 Checkstyle configuration

Checkstyle rules are disabled by default. To add checkstyle to your project just define the following properties and plugins.

pom.xml.  +

3

Default Checkstyle rules

2

File header setup

1

Default suppression rules

14.4.1 Checkstyle configuration

Checkstyle rules are disabled by default. To add checkstyle to your project just define the following properties and plugins.

pom.xml. 

<properties>
 <maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError> 1
         <maven-checkstyle-plugin.failsOnViolation>true
@@ -73,7 +73,7 @@ message (where XXXX is the issue number).

It’s advisable to copy the ${spring-cloud-build.rootFolder}/.editorconfig and ${spring-cloud-build.rootFolder}/.springformat to your project. That way, some default formatting rules will be applied. You can do so by running this script:

$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig
-$ touch .springformat

13.5 IDE setup

13.5.1 Intellij IDEA

In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.

spring-cloud-build-tools/.  +$ touch .springformat

14.5 IDE setup

14.5.1 Intellij IDEA

In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.

spring-cloud-build-tools/. 

└── src
     ├── checkstyle
     │   └── checkstyle-suppressions.xml 1
@@ -84,4 +84,4 @@ $ touch .springformat
4       └── Intellij_Spring_Boot_Java_Conventions.xml 5

-

3

Default Checkstyle rules

2

File header setup

1

Default suppression rules

4

Project defaults for Intellij that apply most of Checkstyle rules

5

Project style conventions for Intellij that apply most of Checkstyle rules

Figure 13.1. Code style

Code style

Go to FileSettingsEditorCode style. There click on the icon next to the Scheme section. There, click on the Import Scheme value and pick the Intellij IDEA code style XML option. Import the spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml file.

Figure 13.2. Inspection profiles

Code style

Go to FileSettingsEditorInspections. There click on the icon next to the Profile section. There, click on the Import Profile and import the spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml file.

Checkstyle. To have Intellij work with Checkstyle, you have to install the Checkstyle plugin. It’s advisable to also install the Assertions2Assertj to automatically convert the JUnit assertions

Checkstyle

Go to FileSettingsOther settingsCheckstyle. There click on the + icon in the Configuration file section. There, you’ll have to define where the checkstyle rules should be picked from. In the image above, we’ve picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build’s GitHub repository (e.g. for the checkstyle.xml : https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml). We need to provide the following variables:

[Important]Important

Remember to set the Scan Scope to All sources since we apply checkstyle rules for production and test sources.

\ No newline at end of file +

3

Default Checkstyle rules

2

File header setup

1

Default suppression rules

4

Project defaults for Intellij that apply most of Checkstyle rules

5

Project style conventions for Intellij that apply most of Checkstyle rules

Figure 14.1. Code style

Code style

Go to FileSettingsEditorCode style. There click on the icon next to the Scheme section. There, click on the Import Scheme value and pick the Intellij IDEA code style XML option. Import the spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml file.

Figure 14.2. Inspection profiles

Code style

Go to FileSettingsEditorInspections. There click on the icon next to the Profile section. There, click on the Import Profile and import the spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml file.

Checkstyle. To have Intellij work with Checkstyle, you have to install the Checkstyle plugin. It’s advisable to also install the Assertions2Assertj to automatically convert the JUnit assertions

Checkstyle

Go to FileSettingsOther settingsCheckstyle. There click on the + icon in the Configuration file section. There, you’ll have to define where the checkstyle rules should be picked from. In the image above, we’ve picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build’s GitHub repository (e.g. for the checkstyle.xml : https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml). We need to provide the following variables:

[Important]Important

Remember to set the Scan Scope to All sources since we apply checkstyle rules for production and test sources.

\ No newline at end of file diff --git a/multi/multi__discoveryclient_for_kubernetes.html b/multi/multi__discoveryclient_for_kubernetes.html index c4ba8e32..f304be4c 100644 --- a/multi/multi__discoveryclient_for_kubernetes.html +++ b/multi/multi__discoveryclient_for_kubernetes.html @@ -1,15 +1,11 @@ - 2. DiscoveryClient for Kubernetes

2. DiscoveryClient for Kubernetes

This project provides an implementation of Discovery Client + 3. DiscoveryClient for Kubernetes

3. DiscoveryClient for Kubernetes

This project provides an implementation of Discovery Client for Kubernetes. This allows you to query Kubernetes endpoints (see services) by name. A service is typically exposed by the Kubernetes API server as a collection of endpoints which represent http, https addresses that a client can access from a Spring Boot application running as a pod. This discovery feature is also used by the Spring Cloud Kubernetes Ribbon project -to fetch the list of the endpoints defined for an application to be load balanced.

This is something that you get for free just by adding the following dependency inside your project:

<dependency>
-    <groupId>org.springframework.cloud</groupId>
-    <artifactId>spring-cloud-starter-kubernetes</artifactId>
-    <version>${latest.version}</version>
-</dependency>

To enable loading of the DiscoveryClient, add @EnableDiscoveryClient to the according configuration or application class like this:

@SpringBootApplication
+to fetch the list of the endpoints defined for an application to be load balanced.

To enable loading of the DiscoveryClient, add @EnableDiscoveryClient to the according configuration or application class like this:

@SpringBootApplication
 @EnableDiscoveryClient
 public class Application {
   public static void main(String[] args) {
@@ -17,4 +13,4 @@ to fetch the list of the endpoints defined for an application to be load balance
   }
 }

Then you can inject the client in your code simply by:

@Autowired
 private DiscoveryClient discoveryClient;

If for any reason you need to disable the DiscoveryClient you can simply set the following property in application.properties:

spring.cloud.kubernetes.discovery.enabled=false

Some Spring Cloud components use the DiscoveryClient in order to obtain info about the local service instance. For -this to work you need to align the Kubernetes service name with the spring.application.name property.

\ No newline at end of file +this to work you need to align the Kubernetes service name with the spring.application.name property.

\ No newline at end of file diff --git a/multi/multi__examples.html b/multi/multi__examples.html index 58ce29e4..9fde54e2 100644 --- a/multi/multi__examples.html +++ b/multi/multi__examples.html @@ -1,5 +1,5 @@ - 10. Examples

10. Examples

Spring Cloud Kubernetes tries to make it transparent for your applications to consume Kubernetes Native Services + 11. Examples

11. Examples

Spring Cloud Kubernetes tries to make it transparent for your applications to consume Kubernetes Native Services following the Spring Cloud interfaces.

In your applications, you need to add the spring-cloud-kubernetes-discovery dependency to your classpath and remove any other dependency that contains a DiscoveryClient implementation (ie. Eureka Discovery Client). -The same applies for PropertySourceLocator, where you need to add to the classpath the spring-cloud-kubernetes-config and remove any other dependency that contains a PropertySourceLocator implementation (ie. Config Server Client).

The following projects highlight the usage of these dependencies and demonstrate how these libraries can be used from any Spring Boot application.

List of examples using these projects:

\ No newline at end of file +The same applies for PropertySourceLocator, where you need to add to the classpath the spring-cloud-kubernetes-config and remove any other dependency that contains a PropertySourceLocator implementation (ie. Config Server Client).

The following projects highlight the usage of these dependencies and demonstrate how these libraries can be used from any Spring Boot application.

List of examples using these projects:

\ No newline at end of file diff --git a/multi/multi__kubernetes_ecosystem_awareness.html b/multi/multi__kubernetes_ecosystem_awareness.html index c8c14f70..6cb73868 100644 --- a/multi/multi__kubernetes_ecosystem_awareness.html +++ b/multi/multi__kubernetes_ecosystem_awareness.html @@ -1,14 +1,14 @@ - 6. Kubernetes Ecosystem Awareness

6. Kubernetes Ecosystem Awareness

All of the features described above will work equally well regardless of whether your application is running inside + 7. Kubernetes Ecosystem Awareness

7. Kubernetes Ecosystem Awareness

All of the features described above will work equally well regardless of whether your application is running inside Kubernetes or not. This is really helpful for development and troubleshooting. From a development point of view, this is really helpful as you can start your Spring Boot application and debug one of the modules part of this project. It is not required to deploy it in Kubernetes as the code of the project relies on the Fabric8 Kubernetes Java client which is a fluent DSL able to -communicate using http protocol to the REST API of Kubernetes Server.

6.1 Kubernetes Profile Autoconfiguration

When the application runs as a pod inside Kubernetes a Spring profile named kubernetes will automatically get activated. +communicate using http protocol to the REST API of Kubernetes Server.

7.1 Kubernetes Profile Autoconfiguration

When the application runs as a pod inside Kubernetes a Spring profile named kubernetes will automatically get activated. This allows the developer to customize the configuration, to define beans that will be applied when the Spring Boot application is deployed -within the Kubernetes platform (e.g. different dev and prod configuration).

6.2 Istio Awareness

When including the spring-cloud-kubernetes-istio module into the application classpath a new profile will be added to the application, +within the Kubernetes platform (e.g. different dev and prod configuration).

7.2 Istio Awareness

When including the spring-cloud-kubernetes-istio module into the application classpath a new profile will be added to the application, if the application is running inside a Kubernetes Cluster with Istio installed. Then you can use spring @Profile("istio") annotations into your Beans and @Configuration's.

The Istio awareness module uses the me.snowdrop:istio-client to interact with Istio APIs enabling us to discover traffic rules, circuit breakers, etc. -Making it easy for our Spring Boot applications to consume this data to dynamically configure themselves according the environment.

\ No newline at end of file +Making it easy for our Spring Boot applications to consume this data to dynamically configure themselves according the environment.

\ No newline at end of file diff --git a/multi/multi__kubernetes_native_service_discovery.html b/multi/multi__kubernetes_native_service_discovery.html index 8383f1aa..4b1954bf 100644 --- a/multi/multi__kubernetes_native_service_discovery.html +++ b/multi/multi__kubernetes_native_service_discovery.html @@ -1,4 +1,4 @@ - 3. Kubernetes native service discovery

3. Kubernetes native service discovery

Kubernetes itself is capable of (server side) service discovery (see: https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services). -Using native kubernetes service discovery ensures compatibility with additional tooling, like: istio https://istio.io (service mesh, capable of load balancing, ribbon, circuit breaker, failover and much more).

The caller service just needs to refer to names resolvable in particular kubernetes cluster then. Simplest implementation might use the spring RestTemplate referring to fully qualified domain name (FQDN) http://{service-name}.{namespace}.svc.{cluster}.local:{service-port}.

Additionally, hystrix can be used for:

  • circuit breaker implementation on the caller side, just by annotating the spring boot application class: @EnableCircuitBreaker
  • and for the fallback functionality, annotating the respective method via: @HystrixCommand(fallbackMethod= does the job.
\ No newline at end of file + 4. Kubernetes native service discovery

4. Kubernetes native service discovery

Kubernetes itself is capable of (server side) service discovery (see: https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services). +Using native kubernetes service discovery ensures compatibility with additional tooling, like: istio https://istio.io (service mesh, capable of load balancing, ribbon, circuit breaker, failover and much more).

The caller service just needs to refer to names resolvable in particular kubernetes cluster then. Simplest implementation might use the spring RestTemplate referring to fully qualified domain name (FQDN) http://{service-name}.{namespace}.svc.{cluster}.local:{service-port}.

Additionally, hystrix can be used for:

  • circuit breaker implementation on the caller side, just by annotating the spring boot application class: @EnableCircuitBreaker
  • and for the fallback functionality, annotating the respective method via: @HystrixCommand(fallbackMethod= does the job.
\ No newline at end of file diff --git a/multi/multi__kubernetes_propertysource_implementations.html b/multi/multi__kubernetes_propertysource_implementations.html index ef88c882..fd38a7c5 100644 --- a/multi/multi__kubernetes_propertysource_implementations.html +++ b/multi/multi__kubernetes_propertysource_implementations.html @@ -1,9 +1,9 @@ - 4. Kubernetes PropertySource implementations

4. Kubernetes PropertySource implementations

The most common approach to configure your Spring Boot application is to create an application.properties|yaml or + 5. Kubernetes PropertySource implementations

5. Kubernetes PropertySource implementations

The most common approach to configure your Spring Boot application is to create an application.properties|yaml or an application-profile.properties|yaml file containing key-value pairs providing customization values to your application or Spring Boot starters. Users may override these properties by specifying system properties or environment -variables.

4.1 ConfigMap PropertySource

Kubernetes provides a resource named ConfigMap to externalize the +variables.

5.1 ConfigMap PropertySource

Kubernetes provides a resource named ConfigMap to externalize the parameters to pass to your application in the form of key-value pairs or embedded application.properties|yaml files. The Spring Cloud Kubernetes Config project makes Kubernetes `ConfigMap`s available during application bootstrapping and triggers hot reloading of beans or Spring context when changes are detected on @@ -106,7 +106,7 @@ and have Spring Cloud Kubernetes read them from the file system. This behavior is controlled by the spring.cloud.kubernetes.config.paths property and can be used in addition to or instead of the mechanism described earlier. Multiple (exact) file paths can be specified in spring.cloud.kubernetes.config.paths by using the , delimiter

Notes: -You have to provide full exact path to each property file, because directories are not being recursively parsed.

Table 4.1. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.config.enableApi

Boolean

true

Enable/Disable consuming ConfigMaps via APIs

spring.cloud.kubernetes.config.enabled

Boolean

true

Enable Secrets PropertySource

spring.cloud.kubernetes.config.name

String

${spring.application.name}

Sets the name of ConfigMap to lookup

spring.cloud.kubernetes.config.namespace

String

Client namespace

Sets the Kubernetes namespace where to lookup

spring.cloud.kubernetes.config.paths

List

null

Sets the paths where ConfigMaps are mounted


4.2 Secrets PropertySource

Kubernetes has the notion of Secrets for storing +You have to provide full exact path to each property file, because directories are not being recursively parsed.

Table 5.1. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.config.enableApi

Boolean

true

Enable/Disable consuming ConfigMaps via APIs

spring.cloud.kubernetes.config.enabled

Boolean

true

Enable Secrets PropertySource

spring.cloud.kubernetes.config.name

String

${spring.application.name}

Sets the name of ConfigMap to lookup

spring.cloud.kubernetes.config.namespace

String

Client namespace

Sets the Kubernetes namespace where to lookup

spring.cloud.kubernetes.config.paths

List

null

Sets the paths where ConfigMaps are mounted


5.2 Secrets PropertySource

Kubernetes has the notion of Secrets for storing sensitive data such as password, OAuth tokens, etc. This project provides integration with Secrets to make secrets accessible by Spring Boot applications. This feature can be explicitly enabled/disabled using the spring.cloud.kubernetes.secrets.enabled property.

The SecretsPropertySource when enabled will lookup Kubernetes for Secrets from the following sources:

  1. reading recursively from secrets mounts
  2. named after the application (as defined by spring.application.name)
  3. matching some labels

Please note that by default, consuming Secrets via API (points 2 and 3 above) is not enabled for security reasons and it is recommended that containers share secrets via mounted volumes. @@ -143,13 +143,13 @@ configuration. We can create a Kubernetes secret using the following command:

secretKeyRef: name: db-secret key: password

You can select the Secrets to consume in a number of ways:

  1. By listing the directories where secrets are mapped:

    -Dspring.cloud.kubernetes.secrets.paths=/etc/secrets/db-secret,etc/secrets/postgresql

    If you have all the secrets mapped to a common root, you can set them like:

    -Dspring.cloud.kubernetes.secrets.paths=/etc/secrets
  2. By setting a named secret:

    -Dspring.cloud.kubernetes.secrets.name=db-secret
  3. By defining a list of labels:

    -Dspring.cloud.kubernetes.secrets.labels.broker=activemq
    --Dspring.cloud.kubernetes.secrets.labels.db=postgresql

Table 4.2. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.secrets.enableApi

Boolean

false

Enable/Disable consuming secrets via APIs (examples 2 and 3)

spring.cloud.kubernetes.secrets.enabled

Boolean

true

Enable Secrets PropertySource

spring.cloud.kubernetes.secrets.name

String

${spring.application.name}

Sets the name of the secret to lookup

spring.cloud.kubernetes.secrets.namespace

String

Client namespace

Sets the Kubernetes namespace where to lookup

spring.cloud.kubernetes.secrets.labels

Map

null

Sets the labels used to lookup secrets

spring.cloud.kubernetes.secrets.paths

List

null

Sets the paths where secrets are mounted (example 1)


Notes: +-Dspring.cloud.kubernetes.secrets.labels.db=postgresql

Table 5.2. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.secrets.enableApi

Boolean

false

Enable/Disable consuming secrets via APIs (examples 2 and 3)

spring.cloud.kubernetes.secrets.enabled

Boolean

true

Enable Secrets PropertySource

spring.cloud.kubernetes.secrets.name

String

${spring.application.name}

Sets the name of the secret to lookup

spring.cloud.kubernetes.secrets.namespace

String

Client namespace

Sets the Kubernetes namespace where to lookup

spring.cloud.kubernetes.secrets.labels

Map

null

Sets the labels used to lookup secrets

spring.cloud.kubernetes.secrets.paths

List

null

Sets the paths where secrets are mounted (example 1)


Notes: - The property spring.cloud.kubernetes.secrets.labels behaves as defined by Map-based binding. - The property spring.cloud.kubernetes.secrets.paths behaves as defined by Collection-based binding. - Access to secrets via API may be restricted for security reasons, the preferred way is to mount secret to the POD.

Example of application using secrets (though it hasn’t been updated to use the new spring-cloud-kubernetes project): -spring-boot-camel-config

4.3 PropertySource Reload

Some applications may need to detect changes on external property sources and update their internal status to reflect the new configuration. +spring-boot-camel-config

5.3 PropertySource Reload

Some applications may need to detect changes on external property sources and update their internal status to reflect the new configuration. The reload feature of Spring Cloud Kubernetes is able to trigger an application reload when a related ConfigMap or Secret changes.

This feature is disabled by default and can be enabled using the configuration property spring.cloud.kubernetes.reload.enabled=true (eg. in the application.properties file).

The following levels of reload are supported (property spring.cloud.kubernetes.reload.strategy): @@ -193,6 +193,6 @@ The view role on the service account is required in - polling: re-creates the configuration periodically from config maps and secrets to see if it has changed. The polling period can be configured using the property spring.cloud.kubernetes.reload.period and defaults to 15 seconds. It requires the same role as the monitored property source. -This means, for example, that using polling on file mounted secret sources does not require particular privileges.

Table 4.3. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.reload.period

Duration

15s

The period for verifying changes when using the polling strategy

spring.cloud.kubernetes.reload.enabled

Boolean

false

Enables monitoring of property sources and configuration reload

spring.cloud.kubernetes.reload.monitoring-config-maps

Boolean

true

Allow monitoring changes in config maps

spring.cloud.kubernetes.reload.monitoring-secrets

Boolean

false

Allow monitoring changes in secrets

spring.cloud.kubernetes.reload.strategy

Enum

refresh

The strategy to use when firing a reload (refresh, restart_context, shutdown)

spring.cloud.kubernetes.reload.mode

Enum

event

Specifies how to listen for changes in property sources (event, polling)


Notes: +This means, for example, that using polling on file mounted secret sources does not require particular privileges.

Table 5.3. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.reload.period

Duration

15s

The period for verifying changes when using the polling strategy

spring.cloud.kubernetes.reload.enabled

Boolean

false

Enables monitoring of property sources and configuration reload

spring.cloud.kubernetes.reload.monitoring-config-maps

Boolean

true

Allow monitoring changes in config maps

spring.cloud.kubernetes.reload.monitoring-secrets

Boolean

false

Allow monitoring changes in secrets

spring.cloud.kubernetes.reload.strategy

Enum

refresh

The strategy to use when firing a reload (refresh, restart_context, shutdown)

spring.cloud.kubernetes.reload.mode

Enum

event

Specifies how to listen for changes in property sources (event, polling)


Notes: - Properties under spring.cloud.kubernetes.reload. should not be used in config maps or secrets: changing such properties at runtime may lead to unexpected results; -- Deleting a property or the whole config map does not restore the original state of the beans when using the refresh level.

\ No newline at end of file +- Deleting a property or the whole config map does not restore the original state of the beans when using the refresh level.

\ No newline at end of file diff --git a/multi/multi__leader_election.html b/multi/multi__leader_election.html index 1a762161..259d1e39 100644 --- a/multi/multi__leader_election.html +++ b/multi/multi__leader_election.html @@ -1,3 +1,3 @@ - 8. Leader Election

8. Leader Election

<TBD>

\ No newline at end of file + 9. Leader Election

9. Leader Election

<TBD>

\ No newline at end of file diff --git a/multi/multi__other_resources.html b/multi/multi__other_resources.html index e889c3ab..44dcf986 100644 --- a/multi/multi__other_resources.html +++ b/multi/multi__other_resources.html @@ -1,3 +1,3 @@ - 11. Other Resources

11. Other Resources

Here you can find other resources such as presentations(slides) and videos about Spring Cloud Kubernetes.

Please feel free to submit other resources via PR to this repository.

\ No newline at end of file + 12. Other Resources

12. Other Resources

Here you can find other resources such as presentations(slides) and videos about Spring Cloud Kubernetes.

Please feel free to submit other resources via PR to this repository.

\ No newline at end of file diff --git a/multi/multi__pod_health_indicator.html b/multi/multi__pod_health_indicator.html index a3a947fc..8a3391ff 100644 --- a/multi/multi__pod_health_indicator.html +++ b/multi/multi__pod_health_indicator.html @@ -1,4 +1,4 @@ - 7. Pod Health Indicator

7. Pod Health Indicator

Spring Boot uses HealthIndicator to expose info about the health of an application. -That makes it really useful for exposing health related information to the user and are also a good fit for use as readiness probes.

The Kubernetes health indicator which is part of the core module exposes the following info:

  • pod name, ip address, namespace, service account, node name and its ip address
  • flag that indicates if the Spring Boot application is internal or external to Kubernetes
\ No newline at end of file + 8. Pod Health Indicator

8. Pod Health Indicator

Spring Boot uses HealthIndicator to expose info about the health of an application. +That makes it really useful for exposing health related information to the user and are also a good fit for use as readiness probes.

The Kubernetes health indicator which is part of the core module exposes the following info:

  • pod name, ip address, namespace, service account, node name and its ip address
  • flag that indicates if the Spring Boot application is internal or external to Kubernetes
\ No newline at end of file diff --git a/multi/multi__ribbon_discovery_in_kubernetes.html b/multi/multi__ribbon_discovery_in_kubernetes.html index f15e78a4..e4c055ff 100644 --- a/multi/multi__ribbon_discovery_in_kubernetes.html +++ b/multi/multi__ribbon_discovery_in_kubernetes.html @@ -1,14 +1,10 @@ - 5. Ribbon discovery in Kubernetes

5. Ribbon discovery in Kubernetes

Spring Cloud client applications calling a microservice should be interested on relying on a client load-balancing + 6. Ribbon discovery in Kubernetes

6. Ribbon discovery in Kubernetes

Spring Cloud client applications calling a microservice should be interested on relying on a client load-balancing feature in order to automatically discover at which endpoint(s) it can reach a given service. This mechanism has been implemented within the [spring-cloud-kubernetes-ribbon](spring-cloud-kubernetes-ribbon/pom.xml) project where a Kubernetes client will populate a Ribbon ServerList containing information -about such endpoints.

The implementation is part of the following starter that you can use by adding its dependency to your pom file:

<dependency>
-    <groupId>org.springframework.cloud</groupId>
-    <artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId>
-    <version>${latest.version}</version>
-</dependency>

When the list of the endpoints is populated, the Kubernetes client will search the registered endpoints living in +about such endpoints.

When the list of the endpoints is populated, the Kubernetes client will search the registered endpoints living in the current namespace/project matching the service name defined using the Ribbon Client annotation:

@RibbonClient(name = "name-service")

You can configure Ribbon’s behavior by providing properties in your application.properties (via your application’s dedicated ConfigMap) using the following format: <name of your service>.ribbon.<Ribbon configuration key> where:

  • <name of your service> corresponds to the service name you’re accessing over Ribbon, as configured using the @RibbonClient annotation (e.g. name-service in the example above)
  • <Ribbon configuration key> is one of the Ribbon configuration key defined by @@ -18,4 +14,4 @@ behavior is to use the first one found. To select more specifically which port t the PortName key. If you want to specify in which Kubernetes' namespace the target service should be looked up, use the KubernetesNamespace key, remembering in both instances to prefix these keys with your service name and ribbon prefix as specified above.

    Examples that are using this module for ribbon discovery are:

    Note: The Ribbon discovery client can be disabled by setting this key within the application properties file -spring.cloud.kubernetes.ribbon.enabled=false.

\ No newline at end of file +spring.cloud.kubernetes.ribbon.enabled=false.

\ No newline at end of file diff --git a/multi/multi__security_configurations_inside_kubernetes.html b/multi/multi__security_configurations_inside_kubernetes.html index b803727f..2f65bd3f 100644 --- a/multi/multi__security_configurations_inside_kubernetes.html +++ b/multi/multi__security_configurations_inside_kubernetes.html @@ -1,9 +1,9 @@ - 9. Security Configurations inside Kubernetes

9. Security Configurations inside Kubernetes

9.1 Namespace

Most of the components provided in this project need to know the namespace. For Kubernetes (1.3+) the namespace is made available to pod as part of the service account secret and automatically detected by the client. + 10. Security Configurations inside Kubernetes

10. Security Configurations inside Kubernetes

10.1 Namespace

Most of the components provided in this project need to know the namespace. For Kubernetes (1.3+) the namespace is made available to pod as part of the service account secret and automatically detected by the client. For earlier version it needs to be specified as an env var to the pod. A quick way to do this is:

env:
 - name: "KUBERNETES_NAMESPACE"
   valueFrom:
     fieldRef:
-      fieldPath: "metadata.namespace"

9.2 Service Account

For distros of Kubernetes that support more fine-grained role-based access within the cluster, you need to make sure a pod that runs with spring-cloud-kubernetes has access to the Kubernetes API. -For any service accounts you assign to a deployment/pod, you need to make sure it has the correct roles. For example, you can add cluster-reader permissions to your default service account depending on the project you’re in:

\ No newline at end of file + fieldPath: "metadata.namespace"

10.2 Service Account

For distros of Kubernetes that support more fine-grained role-based access within the cluster, you need to make sure a pod that runs with spring-cloud-kubernetes has access to the Kubernetes API. +For any service accounts you assign to a deployment/pod, you need to make sure it has the correct roles. For example, you can add cluster-reader permissions to your default service account depending on the project you’re in:

\ No newline at end of file diff --git a/multi/multi__starters.html b/multi/multi__starters.html new file mode 100644 index 00000000..8d23af83 --- /dev/null +++ b/multi/multi__starters.html @@ -0,0 +1,22 @@ + + + 2. Starters

2. Starters

Starters are convenient dependency descriptors you can include in your +application. Include a starter to get the dependencies and Spring Boot +auto-configuration for a feature set.

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

Discovery Client implementation that +resolves service names to Kubernetes Services.

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

Load application properties from Kubernetes +ConfigMaps and Secrets. +Reload application properties when a ConfigMap or +Secret changes.

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

Ribbon client-side load balancer with +server list obtained from Kubernetes Endpoints.

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

All Spring Cloud Kubernetes features.

\ No newline at end of file diff --git a/multi/multi__why_do_you_need_spring_cloud_kubernetes.html b/multi/multi__why_do_you_need_spring_cloud_kubernetes.html index 15ae9e8b..0abfc5de 100644 --- a/multi/multi__why_do_you_need_spring_cloud_kubernetes.html +++ b/multi/multi__why_do_you_need_spring_cloud_kubernetes.html @@ -1,4 +1,4 @@ - 1. Why do you need Spring Cloud Kubernetes?

1. Why do you need Spring Cloud Kubernetes?

Spring Cloud Kubernetes provide Spring Cloud common interfaces implementations to consume Kubernetes native services. -The main objective of the projects provided in this repository is to facilitate the integration of Spring Cloud/Spring Boot applications running inside Kubernetes.

\ No newline at end of file + 1. Why do you need Spring Cloud Kubernetes?

1. Why do you need Spring Cloud Kubernetes?

Spring Cloud Kubernetes provide Spring Cloud common interfaces implementations to consume Kubernetes native services. +The main objective of the projects provided in this repository is to facilitate the integration of Spring Cloud/Spring Boot applications running inside Kubernetes.

\ No newline at end of file diff --git a/multi/multi_spring-cloud-kubernetes.html b/multi/multi_spring-cloud-kubernetes.html index 31bac945..884719ab 100644 --- a/multi/multi_spring-cloud-kubernetes.html +++ b/multi/multi_spring-cloud-kubernetes.html @@ -1,3 +1,3 @@ - Spring Cloud Kubernetes \ No newline at end of file + Spring Cloud Kubernetes \ No newline at end of file diff --git a/single/spring-cloud-kubernetes.html b/single/spring-cloud-kubernetes.html index a81a2915..1e8555bc 100644 --- a/single/spring-cloud-kubernetes.html +++ b/single/spring-cloud-kubernetes.html @@ -1,16 +1,31 @@ - Spring Cloud Kubernetes

Spring Cloud Kubernetes


1. Why do you need Spring Cloud Kubernetes?

Spring Cloud Kubernetes provide Spring Cloud common interfaces implementations to consume Kubernetes native services. -The main objective of the projects provided in this repository is to facilitate the integration of Spring Cloud/Spring Boot applications running inside Kubernetes.

2. DiscoveryClient for Kubernetes

This project provides an implementation of Discovery Client + Spring Cloud Kubernetes

Spring Cloud Kubernetes


1. Why do you need Spring Cloud Kubernetes?

Spring Cloud Kubernetes provide Spring Cloud common interfaces implementations to consume Kubernetes native services. +The main objective of the projects provided in this repository is to facilitate the integration of Spring Cloud/Spring Boot applications running inside Kubernetes.

2. Starters

Starters are convenient dependency descriptors you can include in your +application. Include a starter to get the dependencies and Spring Boot +auto-configuration for a feature set.

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

Discovery Client implementation that +resolves service names to Kubernetes Services.

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

Load application properties from Kubernetes +ConfigMaps and Secrets. +Reload application properties when a ConfigMap or +Secret changes.

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

Ribbon client-side load balancer with +server list obtained from Kubernetes Endpoints.

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

All Spring Cloud Kubernetes features.

3. DiscoveryClient for Kubernetes

This project provides an implementation of Discovery Client for Kubernetes. This allows you to query Kubernetes endpoints (see services) by name. A service is typically exposed by the Kubernetes API server as a collection of endpoints which represent http, https addresses that a client can access from a Spring Boot application running as a pod. This discovery feature is also used by the Spring Cloud Kubernetes Ribbon project -to fetch the list of the endpoints defined for an application to be load balanced.

This is something that you get for free just by adding the following dependency inside your project:

<dependency>
-    <groupId>org.springframework.cloud</groupId>
-    <artifactId>spring-cloud-starter-kubernetes</artifactId>
-    <version>${latest.version}</version>
-</dependency>

To enable loading of the DiscoveryClient, add @EnableDiscoveryClient to the according configuration or application class like this:

@SpringBootApplication
+to fetch the list of the endpoints defined for an application to be load balanced.

To enable loading of the DiscoveryClient, add @EnableDiscoveryClient to the according configuration or application class like this:

@SpringBootApplication
 @EnableDiscoveryClient
 public class Application {
   public static void main(String[] args) {
@@ -18,11 +33,11 @@ to fetch the list of the endpoints defined for an application to be load balance
   }
 }

Then you can inject the client in your code simply by:

@Autowired
 private DiscoveryClient discoveryClient;

If for any reason you need to disable the DiscoveryClient you can simply set the following property in application.properties:

spring.cloud.kubernetes.discovery.enabled=false

Some Spring Cloud components use the DiscoveryClient in order to obtain info about the local service instance. For -this to work you need to align the Kubernetes service name with the spring.application.name property.

3. Kubernetes native service discovery

Kubernetes itself is capable of (server side) service discovery (see: https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services). -Using native kubernetes service discovery ensures compatibility with additional tooling, like: istio https://istio.io (service mesh, capable of load balancing, ribbon, circuit breaker, failover and much more).

The caller service just needs to refer to names resolvable in particular kubernetes cluster then. Simplest implementation might use the spring RestTemplate referring to fully qualified domain name (FQDN) http://{service-name}.{namespace}.svc.{cluster}.local:{service-port}.

Additionally, hystrix can be used for:

  • circuit breaker implementation on the caller side, just by annotating the spring boot application class: @EnableCircuitBreaker
  • and for the fallback functionality, annotating the respective method via: @HystrixCommand(fallbackMethod= does the job.

4. Kubernetes PropertySource implementations

The most common approach to configure your Spring Boot application is to create an application.properties|yaml or +this to work you need to align the Kubernetes service name with the spring.application.name property.

4. Kubernetes native service discovery

Kubernetes itself is capable of (server side) service discovery (see: https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services). +Using native kubernetes service discovery ensures compatibility with additional tooling, like: istio https://istio.io (service mesh, capable of load balancing, ribbon, circuit breaker, failover and much more).

The caller service just needs to refer to names resolvable in particular kubernetes cluster then. Simplest implementation might use the spring RestTemplate referring to fully qualified domain name (FQDN) http://{service-name}.{namespace}.svc.{cluster}.local:{service-port}.

Additionally, hystrix can be used for:

  • circuit breaker implementation on the caller side, just by annotating the spring boot application class: @EnableCircuitBreaker
  • and for the fallback functionality, annotating the respective method via: @HystrixCommand(fallbackMethod= does the job.

5. Kubernetes PropertySource implementations

The most common approach to configure your Spring Boot application is to create an application.properties|yaml or an application-profile.properties|yaml file containing key-value pairs providing customization values to your application or Spring Boot starters. Users may override these properties by specifying system properties or environment -variables.

4.1 ConfigMap PropertySource

Kubernetes provides a resource named ConfigMap to externalize the +variables.

5.1 ConfigMap PropertySource

Kubernetes provides a resource named ConfigMap to externalize the parameters to pass to your application in the form of key-value pairs or embedded application.properties|yaml files. The Spring Cloud Kubernetes Config project makes Kubernetes `ConfigMap`s available during application bootstrapping and triggers hot reloading of beans or Spring context when changes are detected on @@ -125,7 +140,7 @@ and have Spring Cloud Kubernetes read them from the file system. This behavior is controlled by the spring.cloud.kubernetes.config.paths property and can be used in addition to or instead of the mechanism described earlier. Multiple (exact) file paths can be specified in spring.cloud.kubernetes.config.paths by using the , delimiter

Notes: -You have to provide full exact path to each property file, because directories are not being recursively parsed.

Table 4.1. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.config.enableApi

Boolean

true

Enable/Disable consuming ConfigMaps via APIs

spring.cloud.kubernetes.config.enabled

Boolean

true

Enable Secrets PropertySource

spring.cloud.kubernetes.config.name

String

${spring.application.name}

Sets the name of ConfigMap to lookup

spring.cloud.kubernetes.config.namespace

String

Client namespace

Sets the Kubernetes namespace where to lookup

spring.cloud.kubernetes.config.paths

List

null

Sets the paths where ConfigMaps are mounted


4.2 Secrets PropertySource

Kubernetes has the notion of Secrets for storing +You have to provide full exact path to each property file, because directories are not being recursively parsed.

Table 5.1. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.config.enableApi

Boolean

true

Enable/Disable consuming ConfigMaps via APIs

spring.cloud.kubernetes.config.enabled

Boolean

true

Enable Secrets PropertySource

spring.cloud.kubernetes.config.name

String

${spring.application.name}

Sets the name of ConfigMap to lookup

spring.cloud.kubernetes.config.namespace

String

Client namespace

Sets the Kubernetes namespace where to lookup

spring.cloud.kubernetes.config.paths

List

null

Sets the paths where ConfigMaps are mounted


5.2 Secrets PropertySource

Kubernetes has the notion of Secrets for storing sensitive data such as password, OAuth tokens, etc. This project provides integration with Secrets to make secrets accessible by Spring Boot applications. This feature can be explicitly enabled/disabled using the spring.cloud.kubernetes.secrets.enabled property.

The SecretsPropertySource when enabled will lookup Kubernetes for Secrets from the following sources:

  1. reading recursively from secrets mounts
  2. named after the application (as defined by spring.application.name)
  3. matching some labels

Please note that by default, consuming Secrets via API (points 2 and 3 above) is not enabled for security reasons and it is recommended that containers share secrets via mounted volumes. @@ -162,13 +177,13 @@ configuration. We can create a Kubernetes secret using the following command:

secretKeyRef: name: db-secret key: password

You can select the Secrets to consume in a number of ways:

  1. By listing the directories where secrets are mapped:

    -Dspring.cloud.kubernetes.secrets.paths=/etc/secrets/db-secret,etc/secrets/postgresql

    If you have all the secrets mapped to a common root, you can set them like:

    -Dspring.cloud.kubernetes.secrets.paths=/etc/secrets
  2. By setting a named secret:

    -Dspring.cloud.kubernetes.secrets.name=db-secret
  3. By defining a list of labels:

    -Dspring.cloud.kubernetes.secrets.labels.broker=activemq
    --Dspring.cloud.kubernetes.secrets.labels.db=postgresql

Table 4.2. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.secrets.enableApi

Boolean

false

Enable/Disable consuming secrets via APIs (examples 2 and 3)

spring.cloud.kubernetes.secrets.enabled

Boolean

true

Enable Secrets PropertySource

spring.cloud.kubernetes.secrets.name

String

${spring.application.name}

Sets the name of the secret to lookup

spring.cloud.kubernetes.secrets.namespace

String

Client namespace

Sets the Kubernetes namespace where to lookup

spring.cloud.kubernetes.secrets.labels

Map

null

Sets the labels used to lookup secrets

spring.cloud.kubernetes.secrets.paths

List

null

Sets the paths where secrets are mounted (example 1)


Notes: +-Dspring.cloud.kubernetes.secrets.labels.db=postgresql

Table 5.2. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.secrets.enableApi

Boolean

false

Enable/Disable consuming secrets via APIs (examples 2 and 3)

spring.cloud.kubernetes.secrets.enabled

Boolean

true

Enable Secrets PropertySource

spring.cloud.kubernetes.secrets.name

String

${spring.application.name}

Sets the name of the secret to lookup

spring.cloud.kubernetes.secrets.namespace

String

Client namespace

Sets the Kubernetes namespace where to lookup

spring.cloud.kubernetes.secrets.labels

Map

null

Sets the labels used to lookup secrets

spring.cloud.kubernetes.secrets.paths

List

null

Sets the paths where secrets are mounted (example 1)


Notes: - The property spring.cloud.kubernetes.secrets.labels behaves as defined by Map-based binding. - The property spring.cloud.kubernetes.secrets.paths behaves as defined by Collection-based binding. - Access to secrets via API may be restricted for security reasons, the preferred way is to mount secret to the POD.

Example of application using secrets (though it hasn’t been updated to use the new spring-cloud-kubernetes project): -spring-boot-camel-config

4.3 PropertySource Reload

Some applications may need to detect changes on external property sources and update their internal status to reflect the new configuration. +spring-boot-camel-config

5.3 PropertySource Reload

Some applications may need to detect changes on external property sources and update their internal status to reflect the new configuration. The reload feature of Spring Cloud Kubernetes is able to trigger an application reload when a related ConfigMap or Secret changes.

This feature is disabled by default and can be enabled using the configuration property spring.cloud.kubernetes.reload.enabled=true (eg. in the application.properties file).

The following levels of reload are supported (property spring.cloud.kubernetes.reload.strategy): @@ -212,17 +227,13 @@ The view role on the service account is required in - polling: re-creates the configuration periodically from config maps and secrets to see if it has changed. The polling period can be configured using the property spring.cloud.kubernetes.reload.period and defaults to 15 seconds. It requires the same role as the monitored property source. -This means, for example, that using polling on file mounted secret sources does not require particular privileges.

Table 4.3. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.reload.period

Duration

15s

The period for verifying changes when using the polling strategy

spring.cloud.kubernetes.reload.enabled

Boolean

false

Enables monitoring of property sources and configuration reload

spring.cloud.kubernetes.reload.monitoring-config-maps

Boolean

true

Allow monitoring changes in config maps

spring.cloud.kubernetes.reload.monitoring-secrets

Boolean

false

Allow monitoring changes in secrets

spring.cloud.kubernetes.reload.strategy

Enum

refresh

The strategy to use when firing a reload (refresh, restart_context, shutdown)

spring.cloud.kubernetes.reload.mode

Enum

event

Specifies how to listen for changes in property sources (event, polling)


Notes: +This means, for example, that using polling on file mounted secret sources does not require particular privileges.

Table 5.3. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.reload.period

Duration

15s

The period for verifying changes when using the polling strategy

spring.cloud.kubernetes.reload.enabled

Boolean

false

Enables monitoring of property sources and configuration reload

spring.cloud.kubernetes.reload.monitoring-config-maps

Boolean

true

Allow monitoring changes in config maps

spring.cloud.kubernetes.reload.monitoring-secrets

Boolean

false

Allow monitoring changes in secrets

spring.cloud.kubernetes.reload.strategy

Enum

refresh

The strategy to use when firing a reload (refresh, restart_context, shutdown)

spring.cloud.kubernetes.reload.mode

Enum

event

Specifies how to listen for changes in property sources (event, polling)


Notes: - Properties under spring.cloud.kubernetes.reload. should not be used in config maps or secrets: changing such properties at runtime may lead to unexpected results; -- Deleting a property or the whole config map does not restore the original state of the beans when using the refresh level.

5. Ribbon discovery in Kubernetes

Spring Cloud client applications calling a microservice should be interested on relying on a client load-balancing +- Deleting a property or the whole config map does not restore the original state of the beans when using the refresh level.

6. Ribbon discovery in Kubernetes

Spring Cloud client applications calling a microservice should be interested on relying on a client load-balancing feature in order to automatically discover at which endpoint(s) it can reach a given service. This mechanism has been implemented within the [spring-cloud-kubernetes-ribbon](spring-cloud-kubernetes-ribbon/pom.xml) project where a Kubernetes client will populate a Ribbon ServerList containing information -about such endpoints.

The implementation is part of the following starter that you can use by adding its dependency to your pom file:

<dependency>
-    <groupId>org.springframework.cloud</groupId>
-    <artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId>
-    <version>${latest.version}</version>
-</dependency>

When the list of the endpoints is populated, the Kubernetes client will search the registered endpoints living in +about such endpoints.

When the list of the endpoints is populated, the Kubernetes client will search the registered endpoints living in the current namespace/project matching the service name defined using the Ribbon Client annotation:

@RibbonClient(name = "name-service")

You can configure Ribbon’s behavior by providing properties in your application.properties (via your application’s dedicated ConfigMap) using the following format: <name of your service>.ribbon.<Ribbon configuration key> where:

  • <name of your service> corresponds to the service name you’re accessing over Ribbon, as configured using the @RibbonClient annotation (e.g. name-service in the example above)
  • <Ribbon configuration key> is one of the Ribbon configuration key defined by @@ -232,27 +243,27 @@ behavior is to use the first one found. To select more specifically which port t the PortName key. If you want to specify in which Kubernetes' namespace the target service should be looked up, use the KubernetesNamespace key, remembering in both instances to prefix these keys with your service name and ribbon prefix as specified above.

    Examples that are using this module for ribbon discovery are:

    Note: The Ribbon discovery client can be disabled by setting this key within the application properties file -spring.cloud.kubernetes.ribbon.enabled=false.

6. Kubernetes Ecosystem Awareness

All of the features described above will work equally well regardless of whether your application is running inside +spring.cloud.kubernetes.ribbon.enabled=false.

7. Kubernetes Ecosystem Awareness

All of the features described above will work equally well regardless of whether your application is running inside Kubernetes or not. This is really helpful for development and troubleshooting. From a development point of view, this is really helpful as you can start your Spring Boot application and debug one of the modules part of this project. It is not required to deploy it in Kubernetes as the code of the project relies on the Fabric8 Kubernetes Java client which is a fluent DSL able to -communicate using http protocol to the REST API of Kubernetes Server.

6.1 Kubernetes Profile Autoconfiguration

When the application runs as a pod inside Kubernetes a Spring profile named kubernetes will automatically get activated. +communicate using http protocol to the REST API of Kubernetes Server.

7.1 Kubernetes Profile Autoconfiguration

When the application runs as a pod inside Kubernetes a Spring profile named kubernetes will automatically get activated. This allows the developer to customize the configuration, to define beans that will be applied when the Spring Boot application is deployed -within the Kubernetes platform (e.g. different dev and prod configuration).

6.2 Istio Awareness

When including the spring-cloud-kubernetes-istio module into the application classpath a new profile will be added to the application, +within the Kubernetes platform (e.g. different dev and prod configuration).

7.2 Istio Awareness

When including the spring-cloud-kubernetes-istio module into the application classpath a new profile will be added to the application, if the application is running inside a Kubernetes Cluster with Istio installed. Then you can use spring @Profile("istio") annotations into your Beans and @Configuration's.

The Istio awareness module uses the me.snowdrop:istio-client to interact with Istio APIs enabling us to discover traffic rules, circuit breakers, etc. -Making it easy for our Spring Boot applications to consume this data to dynamically configure themselves according the environment.

7. Pod Health Indicator

Spring Boot uses HealthIndicator to expose info about the health of an application. -That makes it really useful for exposing health related information to the user and are also a good fit for use as readiness probes.

The Kubernetes health indicator which is part of the core module exposes the following info:

  • pod name, ip address, namespace, service account, node name and its ip address
  • flag that indicates if the Spring Boot application is internal or external to Kubernetes

8. Leader Election

<TBD>

9. Security Configurations inside Kubernetes

9.1 Namespace

Most of the components provided in this project need to know the namespace. For Kubernetes (1.3+) the namespace is made available to pod as part of the service account secret and automatically detected by the client. +Making it easy for our Spring Boot applications to consume this data to dynamically configure themselves according the environment.

8. Pod Health Indicator

Spring Boot uses HealthIndicator to expose info about the health of an application. +That makes it really useful for exposing health related information to the user and are also a good fit for use as readiness probes.

The Kubernetes health indicator which is part of the core module exposes the following info:

  • pod name, ip address, namespace, service account, node name and its ip address
  • flag that indicates if the Spring Boot application is internal or external to Kubernetes

9. Leader Election

<TBD>

10. Security Configurations inside Kubernetes

10.1 Namespace

Most of the components provided in this project need to know the namespace. For Kubernetes (1.3+) the namespace is made available to pod as part of the service account secret and automatically detected by the client. For earlier version it needs to be specified as an env var to the pod. A quick way to do this is:

env:
 - name: "KUBERNETES_NAMESPACE"
   valueFrom:
     fieldRef:
-      fieldPath: "metadata.namespace"

9.2 Service Account

For distros of Kubernetes that support more fine-grained role-based access within the cluster, you need to make sure a pod that runs with spring-cloud-kubernetes has access to the Kubernetes API. -For any service accounts you assign to a deployment/pod, you need to make sure it has the correct roles. For example, you can add cluster-reader permissions to your default service account depending on the project you’re in:

10. Examples

Spring Cloud Kubernetes tries to make it transparent for your applications to consume Kubernetes Native Services + fieldPath: "metadata.namespace"

10.2 Service Account

For distros of Kubernetes that support more fine-grained role-based access within the cluster, you need to make sure a pod that runs with spring-cloud-kubernetes has access to the Kubernetes API. +For any service accounts you assign to a deployment/pod, you need to make sure it has the correct roles. For example, you can add cluster-reader permissions to your default service account depending on the project you’re in:

11. Examples

Spring Cloud Kubernetes tries to make it transparent for your applications to consume Kubernetes Native Services following the Spring Cloud interfaces.

In your applications, you need to add the spring-cloud-kubernetes-discovery dependency to your classpath and remove any other dependency that contains a DiscoveryClient implementation (ie. Eureka Discovery Client). -The same applies for PropertySourceLocator, where you need to add to the classpath the spring-cloud-kubernetes-config and remove any other dependency that contains a PropertySourceLocator implementation (ie. Config Server Client).

The following projects highlight the usage of these dependencies and demonstrate how these libraries can be used from any Spring Boot application.

List of examples using these projects:

11. Other Resources

Here you can find other resources such as presentations(slides) and videos about Spring Cloud Kubernetes.

Please feel free to submit other resources via PR to this repository.

12. Building

12.1 Basic Compile and Test

To build the source you will need to install JDK 1.7.

Spring Cloud uses Maven for most build-related activities, and you +The same applies for PropertySourceLocator, where you need to add to the classpath the spring-cloud-kubernetes-config and remove any other dependency that contains a PropertySourceLocator implementation (ie. Config Server Client).

The following projects highlight the usage of these dependencies and demonstrate how these libraries can be used from any Spring Boot application.

List of examples using these projects:

12. Other Resources

Here you can find other resources such as presentations(slides) and videos about Spring Cloud Kubernetes.

Please feel free to submit other resources via PR to this repository.

13. Building

13.1 Basic Compile and Test

To build the source you will need to install JDK 1.7.

Spring Cloud uses Maven for most build-related activities, and you should be able to get off the ground quite quickly by cloning the project you are interested in and typing

$ ./mvnw install
[Note]Note

You can also install Maven (>=3.3.3) yourself and run the mvn command in place of ./mvnw in the examples below. If you do that you also @@ -274,18 +285,18 @@ in Docker containers. See the README in the scripts demo repository for specific instructions about the common cases of mongo, rabbit and redis.

[Note]Note

If all else fails, build with the command from .travis.yml (usually -./mvnw install).

12.2 Documentation

The spring-cloud-build module has a "docs" profile, and if you switch +./mvnw install).

13.2 Documentation

The spring-cloud-build module has a "docs" profile, and if you switch that on it will try to build asciidoc sources from src/main/asciidoc. As part of that process it will look for a README.adoc and process it by loading all the includes, but not parsing or rendering it, just copying it to ${main.basedir} (defaults to ${basedir}, i.e. the root of the project). If there are any changes in the README it will then show up after a Maven build as -a modified file in the correct place. Just commit it and push the change.

12.3 Working with the code

If you don’t have an IDE preference we would recommend that you use +a modified file in the correct place. Just commit it and push the change.

13.3 Working with the code

If you don’t have an IDE preference we would recommend that you use Spring Tools Suite or Eclipse when working with the code. We use the m2eclipse eclipse plugin for maven support. Other IDEs and tools -should also work without issue as long as they use Maven 3.3.3 or better.

12.3.1 Importing into eclipse with m2eclipse

We recommend the m2eclipse eclipse plugin when working with +should also work without issue as long as they use Maven 3.3.3 or better.

13.3.1 Importing into eclipse with m2eclipse

We recommend the m2eclipse eclipse plugin when working with eclipse. If you don’t already have m2eclipse installed it is available from the "eclipse marketplace".

[Note]Note

Older versions of m2e do not support Maven 3.3, so once the projects are imported into Eclipse you will also need to tell @@ -294,20 +305,20 @@ see many different errors related to the POMs in the projects, check that you have an up to date installation. If you can’t upgrade m2e, add the "spring" profile to your settings.xml. Alternatively you can copy the repository settings from the "spring" profile of the parent -pom into your settings.xml.

12.3.2 Importing into eclipse without m2eclipse

If you prefer not to use m2eclipse you can generate eclipse project metadata using the +pom into your settings.xml.

13.3.2 Importing into eclipse without m2eclipse

If you prefer not to use m2eclipse you can generate eclipse project metadata using the following command:

$ ./mvnw eclipse:eclipse

The generated eclipse projects can be imported by selecting import existing projects -from the file menu.

13. Contributing

Spring Cloud is released under the non-restrictive Apache 2.0 license, +from the file menu.

14. Contributing

Spring Cloud is released under the non-restrictive Apache 2.0 license, and follows a very standard Github development process, using Github tracker for issues and merging pull requests into master. If you want to contribute even something trivial please do not hesitate, but -follow the guidelines below.

13.1 Sign the Contributor License Agreement

Before we accept a non-trivial patch or pull request we will need you to sign the +follow the guidelines below.

14.1 Sign the Contributor License Agreement

Before we accept a non-trivial patch or pull request we will need you to sign the Contributor License Agreement. Signing the contributor’s agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. Active contributors might be asked to join the core team, and -given the ability to merge pull requests.

13.2 Code of Conduct

This project adheres to the Contributor Covenant code of +given the ability to merge pull requests.

14.2 Code of Conduct

This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report -unacceptable behavior to spring-code-of-conduct@pivotal.io.

13.3 Code Conventions and Housekeeping

None of these is essential for a pull request, but they will all help. They can also be +unacceptable behavior to spring-code-of-conduct@pivotal.io.

14.3 Code Conventions and Housekeeping

None of these is essential for a pull request, but they will all help. They can also be added after the original pull request but before a merge.

  • Use the Spring Framework code format conventions. If you use Eclipse you can import formatter settings using the eclipse-code-formatter.xml file from the @@ -321,7 +332,7 @@ in the project)
  • Add yourself as an Add some Javadocs and, if you change the namespace, some XSD doc elements.
  • A few unit tests would help a lot as well — someone has to do it.
  • If no-one else is using your branch, please rebase it against the current master (or other target branch in the main project).
  • When writing a commit message please follow these conventions, if you are fixing an existing issue please add Fixes gh-XXXX at the end of the commit -message (where XXXX is the issue number).

13.4 Checkstyle

Spring Cloud Build comes with a set of checkstyle rules. You can find them in the spring-cloud-build-tools module. The most notable files under the module are:

spring-cloud-build-tools/.  +message (where XXXX is the issue number).

14.4 Checkstyle

Spring Cloud Build comes with a set of checkstyle rules. You can find them in the spring-cloud-build-tools module. The most notable files under the module are:

spring-cloud-build-tools/. 

└── src
     ├── checkstyle
     │   └── checkstyle-suppressions.xml 1
@@ -329,7 +340,7 @@ message (where XXXX is the issue number).
2    └── checkstyle.xml 3

-

3

Default Checkstyle rules

2

File header setup

1

Default suppression rules

13.4.1 Checkstyle configuration

Checkstyle rules are disabled by default. To add checkstyle to your project just define the following properties and plugins.

pom.xml.  +

3

Default Checkstyle rules

2

File header setup

1

Default suppression rules

14.4.1 Checkstyle configuration

Checkstyle rules are disabled by default. To add checkstyle to your project just define the following properties and plugins.

pom.xml. 

<properties>
 <maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError> 1
         <maven-checkstyle-plugin.failsOnViolation>true
@@ -369,7 +380,7 @@ message (where XXXX is the issue number).

It’s advisable to copy the ${spring-cloud-build.rootFolder}/.editorconfig and ${spring-cloud-build.rootFolder}/.springformat to your project. That way, some default formatting rules will be applied. You can do so by running this script:

$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig
-$ touch .springformat

13.5 IDE setup

13.5.1 Intellij IDEA

In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.

spring-cloud-build-tools/.  +$ touch .springformat

14.5 IDE setup

14.5.1 Intellij IDEA

In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.

spring-cloud-build-tools/. 

└── src
     ├── checkstyle
     │   └── checkstyle-suppressions.xml 1
@@ -380,4 +391,4 @@ $ touch .springformat
4       └── Intellij_Spring_Boot_Java_Conventions.xml 5

-

3

Default Checkstyle rules

2

File header setup

1

Default suppression rules

4

Project defaults for Intellij that apply most of Checkstyle rules

5

Project style conventions for Intellij that apply most of Checkstyle rules

Figure 13.1. Code style

Code style

Go to FileSettingsEditorCode style. There click on the icon next to the Scheme section. There, click on the Import Scheme value and pick the Intellij IDEA code style XML option. Import the spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml file.

Figure 13.2. Inspection profiles

Code style

Go to FileSettingsEditorInspections. There click on the icon next to the Profile section. There, click on the Import Profile and import the spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml file.

Checkstyle. To have Intellij work with Checkstyle, you have to install the Checkstyle plugin. It’s advisable to also install the Assertions2Assertj to automatically convert the JUnit assertions

Checkstyle

Go to FileSettingsOther settingsCheckstyle. There click on the + icon in the Configuration file section. There, you’ll have to define where the checkstyle rules should be picked from. In the image above, we’ve picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build’s GitHub repository (e.g. for the checkstyle.xml : https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml). We need to provide the following variables:

[Important]Important

Remember to set the Scan Scope to All sources since we apply checkstyle rules for production and test sources.

\ No newline at end of file +

3

Default Checkstyle rules

2

File header setup

1

Default suppression rules

4

Project defaults for Intellij that apply most of Checkstyle rules

5

Project style conventions for Intellij that apply most of Checkstyle rules

Figure 14.1. Code style

Code style

Go to FileSettingsEditorCode style. There click on the icon next to the Scheme section. There, click on the Import Scheme value and pick the Intellij IDEA code style XML option. Import the spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml file.

Figure 14.2. Inspection profiles

Code style

Go to FileSettingsEditorInspections. There click on the icon next to the Profile section. There, click on the Import Profile and import the spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml file.

Checkstyle. To have Intellij work with Checkstyle, you have to install the Checkstyle plugin. It’s advisable to also install the Assertions2Assertj to automatically convert the JUnit assertions

Checkstyle

Go to FileSettingsOther settingsCheckstyle. There click on the + icon in the Configuration file section. There, you’ll have to define where the checkstyle rules should be picked from. In the image above, we’ve picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build’s GitHub repository (e.g. for the checkstyle.xml : https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml). We need to provide the following variables:

[Important]Important

Remember to set the Scan Scope to All sources since we apply checkstyle rules for production and test sources.

\ No newline at end of file diff --git a/spring-cloud-kubernetes.xml b/spring-cloud-kubernetes.xml index a6bdcba1..9caf4db7 100644 --- a/spring-cloud-kubernetes.xml +++ b/spring-cloud-kubernetes.xml @@ -11,6 +11,59 @@ Spring Cloud Kubernetes provide Spring Cloud common interfaces implementations to consume Kubernetes native services. The main objective of the projects provided in this repository is to facilitate the integration of Spring Cloud/Spring Boot applications running inside Kubernetes. + +Starters +Starters are convenient dependency descriptors you can include in your +application. Include a starter to get the dependencies and Spring Boot +auto-configuration for a feature set. + + + + + + +Starter +Features + + + + +<dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-kubernetes</artifactId> +</dependency> +Discovery Client implementation that +resolves service names to Kubernetes Services. + + +<dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-kubernetes-config</artifactId> +</dependency> +Load application properties from Kubernetes +ConfigMaps and Secrets. +Reload application properties when a ConfigMap or +Secret changes. + + +<dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId> +</dependency> +Ribbon client-side load balancer with +server list obtained from Kubernetes Endpoints. + + +<dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-kubernetes-all</artifactId> +</dependency> +All Spring Cloud Kubernetes features. + + + + + DiscoveryClient for Kubernetes This project provides an implementation of Discovery Client @@ -19,12 +72,6 @@ This allows you to query Kubernetes endpoints (see http, https addresses that a client can access from a Spring Boot application running as a pod. This discovery feature is also used by the Spring Cloud Kubernetes Ribbon project to fetch the list of the endpoints defined for an application to be load balanced. -This is something that you get for free just by adding the following dependency inside your project: -<dependency> - <groupId>org.springframework.cloud</groupId> - <artifactId>spring-cloud-starter-kubernetes</artifactId> - <version>${latest.version}</version> -</dependency> To enable loading of the DiscoveryClient, add @EnableDiscoveryClient to the according configuration or application class like this: @SpringBootApplication @EnableDiscoveryClient @@ -539,12 +586,6 @@ feature in order to automatically discover at which endpoint(s) it can reach a g implemented within the [spring-cloud-kubernetes-ribbon](spring-cloud-kubernetes-ribbon/pom.xml) project where a Kubernetes client will populate a Ribbon ServerList containing information about such endpoints. -The implementation is part of the following starter that you can use by adding its dependency to your pom file: -<dependency> - <groupId>org.springframework.cloud</groupId> - <artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId> - <version>${latest.version}</version> -</dependency> When the list of the endpoints is populated, the Kubernetes client will search the registered endpoints living in the current namespace/project matching the service name defined using the Ribbon Client annotation: @RibbonClient(name = "name-service")