1.0.0.RC2
+Pick The Documentation Option
+-
+
- + + +
- + + +
diff --git a/spring-cloud-kubernetes/1.0.0.RC2/css/highlight.css b/spring-cloud-kubernetes/1.0.0.RC2/css/highlight.css new file mode 100644 index 00000000..ffefef72 --- /dev/null +++ b/spring-cloud-kubernetes/1.0.0.RC2/css/highlight.css @@ -0,0 +1,35 @@ +/* + code highlight CSS resemblign the Eclipse IDE default color schema + @author Costin Leau +*/ + +.hl-keyword { + color: #7F0055; + font-weight: bold; +} + +.hl-comment { + color: #3F5F5F; + font-style: italic; +} + +.hl-multiline-comment { + color: #3F5FBF; + font-style: italic; +} + +.hl-tag { + color: #3F7F7F; +} + +.hl-attribute { + color: #7F007F; +} + +.hl-value { + color: #2A00FF; +} + +.hl-string { + color: #2A00FF; +} \ No newline at end of file diff --git a/spring-cloud-kubernetes/1.0.0.RC2/css/manual-multipage.css b/spring-cloud-kubernetes/1.0.0.RC2/css/manual-multipage.css new file mode 100644 index 00000000..0c484531 --- /dev/null +++ b/spring-cloud-kubernetes/1.0.0.RC2/css/manual-multipage.css @@ -0,0 +1,9 @@ +@IMPORT url("manual.css"); + +body.firstpage { + background: url("../images/background.png") no-repeat center top; +} + +div.part h1 { + border-top: none; +} diff --git a/spring-cloud-kubernetes/1.0.0.RC2/css/manual-singlepage.css b/spring-cloud-kubernetes/1.0.0.RC2/css/manual-singlepage.css new file mode 100644 index 00000000..4a7fd140 --- /dev/null +++ b/spring-cloud-kubernetes/1.0.0.RC2/css/manual-singlepage.css @@ -0,0 +1,6 @@ +@IMPORT url("manual.css"); + +body { + background: url("../images/background.png") no-repeat center top; +} + diff --git a/spring-cloud-kubernetes/1.0.0.RC2/css/manual.css b/spring-cloud-kubernetes/1.0.0.RC2/css/manual.css new file mode 100644 index 00000000..0ecbe2e8 --- /dev/null +++ b/spring-cloud-kubernetes/1.0.0.RC2/css/manual.css @@ -0,0 +1,344 @@ +@IMPORT url("highlight.css"); + +html { + padding: 0pt; + margin: 0pt; +} + +body { + color: #333333; + margin: 15px 30px; + font-family: Helvetica, Arial, Freesans, Clean, Sans-serif; + line-height: 1.6; + -webkit-font-smoothing: antialiased; +} + +code { + font-size: 16px; + font-family: Consolas, "Liberation Mono", Courier, monospace; +} + +:not(a)>code { + color: #6D180B; +} + +:not(pre)>code { + background-color: #F2F2F2; + border: 1px solid #CCCCCC; + border-radius: 4px; + padding: 1px 3px 0; + text-shadow: none; + white-space: nowrap; +} + +body>*:first-child { + margin-top: 0 !important; +} + +div { + margin: 0pt; +} + +hr { + border: 1px solid #CCCCCC; + background: #CCCCCC; +} + +h1,h2,h3,h4,h5,h6 { + color: #000000; + cursor: text; + font-weight: bold; + margin: 30px 0 10px; + padding: 0; +} + +h1,h2,h3 { + margin: 40px 0 10px; +} + +h1 { + margin: 70px 0 30px; + padding-top: 20px; +} + +div.part h1 { + border-top: 1px dotted #CCCCCC; +} + +h1,h1 code { + font-size: 32px; +} + +h2,h2 code { + font-size: 24px; +} + +h3,h3 code { + font-size: 20px; +} + +h4,h1 code,h5,h5 code,h6,h6 code { + font-size: 18px; +} + +div.book,div.chapter,div.appendix,div.part,div.preface { + min-width: 300px; + max-width: 1200px; + margin: 0 auto; +} + +p.releaseinfo { + font-weight: bold; + margin-bottom: 40px; + margin-top: 40px; +} + +div.authorgroup { + line-height: 1; +} + +p.copyright { + line-height: 1; + margin-bottom: -5px; +} + +.legalnotice p { + font-style: italic; + font-size: 14px; + line-height: 1; +} + +div.titlepage+p,div.titlepage+p { + margin-top: 0; +} + +pre { + line-height: 1.0; + color: black; +} + +a { + color: #4183C4; + text-decoration: none; +} + +p { + margin: 15px 0; + text-align: left; +} + +ul,ol { + padding-left: 30px; +} + +li p { + margin: 0; +} + +div.table { + margin: 1em; + padding: 0.5em; + text-align: center; +} + +div.table table,div.informaltable table { + display: table; + width: 100%; +} + +div.table td { + padding-left: 7px; + padding-right: 7px; +} + +.sidebar { + line-height: 1.4; + padding: 0 20px; + background-color: #F8F8F8; + border: 1px solid #CCCCCC; + border-radius: 3px 3px 3px 3px; +} + +.sidebar p.title { + color: #6D180B; +} + +pre.programlisting,pre.screen { + font-size: 15px; + padding: 6px 10px; + background-color: #F8F8F8; + border: 1px solid #CCCCCC; + border-radius: 3px 3px 3px 3px; + clear: both; + overflow: auto; + line-height: 1.4; + font-family: Consolas, "Liberation Mono", Courier, monospace; +} + +table { + border-collapse: collapse; + border-spacing: 0; + border: 1px solid #DDDDDD !important; + border-radius: 4px !important; + border-collapse: separate !important; + line-height: 1.6; +} + +table thead { + background: #F5F5F5; +} + +table tr { + border: none; + border-bottom: none; +} + +table th { + font-weight: bold; +} + +table th,table td { + border: none !important; + padding: 6px 13px; +} + +table tr:nth-child(2n) { + background-color: #F8F8F8; +} + +td p { + margin: 0 0 15px 0; +} + +div.table-contents td p { + margin: 0; +} + +div.important *,div.note *,div.tip *,div.warning *,div.navheader *,div.navfooter *,div.calloutlist * + { + border: none !important; + background: none !important; + margin: 0; +} + +div.important p,div.note p,div.tip p,div.warning p { + color: #6F6F6F; + line-height: 1.6; +} + +div.important code,div.note code,div.tip code,div.warning code { + background-color: #F2F2F2 !important; + border: 1px solid #CCCCCC !important; + border-radius: 4px !important; + padding: 1px 3px 0 !important; + text-shadow: none !important; + white-space: nowrap !important; +} + +.note th,.tip th,.warning th { + display: none; +} + +.note tr:first-child td,.tip tr:first-child td,.warning tr:first-child td + { + border-right: 1px solid #CCCCCC !important; + padding-top: 10px; +} + +div.calloutlist p,div.calloutlist td { + padding: 0; + margin: 0; +} + +div.calloutlist>table>tbody>tr>td:first-child { + padding-left: 10px; + width: 30px !important; +} + +div.important,div.note,div.tip,div.warning { + margin-left: 0px !important; + margin-right: 20px !important; + margin-top: 20px; + margin-bottom: 20px; + padding-top: 10px; + padding-bottom: 10px; +} + +div.toc { + line-height: 1.2; +} + +dl,dt { + margin-top: 1px; + margin-bottom: 0; +} + +div.toc>dl>dt { + font-size: 32px; + font-weight: bold; + margin: 30px 0 10px 0; + display: block; +} + +div.toc>dl>dd>dl>dt { + font-size: 24px; + font-weight: bold; + margin: 20px 0 10px 0; + display: block; +} + +div.toc>dl>dd>dl>dd>dl>dt { + font-weight: bold; + font-size: 20px; + margin: 10px 0 0 0; +} + +tbody.footnotes * { + border: none !important; +} + +div.footnote p { + margin: 0; + line-height: 1; +} + +div.footnote p sup { + margin-right: 6px; + vertical-align: middle; +} + +div.navheader { + border-bottom: 1px solid #CCCCCC; +} + +div.navfooter { + border-top: 1px solid #CCCCCC; +} + +.title { + margin-left: -1em; + padding-left: 1em; +} + +.title>a { + position: absolute; + visibility: hidden; + display: block; + font-size: 0.85em; + margin-top: 0.05em; + margin-left: -1em; + vertical-align: text-top; + color: black; +} + +.title>a:before { + content: "\00A7"; +} + +.title:hover>a,.title>a:hover,.title:hover>a:hover { + visibility: visible; +} + +.title:focus>a,.title>a:focus,.title:focus>a:focus { + outline: 0; +} diff --git a/spring-cloud-kubernetes/1.0.0.RC2/images/background.png b/spring-cloud-kubernetes/1.0.0.RC2/images/background.png new file mode 100644 index 00000000..15dca6fb Binary files /dev/null and b/spring-cloud-kubernetes/1.0.0.RC2/images/background.png differ diff --git a/spring-cloud-kubernetes/1.0.0.RC2/images/callouts/1.png b/spring-cloud-kubernetes/1.0.0.RC2/images/callouts/1.png new file mode 100644 index 00000000..7d473430 Binary files /dev/null and b/spring-cloud-kubernetes/1.0.0.RC2/images/callouts/1.png differ diff --git a/spring-cloud-kubernetes/1.0.0.RC2/images/callouts/2.png b/spring-cloud-kubernetes/1.0.0.RC2/images/callouts/2.png new file mode 100644 index 00000000..5d09341b Binary files /dev/null and b/spring-cloud-kubernetes/1.0.0.RC2/images/callouts/2.png differ diff --git a/spring-cloud-kubernetes/1.0.0.RC2/images/callouts/3.png b/spring-cloud-kubernetes/1.0.0.RC2/images/callouts/3.png new file mode 100644 index 00000000..ef7b7004 Binary files /dev/null and b/spring-cloud-kubernetes/1.0.0.RC2/images/callouts/3.png differ diff --git a/spring-cloud-kubernetes/1.0.0.RC2/images/caution.png b/spring-cloud-kubernetes/1.0.0.RC2/images/caution.png new file mode 100644 index 00000000..8a5e4fca Binary files /dev/null and b/spring-cloud-kubernetes/1.0.0.RC2/images/caution.png differ diff --git a/spring-cloud-kubernetes/1.0.0.RC2/images/important.png b/spring-cloud-kubernetes/1.0.0.RC2/images/important.png new file mode 100644 index 00000000..ec54df65 Binary files /dev/null and b/spring-cloud-kubernetes/1.0.0.RC2/images/important.png differ diff --git a/spring-cloud-kubernetes/1.0.0.RC2/images/logo.png b/spring-cloud-kubernetes/1.0.0.RC2/images/logo.png new file mode 100644 index 00000000..ade2ce6e Binary files /dev/null and b/spring-cloud-kubernetes/1.0.0.RC2/images/logo.png differ diff --git a/spring-cloud-kubernetes/1.0.0.RC2/images/note.png b/spring-cloud-kubernetes/1.0.0.RC2/images/note.png new file mode 100644 index 00000000..88d997b1 Binary files /dev/null and b/spring-cloud-kubernetes/1.0.0.RC2/images/note.png differ diff --git a/spring-cloud-kubernetes/1.0.0.RC2/images/tip.png b/spring-cloud-kubernetes/1.0.0.RC2/images/tip.png new file mode 100644 index 00000000..6530abb4 Binary files /dev/null and b/spring-cloud-kubernetes/1.0.0.RC2/images/tip.png differ diff --git a/spring-cloud-kubernetes/1.0.0.RC2/images/warning.png b/spring-cloud-kubernetes/1.0.0.RC2/images/warning.png new file mode 100644 index 00000000..0d5b5244 Binary files /dev/null and b/spring-cloud-kubernetes/1.0.0.RC2/images/warning.png differ diff --git a/spring-cloud-kubernetes/1.0.0.RC2/index.html b/spring-cloud-kubernetes/1.0.0.RC2/index.html new file mode 100644 index 00000000..ba6b8f04 --- /dev/null +++ b/spring-cloud-kubernetes/1.0.0.RC2/index.html @@ -0,0 +1,117 @@ + + +
+ + + + +1.0.0.RC2
+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 |
|---|---|
You can also install Maven (>=3.3.3) yourself and run the |
![]() | Note |
|---|---|
Be aware that you might need to increase the amount of memory
+available to Maven by setting a |
For hints on how to build the project look in .travis.yml if there
+is one. There should be a "script" and maybe "install" command. Also
+look at the "services" section to see if any services need to be
+running locally (e.g. mongo or rabbit). Ignore the git-related bits
+that you might find in "before_install" since they’re related to setting git
+credentials and you already have those.
The projects that require middleware generally include a
+docker-compose.yml, so consider using
+Docker Compose to run the middeware servers
+in Docker containers. See the README in the
+scripts demo
+repository for specific instructions about the common cases of mongo,
+rabbit and redis.
![]() | Note |
|---|---|
If all else fails, build with the command from |
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.
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.
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 |
|---|---|
Older versions of m2e do not support Maven 3.3, so once the
+projects are imported into Eclipse you will also need to tell
+m2eclipse to use the right profile for the projects. If you
+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 |
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.
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.
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.
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.
eclipse-code-formatter.xml file from the
+Spring
+Cloud Build project. If using IntelliJ, you can use the
+Eclipse Code Formatter
+Plugin to import the same file..java files to have a simple Javadoc class comment with at least an
+@author tag identifying you, and preferably at least a paragraph on what the class is
+for..java files (copy from existing files
+in the project)@author to the .java files that you modify substantially (more
+than cosmetic changes).Fixes gh-XXXX at the end of the commit
+message (where XXXX is the issue number).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 +@EnableDiscoveryClient +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +}
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.
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:
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.
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).
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.
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:
@EnableCircuitBreaker@HystrixCommand(fallbackMethod= does the job.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.
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:
yaml the content of any property named application.yamlapplication.propertiesThe 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.corepool.size.maximumThis 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.
Another option for using ConfigMaps, is to mount them into the Pod running the Spring Cloud Kubernetes application
+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
Table 4.1. Properties:
| Name | Type | Default | Description |
|---|---|---|---|
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 |
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:
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 +```
`
+-Dspring.cloud.kubernetes.secrets.name=db-secret
+``
+-Dspring.cloud.kubernetes.secrets.labels.broker=activemq
+-Dspring.cloud.kubernetes.secrets.labels.db=postgresql
+`Table 4.2. Properties:
| Name | Type | Default | Description |
|---|---|---|---|
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
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 4.3. Properties:
| Name | Type | Default | Description |
|---|---|---|---|
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.
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.
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:
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 +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
+Ribbon’s CommonClientConfigKey classAdditionally, the spring-cloud-kubernetes-ribbon project defines two additional configuration keys to further
+control how Ribbon interacts with Kubernetes. In particular, if an endpoint defines multiple ports, the default
+behavior is to use the first one found. To select more specifically which port to use, in a multi-port service, use
+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.
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"
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:
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.
Table of Contents
Table of Contents
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.
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 +@EnableDiscoveryClient +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +}
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.
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:
@EnableCircuitBreaker@HystrixCommand(fallbackMethod= does the job.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.
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:
yaml the content of any property named application.yamlapplication.propertiesThe 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.corepool.size.maximumThis 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.
Another option for using ConfigMaps, is to mount them into the Pod running the Spring Cloud Kubernetes application
+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
Table 4.1. Properties:
| Name | Type | Default | Description |
|---|---|---|---|
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 |
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:
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 +```
`
+-Dspring.cloud.kubernetes.secrets.name=db-secret
+``
+-Dspring.cloud.kubernetes.secrets.labels.broker=activemq
+-Dspring.cloud.kubernetes.secrets.labels.db=postgresql
+`Table 4.2. Properties:
| Name | Type | Default | Description |
|---|---|---|---|
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
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 4.3. Properties:
| Name | Type | Default | Description |
|---|---|---|---|
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.
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 +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
+Ribbon’s CommonClientConfigKey classAdditionally, the spring-cloud-kubernetes-ribbon project defines two additional configuration keys to further
+control how Ribbon interacts with Kubernetes. In particular, if an endpoint defines multiple ports, the default
+behavior is to use the first one found. To select more specifically which port to use, in a multi-port service, use
+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.
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.
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).
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.
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:
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"
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:
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:
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.
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 |
|---|---|
You can also install Maven (>=3.3.3) yourself and run the |
![]() | Note |
|---|---|
Be aware that you might need to increase the amount of memory
+available to Maven by setting a |
For hints on how to build the project look in .travis.yml if there
+is one. There should be a "script" and maybe "install" command. Also
+look at the "services" section to see if any services need to be
+running locally (e.g. mongo or rabbit). Ignore the git-related bits
+that you might find in "before_install" since they’re related to setting git
+credentials and you already have those.
The projects that require middleware generally include a
+docker-compose.yml, so consider using
+Docker Compose to run the middeware servers
+in Docker containers. See the README in the
+scripts demo
+repository for specific instructions about the common cases of mongo,
+rabbit and redis.
![]() | Note |
|---|---|
If all else fails, build with the command from |
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.
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.
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 |
|---|---|
Older versions of m2e do not support Maven 3.3, so once the
+projects are imported into Eclipse you will also need to tell
+m2eclipse to use the right profile for the projects. If you
+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 |
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.
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.
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.
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.
eclipse-code-formatter.xml file from the
+Spring
+Cloud Build project. If using IntelliJ, you can use the
+Eclipse Code Formatter
+Plugin to import the same file..java files to have a simple Javadoc class comment with at least an
+@author tag identifying you, and preferably at least a paragraph on what the class is
+for..java files (copy from existing files
+in the project)@author to the .java files that you modify substantially (more
+than cosmetic changes).Fixes gh-XXXX at the end of the commit
+message (where XXXX is the issue number).