diff --git a/multi/multi__building.html b/multi/multi__building.html index 191a94ef..d5d5fb5b 100644 --- a/multi/multi__building.html +++ b/multi/multi__building.html @@ -1,6 +1,6 @@ - 8. Building

8. Building

8.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 + 11. Building

11. Building

11.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).

8.2 Documentation

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

11.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.

8.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.

11.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.

8.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.

11.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.

8.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.

11.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 03c2b1bd..5cff48da 100644 --- a/multi/multi__contributing.html +++ b/multi/multi__contributing.html @@ -1,17 +1,17 @@ - 9. Contributing

9. Contributing

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

12. 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.

9.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.

12.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.

9.2 Code of Conduct

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

12.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.

9.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.

12.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,4 +25,4 @@ 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).
\ No newline at end of file +message (where XXXX is the issue number).
\ No newline at end of file diff --git a/multi/multi__discoveryclient_for_kubernetes.html b/multi/multi__discoveryclient_for_kubernetes.html index 89aa2d02..34ccae9f 100644 --- a/multi/multi__discoveryclient_for_kubernetes.html +++ b/multi/multi__discoveryclient_for_kubernetes.html @@ -1,6 +1,6 @@ - Part I. DiscoveryClient for Kubernetes

Part I. DiscoveryClient for Kubernetes

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

2. 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 @@ -17,4 +17,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 50e8eb57..182f410b 100644 --- a/multi/multi__examples.html +++ b/multi/multi__examples.html @@ -1,3 +1,5 @@ - Part VIII. Examples

Part VIII. Examples

List of examples using these projects:

<TBD>

\ No newline at end of file + 9. Examples

9. 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 diff --git a/multi/multi__kubernetes_awareness.html b/multi/multi__kubernetes_awareness.html index 39a0763a..394f1643 100644 --- a/multi/multi__kubernetes_awareness.html +++ b/multi/multi__kubernetes_awareness.html @@ -1,9 +1,11 @@ - Part IV. Kubernetes Awareness

Part IV. Kubernetes Awareness

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

5. Kubernetes 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](https://github.com/fabric8io/kubernetes-client) which is a fluent DSL able to -communicate using http protocol to the REST API of Kubernetes Server.

\ No newline at end of file +communicate using http protocol to the REST API of Kubernetes Server.

5.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).

\ No newline at end of file diff --git a/multi/multi__kubernetes_propertysource_implementations.html b/multi/multi__kubernetes_propertysource_implementations.html index ec0bb4ea..c1acd7c7 100644 --- a/multi/multi__kubernetes_propertysource_implementations.html +++ b/multi/multi__kubernetes_propertysource_implementations.html @@ -1,6 +1,210 @@ - Part II. Kubernetes PropertySource implementations

Part II. Kubernetes PropertySource implementations

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

3. 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.

\ No newline at end of file +variables.

3.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 +observed `ConfigMap`s.

The default behavior is to create a ConfigMapPropertySource based on a Kubernetes ConfigMap which has metadata.name of either the name of +your Spring application (as defined by its spring.application.name property) or a custom name defined within the +bootstrap.properties file under the following key spring.cloud.kubernetes.config.name.

However, more advanced configuration are possible where multiple ConfigMaps can be used +This is made possible by the spring.cloud.kubernetes.config.sources list. +For example one could define the following ConfigMaps

spring:
+  application:
+    name: cloud-k8s-app
+  cloud:
+    kubernetes:
+      config:
+        name: default-name
+        namespace: default-namespace
+        sources:
+         # Spring Cloud Kubernetes will lookup a ConfigMap named c1 in namespace default-namespace
+         - name: c1
+         # Spring Cloud Kubernetes will lookup a ConfigMap named default-name in whatever namespace n2
+         - namespace: n2
+         # Spring Cloud Kubernetes will lookup a ConfigMap named c3 in namespace n3
+         - namespace: n3
+           name: c3

In the example above, it spring.cloud.kubernetes.config.namespace had not been set, +then the ConfigMap named c1 would be looked up in the namespace that the application runs

Any matching ConfigMap that is found, will be processed as follows:

  • apply individual configuration properties.
  • apply as yaml the content of any property named application.yaml
  • apply as properties file the content of any property named application.properties

The single exception to the aforementioned flow is when the ConfigMap contains a single key that indicates +the file is a YAML or Properties file. In that case the name of the key does NOT have to be application.yaml or +application.properties (it can be anything) and the value of the property will be treated correctly. +This features facilitates the use case where the ConfigMap was created using something like:

kubectl create configmap game-config --from-file=/path/to/app-config.yaml

Example:

Let’s assume that we have a Spring Boot application named demo that uses properties to read its thread pool +configuration.

  • pool.size.core
  • pool.size.maximum

This can be externalized to config map in yaml format:

kind: ConfigMap
+apiVersion: v1
+metadata:
+  name: demo
+data:
+  pool.size.core: 1
+  pool.size.max: 16

Individual properties work fine for most cases but sometimes embedded yaml is more convenient. In this case we will +use a single property named application.yaml to embed our yaml:

 ```yaml
+kind: ConfigMap
+apiVersion: v1
+metadata:
+  name: demo
+data:
+  application.yaml: |-
+    pool:
+      size:
+        core: 1
+        max:16
The following also works:
+
+ ```yaml
+kind: ConfigMap
+apiVersion: v1
+metadata:
+  name: demo
+data:
+  custom-name.yaml: |-
+    pool:
+      size:
+        core: 1
+        max:16

Spring Boot applications can also be configured differently depending on active profiles which will be merged together +when the ConfigMap is read. It is possible to provide different property values for different profiles using an +application.properties|yaml property, specifying profile-specific values each in their own document +(indicated by the --- sequence) as follows:

kind: ConfigMap
+apiVersion: v1
+metadata:
+  name: demo
+data:
+  application.yml: |-
+    greeting:
+      message: Say Hello to the World
+    farewell:
+      message: Say Goodbye
+    ---
+    spring:
+      profiles: development
+    greeting:
+      message: Say Hello to the Developers
+    farewell:
+      message: Say Goodbye to the Developers
+    ---
+    spring:
+      profiles: production
+    greeting:
+      message: Say Hello to the Ops

In the above case, the configuration loaded into your Spring Application with the development profile will be:

  greeting:
+    message: Say Hello to the Developers
+  farewell:
+    message: Say Goodbye to the Developers

whereas if the production profile is active, the configuration will be:

  greeting:
+    message: Say Hello to the Ops
+  farewell:
+    message: Say Goodbye

If both profiles are active, the property which appears last within the configmap will overwrite preceding values.

To tell to Spring Boot which profile should be enabled at bootstrap, a system property can be passed to the Java +command launching your Spring Boot application using an env variable that you will define with the OpenShift +DeploymentConfig or Kubernetes ReplicationConfig resource file as follows:

apiVersion: v1
+kind: DeploymentConfig
+spec:
+  replicas: 1
+  ...
+    spec:
+      containers:
+      - env:
+        - name: JAVA_APP_DIR
+          value: /deployments
+        - name: JAVA_OPTIONS
+          value: -Dspring.profiles.active=developer

Notes: +- check the security configuration section, to access config maps from inside a pod you need to have the correct +Kubernetes service accounts, roles and role bindings.

Table 3.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


3.2 Secrets PropertySource

Kubernetes has the notion of [Secrets](https://kubernetes.io/docs/concepts/configuration/secret/) 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 recommend that containers share secrets via mounted volumes. Otherwise proper RBAC security configurations must be provided + to make sure that unauthorized access to Secrets occurs.

If the secrets are found their data is made available to the application.

Example:

Let’s assume that we have a spring boot application named demo that uses properties to read its database +configuration. We can create a Kubernetes secret using the following command:

oc create secret generic db-secret --from-literal=username=user --from-literal=password=p455w0rd

This would create the following secret (shown using oc get secrets db-secret -o yaml):

apiVersion: v1
+data:
+  password: cDQ1NXcwcmQ=
+  username: dXNlcg==
+kind: Secret
+metadata:
+  creationTimestamp: 2017-07-04T09:15:57Z
+  name: db-secret
+  namespace: default
+  resourceVersion: "357496"
+  selfLink: /api/v1/namespaces/default/secrets/db-secret
+  uid: 63c89263-6099-11e7-b3da-76d6186905a8
+type: Opaque

Note that the data contains Base64-encoded versions of the literal provided by the create command.

This secret can then be used by your application for example by exporting the secret’s value as environment variables:

apiVersion: v1
+kind: Deployment
+metadata:
+  name: ${project.artifactId}
+spec:
+   template:
+     spec:
+       containers:
+         - env:
+            - name: DB_USERNAME
+              valueFrom:
+                 secretKeyRef:
+                   name: db-secret
+                   key: username
+            - name: DB_PASSWORD
+              valueFrom:
+                 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 3.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

3.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): +- refresh (default): only configuration beans annotated with @ConfigurationProperties or @RefreshScope are reloaded. +This reload level leverages the refresh feature of Spring Cloud Context. +- restart_context: the whole Spring ApplicationContext is gracefully restarted. Beans are recreated with the new configuration. +- shutdown: the Spring ApplicationContext is shut down to activate a restart of the container. + When using this level, make sure that the lifecycle of all non-daemon threads is bound to the ApplicationContext + and that a replication controller or replica set is configured to restart the pod.

Example:

Assuming that the reload feature is enabled with default settings (refresh mode), the following bean will be refreshed when the config map changes:

@Configuration
+@ConfigurationProperties(prefix = "bean")
+public class MyConfig {
+
+    private String message = "a message that can be changed live";
+
+    // getter and setters
+
+}

A way to see that changes effectively happen is creating another bean that prints the message periodically.

@Component
+public class MyBean {
+
+    @Autowired
+    private MyConfig config;
+
+    @Scheduled(fixedDelay = 5000)
+    public void hello() {
+        System.out.println("The message is: " + config.getMessage());
+    }
+}

The message printed by the application can be changed using a ConfigMap as follows:

apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: reload-example
+data:
+  application.properties: |-
+    bean.message=Hello World!

Any change to the property named bean.message in the ConfigMap associated to the pod will be reflected in the +output. More generally speaking, changes associated to properties prefixed with the value defined by the prefix +field of the @ConfigurationProperties annotation will be detected and reflected in the application. +[Associating a ConfigMap to a pod](#configmap-propertysource) is explained above.

The full example is available in [spring-cloud-kubernetes-reload-example](spring-cloud-kubernetes-examples/kubernetes-reload-example).

The reload feature supports two operating modes: +- event (default): watches for changes in config maps or secrets using the Kubernetes API (web socket). +Any event will produce a re-check on the configuration and a reload in case of changes. +The view role on the service account is required in order to listen for config map changes. A higher level role (eg. edit) is required for secrets +(secrets are not monitored by default). +- 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 3.3. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.reload.period

Long

15000

The period in milliseconds 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 diff --git a/multi/multi__leader_election.html b/multi/multi__leader_election.html index 5fba8cfe..fbda3a02 100644 --- a/multi/multi__leader_election.html +++ b/multi/multi__leader_election.html @@ -1,3 +1,3 @@ - Part VI. Leader Election

Part VI. Leader Election

<TBD>

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

7. Leader Election

<TBD>

\ No newline at end of file diff --git a/multi/multi__other_resources.html b/multi/multi__other_resources.html index 85a6b97a..b63e2558 100644 --- a/multi/multi__other_resources.html +++ b/multi/multi__other_resources.html @@ -1,3 +1,3 @@ - Part IX. Other Resources

Part IX. Other Resources

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

10. 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 d00d7dbe..096378c8 100644 --- a/multi/multi__pod_health_indicator.html +++ b/multi/multi__pod_health_indicator.html @@ -1,4 +1,4 @@ - Part V. Pod Health Indicator

Part V. 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 + 6. Pod Health Indicator

6. 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 ead39f1d..40b28adb 100644 --- a/multi/multi__ribbon_discovery_in_kubernetes.html +++ b/multi/multi__ribbon_discovery_in_kubernetes.html @@ -1,12 +1,12 @@ - Part III. Ribbon discovery in Kubernetes

Part III. Ribbon discovery in Kubernetes

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

4. 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-netflix</artifactId>
+    <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")

You can configure Ribbon’s behavior by providing properties in your application.properties (via your application’s @@ -18,4 +18,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 01d8c4d4..86836a78 100644 --- a/multi/multi__security_configurations_inside_kubernetes.html +++ b/multi/multi__security_configurations_inside_kubernetes.html @@ -1,3 +1,9 @@ - Part VII. Security Configurations inside Kubernetes

Part VII. Security Configurations inside Kubernetes

\ No newline at end of file + 8. Security Configurations inside Kubernetes

8. Security Configurations inside Kubernetes

8.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"

8.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__why_do_you_need_spring_cloud_kubernetes.html b/multi/multi__why_do_you_need_spring_cloud_kubernetes.html index ae3d1a04..15ae9e8b 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 0ce2ca8c..12bce477 100644 --- a/multi/multi_spring-cloud-kubernetes.html +++ b/multi/multi_spring-cloud-kubernetes.html @@ -1,3 +1,3 @@ - Spring Cloud Kubernetes

Spring Cloud Kubernetes


\ No newline at end of file + Spring Cloud Kubernetes

Spring Cloud Kubernetes


\ No newline at end of file diff --git a/single/spring-cloud-kubernetes.html b/single/spring-cloud-kubernetes.html index 274eb923..216f843f 100644 --- a/single/spring-cloud-kubernetes.html +++ b/single/spring-cloud-kubernetes.html @@ -1,7 +1,7 @@ - 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.

Part I. 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. 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 @@ -18,10 +18,10 @@ 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.

Part II. 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.

3. 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.

2. ConfigMap PropertySource

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

3.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 @@ -123,13 +123,14 @@ command launching your Spring Boot application using an env variable that you wi - name: JAVA_OPTIONS value: -Dspring.profiles.active=developer

Notes: - check the security configuration section, to access config maps from inside a pod you need to have the correct -Kubernetes service accounts, roles and role bindings.

Table 2.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


3. Secrets PropertySource

Kubernetes has the notion of [Secrets](https://kubernetes.io/docs/concepts/configuration/secret/) for storing +Kubernetes service accounts, roles and role bindings.

Table 3.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


3.2 Secrets PropertySource

Kubernetes has the notion of [Secrets](https://kubernetes.io/docs/concepts/configuration/secret/) 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 recommend that containers share secrets via mounted volumes.

If the secrets are found their data is made available to the application.

Example:

Let’s assume that we have a spring boot application named demo that uses properties to read its database + and it is recommend that containers share secrets via mounted volumes. Otherwise proper RBAC security configurations must be provided + to make sure that unauthorized access to Secrets occurs.

If the secrets are found their data is made available to the application.

Example:

Let’s assume that we have a spring boot application named demo that uses properties to read its database configuration. We can create a Kubernetes secret using the following command:

oc create secret generic db-secret --from-literal=username=user --from-literal=password=p455w0rd

This would create the following secret (shown using oc get secrets db-secret -o yaml):

apiVersion: v1
 data:
   password: cDQ1NXcwcmQ=
@@ -172,13 +173,13 @@ configuration. We can create a Kubernetes secret using the following command:

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

Table 3.1. 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: +`

Table 3.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. 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

3.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): @@ -222,15 +223,15 @@ 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.1. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.reload.period

Long

15000

The period in milliseconds 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 3.3. Properties:

NameTypeDefaultDescription

spring.cloud.kubernetes.reload.period

Long

15000

The period in milliseconds 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.

Part III. 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.

4. 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-netflix</artifactId>
+    <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")

You can configure Ribbon’s behavior by providing properties in your application.properties (via your application’s @@ -242,22 +243,24 @@ 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.

Part IV. Kubernetes 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.

5. Kubernetes 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](https://github.com/fabric8io/kubernetes-client) which is a fluent DSL able to -communicate using http protocol to the REST API of Kubernetes Server.

5. 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.

5.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).

Part V. 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

Part VI. Leader Election

<TBD>

Part VII. Security Configurations inside Kubernetes

6. 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. +within the Kubernetes platform (e.g. different dev and prod configuration).

6. 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

7. Leader Election

<TBD>

8. Security Configurations inside Kubernetes

8.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"

7. 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:

Part VIII. Examples

List of examples using these projects:

<TBD>

Part IX. Other Resources

8. Building

8.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 + fieldPath: "metadata.namespace"

8.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:

9. 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:

10. 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.

11. Building

11.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 @@ -279,18 +282,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).

8.2 Documentation

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

11.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.

8.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.

11.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.

8.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.

11.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 @@ -299,20 +302,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.

8.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.

11.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.

9. Contributing

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

12. 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.

9.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.

12.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.

9.2 Code of Conduct

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

12.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.

9.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.

12.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 @@ -326,4 +329,4 @@ 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).
\ No newline at end of file +message (where XXXX is the issue number). \ No newline at end of file diff --git a/spring-cloud-kubernetes.xml b/spring-cloud-kubernetes.xml index 9586e96a..ad161496 100644 --- a/spring-cloud-kubernetes.xml +++ b/spring-cloud-kubernetes.xml @@ -11,9 +11,8 @@ 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. - + DiscoveryClient for Kubernetes - This project provides an implementation of Discovery Client for Kubernetes. This allows you to query Kubernetes endpoints (see services) by name. @@ -41,17 +40,14 @@ private DiscoveryClient discoveryClient; 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. - - - + + 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. - - +
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. @@ -250,8 +246,8 @@ Kubernetes service accounts, roles and role bindings. - - +
+
Secrets PropertySource Kubernetes has the notion of [Secrets](https://kubernetes.io/docs/concepts/configuration/secret/) for storing sensitive data such as password, OAuth tokens, etc. This project provides integration with Secrets to make secrets @@ -261,7 +257,8 @@ accessible by Spring Boot applications. This feature can be explicitly enabled/d 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 recommend that containers share secrets via mounted volumes. + and it is recommend that containers share secrets via mounted volumes. Otherwise proper RBAC security configurations must be provided + to make sure that unauthorized access to Secrets occurs. If the secrets are found their data is made available to the application. Example: Let’s assume that we have a spring boot application named demo that uses properties to read its database @@ -393,8 +390,8 @@ spec: - 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 - - +
+
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 @@ -513,11 +510,10 @@ This means, for example, that using polling on file mounted secret sources does 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. +
-
- + 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 @@ -526,7 +522,7 @@ 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-netflix</artifactId> + <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 @@ -564,11 +560,9 @@ the KubernetesNamespace key, remembering in both instances to Note: The Ribbon discovery client can be disabled by setting this key within the application properties file spring.cloud.kubernetes.ribbon.enabled=false. - - - + + Kubernetes 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 @@ -576,17 +570,15 @@ of the modules part of this project. It is not required to deploy it in Kubernet as the code of the project relies on the [Fabric8 Kubernetes Java client](https://github.com/fabric8io/kubernetes-client) which is a fluent DSL able to communicate using http protocol to the REST API of Kubernetes Server. - - +
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). +
-
- + 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: @@ -598,17 +590,14 @@ That makes it really useful for exposing health related information to the user flag that indicates if the Spring Boot application is internal or external to Kubernetes - - - + + Leader Election - <TBD> - - - + + Security Configurations inside Kubernetes - +
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: @@ -617,22 +606,58 @@ For earlier version it needs to be specified as an env var to the pod. A quick w valueFrom: fieldRef: fieldPath: "metadata.namespace" - - +
+
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: +
-
- + 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: -<TBD> - - - + + +Spring Cloud Kubernetes Examples: the ones located inside this repository. + + +Spring Cloud Kubernetes Full Example: Minions and Boss + + +Minion + + +Boss + + +Spring Cloud Kubernetes Full Example: SpringOne Platform Tickets Service + + +Spring Cloud Gateway with Spring Cloud Kubernetes Discovery and Config + + +Spring Boot Admin with Spring Cloud Kubernetes Discovery and Config + + + + Other Resources +Here you can find other resources such as presentations(slides) and videos about Spring Cloud Kubernetes. + + +S1P Spring Cloud on PKS + + +Spring Cloud, Docker, Kubernetes → London Java Community July 2018 + + +Please feel free to submit other resources via PR to this repository. + Building
@@ -785,5 +810,4 @@ message (where XXXX is the issue number).
-
\ No newline at end of file