Antora migration (#1446)
* Migrate Structure * Insert explicit ids for headers * Remove unnecessary asciidoc attributes * Copy default antora files * Fix indentation for all pages * Split files * Generate a default navigation * Remove includes * Fix cross references * Enable Section Summary TOC for small pages * Antora migration
This commit is contained in:
32
.github/workflows/deploy-docs.yml
vendored
Normal file
32
.github/workflows/deploy-docs.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
name: Deploy Docs
|
||||
on:
|
||||
push:
|
||||
branches-ignore: [ gh-pages ]
|
||||
tags: '**'
|
||||
repository_dispatch:
|
||||
types: request-build-reference # legacy
|
||||
#schedule:
|
||||
#- cron: '0 10 * * *' # Once per day at 10am UTC
|
||||
workflow_dispatch:
|
||||
permissions:
|
||||
actions: write
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
# if: github.repository_owner == 'spring-cloud'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: docs-build
|
||||
fetch-depth: 1
|
||||
- name: Dispatch (partial build)
|
||||
if: github.ref_type == 'branch'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) -f build-refname=${{ github.ref_name }}
|
||||
- name: Dispatch (full build)
|
||||
if: github.ref_type == 'tag'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD)
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -84,3 +84,9 @@ crashlytics-build.properties
|
||||
.vscode/
|
||||
.java-version
|
||||
*Dockerfile
|
||||
|
||||
node
|
||||
node_modules
|
||||
build
|
||||
package.json
|
||||
package-lock.json
|
||||
|
||||
@@ -1 +1 @@
|
||||
-DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring
|
||||
-P spring
|
||||
|
||||
3
.mvn/wrapper/maven-wrapper.properties
vendored
3
.mvn/wrapper/maven-wrapper.properties
vendored
@@ -1 +1,2 @@
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
|
||||
|
||||
2477
README.adoc
2477
README.adoc
File diff suppressed because it is too large
Load Diff
38
docs/antora-playbook.yml
Normal file
38
docs/antora-playbook.yml
Normal file
@@ -0,0 +1,38 @@
|
||||
antora:
|
||||
extensions:
|
||||
- '@springio/antora-extensions/partial-build-extension'
|
||||
- require: '@springio/antora-extensions/latest-version-extension'
|
||||
- require: '@springio/antora-extensions/inject-collector-cache-config-extension'
|
||||
- '@antora/collector-extension'
|
||||
- '@antora/atlas-extension'
|
||||
- require: '@springio/antora-extensions/root-component-extension'
|
||||
root_component_name: 'cloud-kubernetes'
|
||||
site:
|
||||
title: Spring Cloud Kubernetes
|
||||
url: https://docs.spring.io/spring-cloud-kubernetes/reference/
|
||||
content:
|
||||
sources:
|
||||
- url: ./..
|
||||
branches: HEAD
|
||||
start_path: docs
|
||||
worktrees: true
|
||||
asciidoc:
|
||||
attributes:
|
||||
page-stackoverflow-url: https://stackoverflow.com/tags/spring-cloud
|
||||
page-pagination: ''
|
||||
hide-uri-scheme: '@'
|
||||
tabs-sync-option: '@'
|
||||
chomp: 'all'
|
||||
extensions:
|
||||
- '@asciidoctor/tabs'
|
||||
- '@springio/asciidoctor-extensions'
|
||||
sourcemap: true
|
||||
urls:
|
||||
latest_version_segment: ''
|
||||
runtime:
|
||||
log:
|
||||
failure_level: warn
|
||||
format: pretty
|
||||
ui:
|
||||
bundle:
|
||||
url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.3.5/ui-bundle.zip
|
||||
12
docs/antora.yml
Normal file
12
docs/antora.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
name: cloud-kubernetes
|
||||
version: true
|
||||
title: Spring Cloud Kubernetes
|
||||
nav:
|
||||
- modules/ROOT/nav.adoc
|
||||
ext:
|
||||
collector:
|
||||
run:
|
||||
command: ./mvnw --no-transfer-progress -B process-resources -Pdocs -pl docs -Dantora-maven-plugin.phase=none -Dgenerate-docs.phase=none -Dgenerate-readme.phase=none -Dgenerate-cloud-resources.phase=none -Dmaven-dependency-plugin-for-docs.phase=none -Dmaven-dependency-plugin-for-docs-classes.phase=none -DskipTests
|
||||
local: true
|
||||
scan:
|
||||
dir: ./target/classes/antora-resources/
|
||||
24
docs/modules/ROOT/nav.adoc
Normal file
24
docs/modules/ROOT/nav.adoc
Normal file
@@ -0,0 +1,24 @@
|
||||
* xref:index.adoc[Introduction]
|
||||
* xref:getting-started.adoc[]
|
||||
* xref:discovery-client.adoc[]
|
||||
* xref:discovery-kubernetes-native.adoc[]
|
||||
* xref:property-source-config.adoc[]
|
||||
** xref:property-source-config/configmap-propertysource.adoc[]
|
||||
** xref:property-source-config/secrets-propertysource.adoc[]
|
||||
** xref:property-source-config/namespace-resolution.adoc[]
|
||||
** xref:property-source-config/order_of_configMaps_and_secrets.adoc[]
|
||||
** xref:property-source-config/propertysource-reload.adoc[]
|
||||
** xref:property-source-config/namespace-label-filtering.adoc[]
|
||||
* xref:kubernetes-awareness.adoc[]
|
||||
* xref:pod-health-indicator.adoc[]
|
||||
* xref:info-contributor.adoc[]
|
||||
* xref:leader-election.adoc[]
|
||||
* xref:load-balancer.adoc[]
|
||||
* xref:security-service-accounts.adoc[]
|
||||
* xref:service-registry.adoc[]
|
||||
* xref:spring-cloud-kubernetes-configuration-watcher.adoc[]
|
||||
* xref:spring-cloud-kubernetes-configserver.adoc[]
|
||||
* xref:spring-cloud-kubernetes-discoveryserver.adoc[]
|
||||
* xref:examples.adoc[]
|
||||
* xref:other-resources.adoc[]
|
||||
* xref:appendix.adoc[]
|
||||
@@ -1,8 +1,6 @@
|
||||
:doctype: book
|
||||
:idprefix:
|
||||
:idseparator: -
|
||||
:toc: left
|
||||
:toclevels: 4
|
||||
:tabsize: 4
|
||||
:numbered:
|
||||
:sectanchors:
|
||||
@@ -1,7 +1,8 @@
|
||||
:numbered!:
|
||||
[appendix]
|
||||
[[common-application-properties]]
|
||||
== Common application properties
|
||||
= Common application properties
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
include::_attributes.adoc[]
|
||||
|
||||
@@ -11,4 +12,4 @@ This appendix provides a list of common {project-full-name} properties and refer
|
||||
NOTE: Property contributions can come from additional jar files on your classpath, so you should not consider this an exhaustive list.
|
||||
Also, you can define your own properties.
|
||||
|
||||
include::_configprops.adoc[]
|
||||
include::partial$_configprops.adoc[]
|
||||
6
docs/modules/ROOT/pages/configprops.adoc
Normal file
6
docs/modules/ROOT/pages/configprops.adoc
Normal file
@@ -0,0 +1,6 @@
|
||||
[[configuration-properties]]
|
||||
= Configuration Properties
|
||||
|
||||
Below you can find a list of configuration properties.
|
||||
|
||||
include::partial$_configprops.adoc[]
|
||||
@@ -1,4 +1,5 @@
|
||||
== DiscoveryClient for Kubernetes
|
||||
[[discoveryclient-for-kubernetes]]
|
||||
= DiscoveryClient for Kubernetes
|
||||
|
||||
This project provides an implementation of https://github.com/spring-cloud/spring-cloud-commons/blob/master/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java[Discovery Client]
|
||||
for https://kubernetes.io[Kubernetes].
|
||||
@@ -10,7 +11,6 @@ DiscoveryClient can also find services of type `ExternalName` (see https://kuber
|
||||
|
||||
This is something that you get for free by adding the following dependency inside your project:
|
||||
|
||||
====
|
||||
HTTP Based `DiscoveryClient`
|
||||
[source,xml]
|
||||
----
|
||||
@@ -19,12 +19,10 @@ HTTP Based `DiscoveryClient`
|
||||
<artifactId>spring-cloud-starter-kubernetes-discoveryclient</artifactId>
|
||||
</dependency>
|
||||
----
|
||||
====
|
||||
|
||||
NOTE: `spring-cloud-starter-kubernetes-discoveryclient` is designed to be used with the
|
||||
<<spring-cloud-kubernetes-discoveryserver, Spring Cloud Kubernetes DiscoveryServer>>.
|
||||
xref:spring-cloud-kubernetes-discoveryserver.adoc#spring-cloud-kubernetes-discoveryserver[Spring Cloud Kubernetes DiscoveryServer].
|
||||
|
||||
====
|
||||
Fabric8 Kubernetes Client
|
||||
[source,xml]
|
||||
----
|
||||
@@ -33,9 +31,7 @@ Fabric8 Kubernetes Client
|
||||
<artifactId>spring-cloud-starter-kubernetes-fabric8</artifactId>
|
||||
</dependency>
|
||||
----
|
||||
====
|
||||
|
||||
====
|
||||
Kubernetes Java Client
|
||||
[source,xml]
|
||||
----
|
||||
@@ -44,11 +40,9 @@ Kubernetes Java Client
|
||||
<artifactId>spring-cloud-starter-kubernetes-client</artifactId>
|
||||
</dependency>
|
||||
----
|
||||
====
|
||||
|
||||
To enable loading of the `DiscoveryClient`, add `@EnableDiscoveryClient` to the according configuration or application class, as the following example shows:
|
||||
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
@@ -59,46 +53,37 @@ public class Application {
|
||||
}
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
Then you can inject the client in your code simply by autowiring it, as the following example shows:
|
||||
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
----
|
||||
====
|
||||
|
||||
You can choose to enable `DiscoveryClient` from all namespaces by setting the following property in `application.properties`:
|
||||
|
||||
====
|
||||
[source]
|
||||
----
|
||||
spring.cloud.kubernetes.discovery.all-namespaces=true
|
||||
----
|
||||
====
|
||||
|
||||
To discover services and endpoints only from specified namespaces you should set property `all-namespaces` to `false` and set the following property in `application.properties` (in this example namespaces are: `ns1` and `ns2`).
|
||||
|
||||
====
|
||||
[source]
|
||||
----
|
||||
spring.cloud.kubernetes.discovery.namespaces[0]=ns1
|
||||
spring.cloud.kubernetes.discovery.namespaces[1]=ns2
|
||||
----
|
||||
====
|
||||
|
||||
To discover service endpoint addresses that are not marked as "ready" by the kubernetes api server, you can set the following property in `application.properties` (default: false):
|
||||
|
||||
====
|
||||
[source]
|
||||
----
|
||||
spring.cloud.kubernetes.discovery.include-not-ready-addresses=true
|
||||
----
|
||||
NOTE: This might be useful when discovering services for monitoring purposes, and would enable inspecting the `/health` endpoint of not-ready service instances.
|
||||
====
|
||||
|
||||
If your service exposes multiple ports, you will need to specify which port the `DiscoveryClient` should use.
|
||||
The `DiscoveryClient` will choose the port using the following logic.
|
||||
@@ -122,12 +107,10 @@ As said before, if you want to get the list of `ServiceInstance` to also include
|
||||
|
||||
If, for any reason, you need to disable the `DiscoveryClient`, you can set the following property in `application.properties`:
|
||||
|
||||
====
|
||||
[source]
|
||||
----
|
||||
spring.cloud.kubernetes.discovery.enabled=false
|
||||
----
|
||||
====
|
||||
|
||||
Some Spring Cloud components use the `DiscoveryClient` in order to obtain information about the local service instance. For
|
||||
this to work, you need to align the Kubernetes service name with the `spring.application.name` property.
|
||||
@@ -155,7 +138,7 @@ spring:
|
||||
- namespace-b
|
||||
```
|
||||
|
||||
- we will use: xref:property-source-config.adoc#namespace-resolution[Namespace Resolution] if the above two paths are not taken.
|
||||
- we will use: xref:property-source-config/namespace-resolution.adoc[Namespace Resolution] if the above two paths are not taken.
|
||||
|
||||
In order to enable this functionality you need to add
|
||||
`@EnableScheduling` on a configuration class in your application.
|
||||
@@ -1,9 +1,11 @@
|
||||
== Kubernetes native service discovery
|
||||
[[kubernetes-native-service-discovery]]
|
||||
= Kubernetes native service discovery
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
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, such as Istio (https://istio.io), a service mesh that is capable of load balancing, circuit breaker, failover, and much more.
|
||||
|
||||
The caller service then need only refer to names resolvable in a particular Kubernetes cluster. A simple implementation might use a spring `RestTemplate` that refers to a fully qualified domain name (FQDN), such as `https://{service-name}.{namespace}.svc.{cluster}.local:{service-port}`.
|
||||
The caller service then need only refer to names resolvable in a particular Kubernetes cluster. A simple implementation might use a spring `RestTemplate` that refers to a fully qualified domain name (FQDN), such as `https://\{service-name}.\{namespace}.svc.\{cluster}.local:\{service-port}`.
|
||||
|
||||
Additionally, you can use Hystrix for:
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
== Examples
|
||||
[[examples]]
|
||||
= Examples
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
Spring Cloud Kubernetes tries to make it transparent for your applications to consume Kubernetes Native Services by
|
||||
following the Spring Cloud interfaces.
|
||||
@@ -1,4 +1,5 @@
|
||||
== Starters
|
||||
[[starters]]
|
||||
= Starters
|
||||
|
||||
Starters are convenient dependency descriptors you can include in your
|
||||
application. Include a starter to get the dependencies and Spring Boot
|
||||
@@ -49,8 +50,8 @@ resolves service names to Kubernetes Services.
|
||||
</dependency>
|
||||
----
|
||||
| Load application properties from Kubernetes
|
||||
<<configmap-propertysource,ConfigMaps>> and <<Secrets PropertySource,Secrets>>.
|
||||
<<propertysource-reload,Reload>> application properties when a ConfigMap or
|
||||
xref:property-source-config/configmap-propertysource.adoc[ConfigMaps] and <<Secrets PropertySource,Secrets>>.
|
||||
xref:property-source-config/propertysource-reload.adoc[Reload] application properties when a ConfigMap or
|
||||
Secret changes.
|
||||
|
||||
| [source,xml]
|
||||
1
docs/modules/ROOT/pages/index.adoc
Normal file
1
docs/modules/ROOT/pages/index.adoc
Normal file
@@ -0,0 +1 @@
|
||||
include::spring-cloud-kubernetes.adoc[Introduction]
|
||||
@@ -1,4 +1,6 @@
|
||||
== Info Contributor
|
||||
[[info-contributor]]
|
||||
= Info Contributor
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
Spring Cloud Kubernetes includes an `InfoContributor` which adds Pod information to
|
||||
Spring Boot's `/info` Acturator endpoint.
|
||||
@@ -1,4 +1,5 @@
|
||||
== Kubernetes Ecosystem Awareness
|
||||
[[kubernetes-ecosystem-awareness]]
|
||||
= Kubernetes Ecosystem Awareness
|
||||
|
||||
All features described earlier in this guide work equally well, regardless of whether your application is running inside
|
||||
Kubernetes. This is really helpful for development and troubleshooting.
|
||||
@@ -20,19 +21,22 @@ you will have to set `spring.main.cloud-platform` should be set in `bootstrap.{p
|
||||
(or the profile specific one). Also note that these properties: `spring.cloud.kubernetes.config.enabled` and `spring.cloud.kubernetes.secrets.enabled`
|
||||
will only take effect when set in `bootstrap.{properties|yml}` when you have `spring-cloud-starter-bootstrap` on your classpath or are setting `spring.cloud.bootstrap.enabled=true`.
|
||||
|
||||
=== Breaking Changes In 3.0.x
|
||||
[[breaking-changes-in-3-0-x]]
|
||||
== Breaking Changes In 3.0.x
|
||||
|
||||
In versions of Spring Cloud Kubernetes prior to `3.0.x`, Kubernetes awareness was implemented using `spring.cloud.kubernetes.enabled` property. This
|
||||
property was removed and is un-supported. Instead, we use Spring Boot API: https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/condition/ConditionalOnCloudPlatform.html[ConditionalOnCloudPlatform].
|
||||
If it is needed to explicitly enable or disable this awareness, use `spring.main.cloud-platform=NONE/KUBERNETES`.
|
||||
|
||||
=== Kubernetes Profile Autoconfiguration
|
||||
[[kubernetes-profile-autoconfiguration]]
|
||||
== Kubernetes Profile Autoconfiguration
|
||||
|
||||
When the application runs as a pod inside Kubernetes, a Spring profile named `kubernetes` automatically gets activated.
|
||||
This lets you customize the configuration, to define beans that are applied when the Spring Boot application is deployed
|
||||
within the Kubernetes platform (for example, different development and production configuration).
|
||||
|
||||
=== Istio Awareness
|
||||
[[istio-awareness]]
|
||||
== Istio Awareness
|
||||
|
||||
When you include the `spring-cloud-kubernetes-fabric8-istio` module in the application classpath, a new profile is added to the application,
|
||||
provided the application is running inside a Kubernetes Cluster with https://istio.io[Istio] installed. You can then use
|
||||
@@ -1,4 +1,6 @@
|
||||
== Leader Election
|
||||
[[leader-election]]
|
||||
= Leader Election
|
||||
|
||||
The Spring Cloud Kubernetes leader election mechanism implements the leader election API of Spring Integration using a Kubernetes ConfigMap.
|
||||
|
||||
Multiple application instances compete for leadership, but leadership will only be granted to one.
|
||||
@@ -9,7 +11,6 @@ When leadership removal occurs, the previous leader receives `OnRevokedEvent` ap
|
||||
After removal, any instances in the cluster may become the new leader, including the old leader.
|
||||
|
||||
To include it in your project, add the following dependency.
|
||||
====
|
||||
Fabric8 Leader Implementation
|
||||
[source,xml]
|
||||
----
|
||||
@@ -18,12 +19,9 @@ Fabric8 Leader Implementation
|
||||
<artifactId>spring-cloud-kubernetes-fabric8-leader</artifactId>
|
||||
</dependency>
|
||||
----
|
||||
====
|
||||
|
||||
To specify the name of the configmap used for leader election use the following property.
|
||||
====
|
||||
[source,properties]
|
||||
----
|
||||
spring.cloud.kubernetes.leader.config-map-name=leader
|
||||
----
|
||||
====
|
||||
@@ -1,7 +1,8 @@
|
||||
== LoadBalancer for Kubernetes
|
||||
[[loadbalancer-for-kubernetes]]
|
||||
= LoadBalancer for Kubernetes
|
||||
|
||||
This project includes Spring Cloud Load Balancer for load balancing based on Kubernetes Endpoints and provides implementation of load balancer based on Kubernetes Service.
|
||||
To include it to your project add the following dependency.
|
||||
====
|
||||
Fabric8 Implementation
|
||||
[source,xml]
|
||||
----
|
||||
@@ -10,9 +11,7 @@ Fabric8 Implementation
|
||||
<artifactId>spring-cloud-starter-kubernetes-fabric8-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
----
|
||||
====
|
||||
|
||||
====
|
||||
Kubernetes Java Client Implementation
|
||||
[source,xml]
|
||||
----
|
||||
@@ -21,22 +20,17 @@ Kubernetes Java Client Implementation
|
||||
<artifactId>spring-cloud-starter-kubernetes-client-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
----
|
||||
====
|
||||
|
||||
To enable load balancing based on Kubernetes Service name use the following property. Then load balancer would try to call application using address, for example `service-a.default.svc.cluster.local`
|
||||
====
|
||||
[source]
|
||||
----
|
||||
spring.cloud.kubernetes.loadbalancer.mode=SERVICE
|
||||
----
|
||||
====
|
||||
|
||||
To enabled load balancing across all namespaces use the following property. Property from `spring-cloud-kubernetes-discovery` module is respected.
|
||||
====
|
||||
[source]
|
||||
----
|
||||
spring.cloud.kubernetes.discovery.all-namespaces=true
|
||||
----
|
||||
====
|
||||
|
||||
If a service needs to be accessed over HTTPS you need to add a label or annotation to your service definition with the name `secured` and the value `true` and the load balancer will then use HTTPS to make requests to the service.
|
||||
@@ -1,4 +1,6 @@
|
||||
== Other Resources
|
||||
[[other-resources]]
|
||||
= Other Resources
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
This section lists other resources, such as presentations (slides) and videos about Spring Cloud Kubernetes.
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
== Pod Health Indicator
|
||||
[[pod-health-indicator]]
|
||||
= Pod Health Indicator
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
Spring Boot uses https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpoint.java[`HealthIndicator`] to expose info about the health of an application.
|
||||
That makes it really useful for exposing health-related information to the user and makes it a good fit for use as https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/[readiness probes].
|
||||
18
docs/modules/ROOT/pages/property-source-config.adoc
Normal file
18
docs/modules/ROOT/pages/property-source-config.adoc
Normal file
@@ -0,0 +1,18 @@
|
||||
[[kubernetes-propertysource-implementations]]
|
||||
= Kubernetes PropertySource implementations
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
The most common approach to configuring your Spring Boot application is to create an `application.properties` or `application.yaml` or
|
||||
an `application-profile.properties` or `application-profile.yaml` file that contains key-value pairs that provide customization values to your
|
||||
application or Spring Boot starters. You can override these properties by specifying system properties or environment
|
||||
variables.
|
||||
|
||||
To enable this functionality you need to set `spring.config.import=kubernetes:` in your application's configuration properties.
|
||||
Currently you can not specify a ConfigMap or Secret to load using `spring.config.import`, by default Spring Cloud Kubernetes
|
||||
will load a ConfigMap and/or Secret based on the `spring.application.name` property. If `spring.application.name` is not set it will
|
||||
load a ConfigMap and/or Secret with the name `application`.
|
||||
|
||||
If you would like to load Kubernetes ``PropertySource``s during the bootstrap phase like it worked prior to the 3.0.x release
|
||||
you can either add `spring-cloud-starter-bootstrap` to your application's classpath or set `spring.cloud.bootstrap.enabled=true`
|
||||
as an environment variable.
|
||||
|
||||
@@ -0,0 +1,572 @@
|
||||
[[configmap-propertysource]]
|
||||
= Using a `ConfigMap` `PropertySource`
|
||||
|
||||
Kubernetes provides a resource named https://kubernetes.io/docs/user-guide/configmap/[`ConfigMap`] to externalize the
|
||||
parameters to pass to your application in the form of key-value pairs or embedded `application.properties` or `application.yaml` files.
|
||||
The link:https://github.com/spring-cloud/spring-cloud-kubernetes/tree/master/spring-cloud-kubernetes-fabric8-config[Spring Cloud Kubernetes Config] project makes Kubernetes `ConfigMap` instances available
|
||||
during application startup and triggers hot reloading of beans or Spring context when changes are detected on
|
||||
observed `ConfigMap` instances.
|
||||
|
||||
Everything that follows is explained mainly referring to examples using ConfigMaps, but the same stands for
|
||||
Secrets, i.e.: every feature is supported for both.
|
||||
|
||||
The default behavior is to create a `Fabric8ConfigMapPropertySource` (or a `KubernetesClientConfigMapPropertySource`) based on a Kubernetes `ConfigMap` that has a `metadata.name` value of either the name of
|
||||
your Spring application (as defined by its `spring.application.name` property) or a custom name defined within the
|
||||
`application.properties` file under the following key: `spring.cloud.kubernetes.config.name`.
|
||||
|
||||
However, more advanced configuration is possible where you can use multiple `ConfigMap` instances.
|
||||
The `spring.cloud.kubernetes.config.sources` list makes this possible.
|
||||
For example, you could define the following `ConfigMap` instances:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: cloud-k8s-app
|
||||
cloud:
|
||||
kubernetes:
|
||||
config:
|
||||
name: default-name
|
||||
namespace: default-namespace
|
||||
sources:
|
||||
# Spring Cloud Kubernetes looks up a ConfigMap named c1 in namespace default-namespace
|
||||
- name: c1
|
||||
# Spring Cloud Kubernetes looks up a ConfigMap named default-name in whatever namespace n2
|
||||
- namespace: n2
|
||||
# Spring Cloud Kubernetes looks up a ConfigMap named c3 in namespace n3
|
||||
- namespace: n3
|
||||
name: c3
|
||||
----
|
||||
|
||||
In the preceding example, if `spring.cloud.kubernetes.config.namespace` had not been set,
|
||||
the `ConfigMap` named `c1` would be looked up in the namespace that the application runs.
|
||||
See xref:property-source-config/namespace-resolution.adoc[Namespace resolution] to get a better understanding of how the namespace
|
||||
of the application is resolved.
|
||||
|
||||
|
||||
Any matching `ConfigMap` that is found is processed as follows:
|
||||
|
||||
* Apply individual configuration properties.
|
||||
* Apply as `yaml` (or `properties`) the content of any property that is named by the value of `spring.application.name`
|
||||
(if it's not present, by `application.yaml/properties`)
|
||||
* Apply as a properties file the content of the above name + each active profile.
|
||||
|
||||
An example should make a lot more sense. Let's suppose that `spring.application.name=my-app` and that
|
||||
we have a single active profile called `k8s`. For a configuration as below:
|
||||
|
||||
|
||||
[source]
|
||||
----
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: my-app
|
||||
data:
|
||||
my-app.yaml: |-
|
||||
...
|
||||
my-app-k8s.yaml: |-
|
||||
..
|
||||
my-app-dev.yaml: |-
|
||||
..
|
||||
someProp: someValue
|
||||
----
|
||||
|
||||
These is what we will end-up loading:
|
||||
|
||||
- `my-app.yaml` treated as a file
|
||||
- `my-app-k8s.yaml` treated as a file
|
||||
- `my-app-dev.yaml` _ignored_, since `dev` is _not_ an active profile
|
||||
- `someProp: someValue` plain property
|
||||
|
||||
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 is treated correctly.
|
||||
This features facilitates the use case where the `ConfigMap` was created by using something like the following:
|
||||
|
||||
[source]
|
||||
----
|
||||
kubectl create configmap game-config --from-file=/path/to/app-config.yaml
|
||||
----
|
||||
|
||||
Assume that we have a Spring Boot application named `demo` that uses the following properties to read its thread pool
|
||||
configuration.
|
||||
|
||||
* `pool.size.core`
|
||||
* `pool.size.maximum`
|
||||
|
||||
This can be externalized to config map in `yaml` format as follows:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: demo
|
||||
data:
|
||||
pool.size.core: 1
|
||||
pool.size.max: 16
|
||||
----
|
||||
|
||||
Individual properties work fine for most cases. However, sometimes, embedded `yaml` is more convenient. In this case, we
|
||||
use a single property named `application.yaml` to embed our `yaml`, as follows:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: demo
|
||||
data:
|
||||
application.yaml: |-
|
||||
pool:
|
||||
size:
|
||||
core: 1
|
||||
max:16
|
||||
----
|
||||
|
||||
The following example also works:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: demo
|
||||
data:
|
||||
custom-name.yaml: |-
|
||||
pool:
|
||||
size:
|
||||
core: 1
|
||||
max:16
|
||||
----
|
||||
|
||||
You can also define the search to happen based on labels, for example:
|
||||
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: labeled-configmap-with-prefix
|
||||
cloud:
|
||||
kubernetes:
|
||||
config:
|
||||
enableApi: true
|
||||
useNameAsPrefix: true
|
||||
namespace: spring-k8s
|
||||
sources:
|
||||
- labels:
|
||||
letter: a
|
||||
----
|
||||
|
||||
This will search for every configmap in namespace `spring-k8s` that has labels `{letter : a}`. The important
|
||||
thing to notice here is that unlike reading a configmap by name, this can result in _multiple_ config maps read.
|
||||
As usual, the same feature is supported for secrets.
|
||||
|
||||
You can also configure Spring Boot applications differently depending on active profiles that are merged together
|
||||
when the `ConfigMap` is read. You can provide different property values for different profiles by using an
|
||||
`application.properties` or `application.yaml` property, specifying profile-specific values, each in their own document
|
||||
(indicated by the `---` sequence), as follows:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
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 preceding case, the configuration loaded into your Spring Application with the `development` profile is as follows:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
greeting:
|
||||
message: Say Hello to the Developers
|
||||
farewell:
|
||||
message: Say Goodbye to the Developers
|
||||
----
|
||||
|
||||
However, if the `production` profile is active, the configuration becomes:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
greeting:
|
||||
message: Say Hello to the Ops
|
||||
farewell:
|
||||
message: Say Goodbye
|
||||
----
|
||||
|
||||
If both profiles are active, the property that appears last within the `ConfigMap` overwrites any preceding values.
|
||||
|
||||
Another option is to create a different config map per profile and spring boot will automatically fetch it based
|
||||
on active profiles
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: demo
|
||||
data:
|
||||
application.yml: |-
|
||||
greeting:
|
||||
message: Say Hello to the World
|
||||
farewell:
|
||||
message: Say Goodbye
|
||||
----
|
||||
[source,yaml]
|
||||
----
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: demo-development
|
||||
data:
|
||||
application.yml: |-
|
||||
spring:
|
||||
profiles: development
|
||||
greeting:
|
||||
message: Say Hello to the Developers
|
||||
farewell:
|
||||
message: Say Goodbye to the Developers
|
||||
----
|
||||
[source,yaml]
|
||||
----
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: demo-production
|
||||
data:
|
||||
application.yml: |-
|
||||
spring:
|
||||
profiles: production
|
||||
greeting:
|
||||
message: Say Hello to the Ops
|
||||
farewell:
|
||||
message: Say Goodbye
|
||||
----
|
||||
|
||||
|
||||
To tell Spring Boot which `profile` should be enabled see the https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.profiles[Spring Boot documentation].
|
||||
One option for activating a specific profile when deploying to Kubernetes is to launch your Spring Boot application with an environment variable that you can define in the PodSpec at the container specification.
|
||||
Deployment resource file, as follows:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deployment-name
|
||||
labels:
|
||||
app: deployment-name
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: deployment-name
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: deployment-name
|
||||
spec:
|
||||
containers:
|
||||
- name: container-name
|
||||
image: your-image
|
||||
env:
|
||||
- name: SPRING_PROFILES_ACTIVE
|
||||
value: "development"
|
||||
----
|
||||
|
||||
You could run into a situation where there are multiple configs maps that have the same property names. For example:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: config-map-one
|
||||
data:
|
||||
application.yml: |-
|
||||
greeting:
|
||||
message: Say Hello from one
|
||||
----
|
||||
|
||||
and
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: config-map-two
|
||||
data:
|
||||
application.yml: |-
|
||||
greeting:
|
||||
message: Say Hello from two
|
||||
----
|
||||
|
||||
Depending on the order in which you place these in `bootstrap.yaml|properties`, you might end up with an un-expected result (the last config map wins). For example:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: cloud-k8s-app
|
||||
cloud:
|
||||
kubernetes:
|
||||
config:
|
||||
namespace: default-namespace
|
||||
sources:
|
||||
- name: config-map-two
|
||||
- name: config-map-one
|
||||
----
|
||||
|
||||
will result in property `greetings.message` being `Say Hello from one`.
|
||||
|
||||
There is a way to change this default configuration by specifying `useNameAsPrefix`. For example:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: with-prefix
|
||||
cloud:
|
||||
kubernetes:
|
||||
config:
|
||||
useNameAsPrefix: true
|
||||
namespace: default-namespace
|
||||
sources:
|
||||
- name: config-map-one
|
||||
useNameAsPrefix: false
|
||||
- name: config-map-two
|
||||
----
|
||||
|
||||
Such a configuration will result in two properties being generated:
|
||||
|
||||
- `greetings.message` equal to `Say Hello from one`.
|
||||
|
||||
- `config-map-two.greetings.message` equal to `Say Hello from two`
|
||||
|
||||
Notice that `spring.cloud.kubernetes.config.useNameAsPrefix` has a _lower_ priority than `spring.cloud.kubernetes.config.sources.useNameAsPrefix`.
|
||||
This allows you to set a "default" strategy for all sources, at the same time allowing to override only a few.
|
||||
|
||||
If using the config map name is not an option, you can specify a different strategy, called : `explicitPrefix`. Since this is an _explicit_ prefix that
|
||||
you select, it can only be supplied to the `sources` level. At the same time it has a higher priority than `useNameAsPrefix`. Let's suppose we have a third config map with these entries:
|
||||
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: config-map-three
|
||||
data:
|
||||
application.yml: |-
|
||||
greeting:
|
||||
message: Say Hello from three
|
||||
----
|
||||
|
||||
A configuration like the one below:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: with-prefix
|
||||
cloud:
|
||||
kubernetes:
|
||||
config:
|
||||
useNameAsPrefix: true
|
||||
namespace: default-namespace
|
||||
sources:
|
||||
- name: config-map-one
|
||||
useNameAsPrefix: false
|
||||
- name: config-map-two
|
||||
explicitPrefix: two
|
||||
- name: config-map-three
|
||||
----
|
||||
|
||||
will result in three properties being generated:
|
||||
|
||||
- `greetings.message` equal to `Say Hello from one`.
|
||||
|
||||
- `two.greetings.message` equal to `Say Hello from two`.
|
||||
|
||||
- `config-map-three.greetings.message` equal to `Say Hello from three`.
|
||||
|
||||
The same way you configure a prefix for configmaps, you can do it for secrets also; both for secrets that are based on name
|
||||
and the ones based on labels. For example:
|
||||
|
||||
[source.yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: prefix-based-secrets
|
||||
cloud:
|
||||
kubernetes:
|
||||
secrets:
|
||||
enableApi: true
|
||||
useNameAsPrefix: true
|
||||
namespace: spring-k8s
|
||||
sources:
|
||||
- labels:
|
||||
letter: a
|
||||
useNameAsPrefix: false
|
||||
- labels:
|
||||
letter: b
|
||||
explicitPrefix: two
|
||||
- labels:
|
||||
letter: c
|
||||
- labels:
|
||||
letter: d
|
||||
useNameAsPrefix: true
|
||||
- name: my-secret
|
||||
----
|
||||
|
||||
The same processing rules apply when generating property source as for config maps. The only difference is that
|
||||
potentially, looking up secrets by labels can mean that we find more than one source. In such a case, prefix (if specified via `useNameAsPrefix`)
|
||||
will be the names of all secrets found for those particular labels.
|
||||
|
||||
One more thing to bear in mind is that we support `prefix` per _source_, not per secret. The easiest way to explain this is via an example:
|
||||
|
||||
[source.yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: prefix-based-secrets
|
||||
cloud:
|
||||
kubernetes:
|
||||
secrets:
|
||||
enableApi: true
|
||||
useNameAsPrefix: true
|
||||
namespace: spring-k8s
|
||||
sources:
|
||||
- labels:
|
||||
color: blue
|
||||
useNameAsPrefix: true
|
||||
----
|
||||
|
||||
Suppose that a query matching such a label will provide two secrets as a result: `secret-a` and `secret-b`.
|
||||
Both of these secrets have the same property name: `color=sea-blue` and `color=ocean-blue`. It is undefined which
|
||||
`color` will end-up as part of property sources, but the prefix for it will be `secret-a.secret-b`
|
||||
(concatenated sorted naturally, names of the secrets).
|
||||
|
||||
If you need more fine-grained results, adding more labels to identify the secret uniquely would be an option.
|
||||
|
||||
|
||||
|
||||
By default, besides reading the config map that is specified in the `sources` configuration, Spring will also try to read
|
||||
all properties from "profile aware" sources. The easiest way to explain this is via an example. Let's suppose your application
|
||||
enables a profile called "dev" and you have a configuration like the one below:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: spring-k8s
|
||||
cloud:
|
||||
kubernetes:
|
||||
config:
|
||||
namespace: default-namespace
|
||||
sources:
|
||||
- name: config-map-one
|
||||
----
|
||||
|
||||
Besides reading the `config-map-one`, Spring will also try to read `config-map-one-dev`; in this particular order. Each active profile
|
||||
generates such a profile aware config map.
|
||||
|
||||
Though your application should not be impacted by such a config map, it can be disabled if needed:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: spring-k8s
|
||||
cloud:
|
||||
kubernetes:
|
||||
config:
|
||||
includeProfileSpecificSources: false
|
||||
namespace: default-namespace
|
||||
sources:
|
||||
- name: config-map-one
|
||||
includeProfileSpecificSources: false
|
||||
----
|
||||
|
||||
Notice that just like before, there are two levels where you can specify this property: for all config maps or
|
||||
for individual ones; the latter having a higher priority.
|
||||
|
||||
NOTE: You should 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 `ConfigMap` instances is to mount them into the Pod by running the Spring Cloud Kubernetes application
|
||||
and having Spring Cloud Kubernetes read them from the file system.
|
||||
|
||||
NOTE: This feature is deprecated and will be removed in a future release (Use `spring.config.import` instead).
|
||||
This behavior is controlled by the `spring.cloud.kubernetes.config.paths` property. You can use it in
|
||||
addition to or instead of the mechanism described earlier.
|
||||
`spring.cloud.kubernetes.config.paths` expects a List of full paths to each property file, because directories are not being recursively parsed. For example:
|
||||
|
||||
```
|
||||
spring:
|
||||
cloud:
|
||||
kubernetes:
|
||||
config:
|
||||
paths:
|
||||
- /tmp/application.properties
|
||||
- /var/application.yaml
|
||||
```
|
||||
|
||||
NOTE: If you use `spring.cloud.kubernetes.config.paths` or `spring.cloud.kubernetes.secrets.path` the automatic reload
|
||||
functionality will not work. You will need to make a `POST` request to the `/actuator/refresh` endpoint or
|
||||
restart/redeploy the application.
|
||||
|
||||
[#config-map-fail-fast]
|
||||
In some cases, your application may be unable to load some of your `ConfigMaps` using the Kubernetes API.
|
||||
If you want your application to fail the start-up process in such cases, you can set
|
||||
`spring.cloud.kubernetes.config.fail-fast=true` to make the application start-up fail with an Exception.
|
||||
|
||||
[#config-map-retry]
|
||||
You can also make your application retry loading `ConfigMap` property sources on a failure. First, you need to
|
||||
set `spring.cloud.kubernetes.config.fail-fast=true`. Then you need to add `spring-retry`
|
||||
and `spring-boot-starter-aop` to your classpath. You can configure retry properties such as
|
||||
the maximum number of attempts, backoff options like initial interval, multiplier, max interval by setting the
|
||||
`spring.cloud.kubernetes.config.retry.*` properties.
|
||||
|
||||
NOTE: If you already have `spring-retry` and `spring-boot-starter-aop` on the classpath for some reason
|
||||
and want to enable fail-fast, but do not want retry to be enabled; you can disable retry for `ConfigMap` `PropertySources`
|
||||
by setting `spring.cloud.kubernetes.config.retry.enabled=false`.
|
||||
|
||||
.Properties:
|
||||
[options="header,footer"]
|
||||
|===
|
||||
| Name | Type | Default | Description
|
||||
| `spring.cloud.kubernetes.config.enabled` | `Boolean` | `true` | Enable ConfigMaps `PropertySource`
|
||||
| `spring.cloud.kubernetes.config.name` | `String` | `${spring.application.name}` | Sets the name of `ConfigMap` to look up
|
||||
| `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 `ConfigMap` instances are mounted
|
||||
| `spring.cloud.kubernetes.config.enableApi` | `Boolean` | `true` | Enable or disable consuming `ConfigMap` instances through APIs
|
||||
| `spring.cloud.kubernetes.config.fail-fast` | `Boolean` | `false` | Enable or disable failing the application start-up when an error occurred while loading a `ConfigMap`
|
||||
| `spring.cloud.kubernetes.config.retry.enabled` | `Boolean` | `true` | Enable or disable config retry.
|
||||
| `spring.cloud.kubernetes.config.retry.initial-interval` | `Long` | `1000` | Initial retry interval in milliseconds.
|
||||
| `spring.cloud.kubernetes.config.retry.max-attempts` | `Integer` | `6` | Maximum number of attempts.
|
||||
| `spring.cloud.kubernetes.config.retry.max-interval` | `Long` | `2000` | Maximum interval for backoff.
|
||||
| `spring.cloud.kubernetes.config.retry.multiplier` | `Double` | `1.1` | Multiplier for next interval.
|
||||
|===
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
[[namespace-label-filtering]]
|
||||
= Reload namespace and label filtering
|
||||
|
||||
By default, a namespace chosen using the steps outlined in xref:property-source-config/namespace-resolution.adoc[Namespace resolution] will be used to listen to changes
|
||||
in configmaps and secrets. i.e.: if you do not tell reload what namespaces and configmaps/secrets to watch for,
|
||||
it will watch all configmaps/secrets from the namespace that will be computed using the above algorithm.
|
||||
|
||||
On the other hand, you can define a more fine-grained approach. For example, you can specify the namespaces where
|
||||
changes will be monitored:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: event-reload
|
||||
cloud:
|
||||
kubernetes:
|
||||
reload:
|
||||
enabled: true
|
||||
strategy: shutdown
|
||||
mode: event
|
||||
namespaces:
|
||||
- my-namespace
|
||||
----
|
||||
|
||||
Such a configuration will make the app watch changes only in the `my-namespace` namespace. Mind that this will
|
||||
watch _all_ configmaps/secrets (depending on which one you enable). If you want an even more fine-grained approach,
|
||||
you can enable "label-filtering". First we need to enable such support via : `enable-reload-filtering: true`
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: event-reload
|
||||
cloud:
|
||||
kubernetes:
|
||||
reload:
|
||||
enabled: true
|
||||
strategy: shutdown
|
||||
mode: event
|
||||
namespaces:
|
||||
- my-namespaces
|
||||
monitoring-config-maps: true
|
||||
enable-reload-filtering: true
|
||||
----
|
||||
|
||||
What this will do, is watch configmaps/secrets that only have the `spring.cloud.kubernetes.config.informer.enabled: true` label.
|
||||
|
||||
.Properties:
|
||||
[options="header,footer"]
|
||||
|===
|
||||
| Name | Type | Default | Description
|
||||
| `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`, or `shutdown`)
|
||||
| `spring.cloud.kubernetes.reload.mode` | `Enum` | `event` | Specifies how to listen for changes in property sources (`event` or `polling`)
|
||||
| `spring.cloud.kubernetes.reload.period` | `Duration`| `15s` | The period for verifying changes when using the `polling` strategy
|
||||
| `spring.cloud.kubernetes.reload.namespaces` | `String[]`| | namespaces where we should watch for changes
|
||||
| `spring.cloud.kubernetes.reload.enable-reload-filtering` | `String` | | enabled labeled filtering for reload functionality
|
||||
|===
|
||||
|
||||
Notes:
|
||||
|
||||
* You should not use properties under `spring.cloud.kubernetes.reload` 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 you use the `refresh` level.
|
||||
@@ -0,0 +1,38 @@
|
||||
[[namespace-resolution]]
|
||||
= Namespace resolution
|
||||
|
||||
Finding an application namespace happens on a best-effort basis. There are some steps that we iterate in order
|
||||
to find it. The easiest and most common one, is to specify it in the proper configuration, for example:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: app
|
||||
cloud:
|
||||
kubernetes:
|
||||
secrets:
|
||||
name: secret
|
||||
namespace: default
|
||||
sources:
|
||||
# Spring Cloud Kubernetes looks up a Secret named 'a' in namespace 'default'
|
||||
- name: a
|
||||
# Spring Cloud Kubernetes looks up a Secret named 'secret' in namespace 'b'
|
||||
- namespace: b
|
||||
# Spring Cloud Kubernetes looks up a Secret named 'd' in namespace 'c'
|
||||
- namespace: c
|
||||
name: d
|
||||
----
|
||||
|
||||
Remember that the same can be done for config maps. If such a namespace is not specified, it will be read (in this order):
|
||||
|
||||
1. from property `spring.cloud.kubernetes.client.namespace`
|
||||
2. from a String residing in a file denoted by `spring.cloud.kubernetes.client.serviceAccountNamespacePath` property
|
||||
3. from a String residing in `/var/run/secrets/kubernetes.io/serviceaccount/namespace` file
|
||||
(kubernetes default namespace path)
|
||||
4. from a designated client method call (for example fabric8's : `KubernetesClient::getNamespace`), if the client provides
|
||||
such a method. This, in turn, could be configured via environment properties. For example fabric8 client can be configured via
|
||||
"KUBERNETES_NAMESPACE" property; consult the client documentation for exact details.
|
||||
|
||||
Failure to find a namespace from the above steps will result in an Exception being raised.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
[[order_of_configMaps_and_secrets]]
|
||||
= Order of ConfigMaps and Secrets
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
If, for whatever reason, you enabled both configmaps and secrets, and there is a common property between them, the value from the ConfigMap will have a higher precedence. That is: it will override whatever values are found in secrets.
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
[[propertysource-reload]]
|
||||
= `PropertySource` Reload
|
||||
|
||||
WARNING: This functionality has been deprecated in the 2020.0 release. Please see
|
||||
the xref:spring-cloud-kubernetes-configuration-watcher.adoc#spring-cloud-kubernetes-configuration-watcher[null] controller for an alternative way
|
||||
to achieve the same functionality.
|
||||
|
||||
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.
|
||||
|
||||
By default, this feature is disabled. You can enable it by using the `spring.cloud.kubernetes.reload.enabled=true` configuration property (for example, in the `application.properties` file).
|
||||
Please notice that this will enable monitoring of configmaps only (i.e.: `spring.cloud.kubernetes.reload.monitoring-config-maps` will be set to `true`).
|
||||
If you want to enable monitoring of secrets, this must be done explicitly via : `spring.cloud.kubernetes.reload.monitoring-secrets=true`.
|
||||
|
||||
The following levels of reload are supported (by setting the `spring.cloud.kubernetes.reload.strategy` property):
|
||||
|
||||
* `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.
|
||||
In order for the restart context functionality to work properly you must enable and expose the restart actuator endpoint
|
||||
[source,yaml]
|
||||
====
|
||||
----
|
||||
management:
|
||||
endpoint:
|
||||
restart:
|
||||
enabled: true
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: restart
|
||||
----
|
||||
====
|
||||
|
||||
* `shutdown`: the Spring `ApplicationContext` is shut down to activate a restart of the container.
|
||||
When you use 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.
|
||||
|
||||
Assuming that the reload feature is enabled with default settings (`refresh` mode), the following bean is refreshed when the config map changes:
|
||||
|
||||
[java, source]
|
||||
----
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "bean")
|
||||
public class MyConfig {
|
||||
|
||||
private String message = "a message that can be changed live";
|
||||
|
||||
// getter and setters
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
To see that changes effectively happen, you can create another bean that prints the message periodically, as follows
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
@Autowired
|
||||
private MyConfig config;
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void hello() {
|
||||
System.out.println("The message is: " + config.getMessage());
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
You can change the message printed by the application by using a `ConfigMap`, as follows:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
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 with the pod is reflected in the
|
||||
output. More generally speaking, changes associated to properties prefixed with the value defined by the `prefix`
|
||||
field of the `@ConfigurationProperties` annotation are detected and reflected in the application.
|
||||
xref:property-source-config/configmap-propertysource.adoc[Associating a `ConfigMap` with a pod] is explained earlier in this chapter.
|
||||
|
||||
The reload feature supports two operating modes:
|
||||
|
||||
* Event (default): Watches for changes in config maps or secrets by using the Kubernetes API (web socket).
|
||||
Any event produces a re-check on the configuration and, in case of changes, a reload.
|
||||
The `view` role on the service account is required in order to listen for config map changes. A higher level role (such as `edit`) is required for secrets
|
||||
(by default, secrets are not monitored).
|
||||
* Polling: Periodically re-creates the configuration from config maps and secrets to see if it has changed.
|
||||
You can configure the polling period by using the `spring.cloud.kubernetes.reload.period` property 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.
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
[[secrets-propertysource]]
|
||||
= Secrets PropertySource
|
||||
|
||||
Kubernetes has the notion of https://kubernetes.io/docs/concepts/configuration/secret/[Secrets] for storing
|
||||
sensitive data such as passwords, OAuth tokens, and so on. This project provides integration with `Secrets` to make secrets
|
||||
accessible by Spring Boot applications. You can explicitly enable or disable This feature by setting the `spring.cloud.kubernetes.secrets.enabled` property.
|
||||
|
||||
When enabled, the `Fabric8SecretsPropertySource` looks up Kubernetes for `Secrets` from the following sources:
|
||||
|
||||
. Reading recursively from secrets mounts
|
||||
. Named after the application (as defined by `spring.application.name`)
|
||||
. Matching some labels
|
||||
|
||||
*Note:*
|
||||
|
||||
By default, consuming Secrets through the API (points 2 and 3 above) *is not enabled* for security reasons. The permission 'list' on secrets allows clients to inspect secrets values in the specified namespace.
|
||||
Further, we recommend that containers share secrets through mounted volumes.
|
||||
|
||||
If you enable consuming Secrets through the API, we recommend that you limit access to Secrets by using an authorization policy, such as RBAC.
|
||||
For more information about risks and best practices when consuming Secrets through the API refer to https://kubernetes.io/docs/concepts/configuration/secret/#best-practices[this doc].
|
||||
|
||||
If the secrets are found, their data is made available to the application.
|
||||
|
||||
Assume that we have a spring boot application named `demo` that uses properties to read its database
|
||||
configuration. We can create a Kubernetes secret by using the following command:
|
||||
|
||||
[source]
|
||||
----
|
||||
kubectl create secret generic db-secret --from-literal=username=user --from-literal=password=p455w0rd
|
||||
----
|
||||
|
||||
The preceding command would create the following secret (which you can see by using `kubectl get secrets db-secret -o yaml`):
|
||||
|
||||
[source,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.
|
||||
|
||||
Your application can then use this secret -- for example, by exporting the secret's value as environment variables:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
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:
|
||||
+
|
||||
[source,bash]
|
||||
----
|
||||
-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:
|
||||
+
|
||||
[source,bash]
|
||||
----
|
||||
-Dspring.cloud.kubernetes.secrets.paths=/etc/secrets
|
||||
----
|
||||
|
||||
. By setting a named secret:
|
||||
+
|
||||
[source,bash]
|
||||
----
|
||||
-Dspring.cloud.kubernetes.secrets.name=db-secret
|
||||
----
|
||||
|
||||
. By defining a list of labels:
|
||||
+
|
||||
[source,bash]
|
||||
----
|
||||
-Dspring.cloud.kubernetes.secrets.labels.broker=activemq
|
||||
-Dspring.cloud.kubernetes.secrets.labels.db=postgresql
|
||||
----
|
||||
|
||||
As the case with `ConfigMap`, more advanced configuration is also possible where you can use multiple `Secret`
|
||||
instances. The `spring.cloud.kubernetes.secrets.sources` list makes this possible.
|
||||
For example, you could define the following `Secret` instances:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
application:
|
||||
name: cloud-k8s-app
|
||||
cloud:
|
||||
kubernetes:
|
||||
secrets:
|
||||
name: default-name
|
||||
namespace: default-namespace
|
||||
sources:
|
||||
# Spring Cloud Kubernetes looks up a Secret named s1 in namespace default-namespace
|
||||
- name: s1
|
||||
# Spring Cloud Kubernetes looks up a Secret named default-name in namespace n2
|
||||
- namespace: n2
|
||||
# Spring Cloud Kubernetes looks up a Secret named s3 in namespace n3
|
||||
- namespace: n3
|
||||
name: s3
|
||||
----
|
||||
|
||||
In the preceding example, if `spring.cloud.kubernetes.secrets.namespace` had not been set,
|
||||
the `Secret` named `s1` would be looked up in the namespace that the application runs.
|
||||
See xref:property-source-config/namespace-resolution.adoc[namespace-resolution] to get a better understanding of how the namespace
|
||||
of the application is resolved.
|
||||
|
||||
xref:property-source-config/configmap-propertysource.adoc#config-map-fail-fast[Similar to the `ConfigMaps`]; if you want your application to fail to start
|
||||
when it is unable to load `Secrets` property sources, you can set `spring.cloud.kubernetes.secrets.fail-fast=true`.
|
||||
|
||||
It is also possible to enable retry for `Secret` property sources xref:property-source-config/configmap-propertysource.adoc#config-map-retry[like the `ConfigMaps`].
|
||||
As with the `ConfigMap` property sources, first you need to set `spring.cloud.kubernetes.secrets.fail-fast=true`.
|
||||
Then you need to add `spring-retry` and `spring-boot-starter-aop` to your classpath.
|
||||
Retry behavior of the `Secret` property sources can be configured by setting the `spring.cloud.kubernetes.secrets.retry.*`
|
||||
properties.
|
||||
|
||||
NOTE: If you already have `spring-retry` and `spring-boot-starter-aop` on the classpath for some reason
|
||||
and want to enable fail-fast, but do not want retry to be enabled; you can disable retry for `Secrets` `PropertySources`
|
||||
by setting `spring.cloud.kubernetes.secrets.retry.enabled=false`.
|
||||
|
||||
.Properties:
|
||||
[options="header,footer"]
|
||||
|===
|
||||
| Name | Type | Default | Description
|
||||
| `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 look up
|
||||
| `spring.cloud.kubernetes.secrets.namespace` | `String` | Client namespace | Sets the Kubernetes namespace where to look up
|
||||
| `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)
|
||||
| `spring.cloud.kubernetes.secrets.enableApi` | `Boolean` | `false` | Enables or disables consuming secrets through APIs (examples 2 and 3)
|
||||
| `spring.cloud.kubernetes.secrets.fail-fast` | `Boolean` | `false` | Enable or disable failing the application start-up when an error occurred while loading a `Secret`
|
||||
| `spring.cloud.kubernetes.secrets.retry.enabled` | `Boolean` | `true` | Enable or disable secrets retry.
|
||||
| `spring.cloud.kubernetes.secrets.retry.initial-interval` | `Long` | `1000` | Initial retry interval in milliseconds.
|
||||
| `spring.cloud.kubernetes.secrets.retry.max-attempts` | `Integer` | `6` | Maximum number of attempts.
|
||||
| `spring.cloud.kubernetes.secrets.retry.max-interval` | `Long` | `2000` | Maximum interval for backoff.
|
||||
| `spring.cloud.kubernetes.secrets.retry.multiplier` | `Double` | `1.1` | Multiplier for next interval.
|
||||
|===
|
||||
|
||||
Notes:
|
||||
|
||||
* The `spring.cloud.kubernetes.secrets.labels` property behaves as defined by
|
||||
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-Configuration-Binding#map-based-binding[Map-based binding].
|
||||
* The `spring.cloud.kubernetes.secrets.paths` property behaves as defined by
|
||||
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-Configuration-Binding#collection-based-binding[Collection-based binding].
|
||||
* Access to secrets through the API may be restricted for security reasons. The preferred way is to mount secrets to the Pod.
|
||||
|
||||
You can find an example of an application that uses secrets (though it has not been updated to use the new `spring-cloud-kubernetes` project) at
|
||||
https://github.com/fabric8-quickstarts/spring-boot-camel-config[spring-boot-camel-config]
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
== Security Configurations Inside Kubernetes
|
||||
[[security-configurations-inside-kubernetes]]
|
||||
= Security Configurations Inside Kubernetes
|
||||
|
||||
|
||||
=== Namespace
|
||||
[[namespace]]
|
||||
== Namespace
|
||||
|
||||
Most of the components provided in this project need to know the namespace. For Kubernetes (1.3+), the namespace is made available to the pod as part of the service account secret and is automatically detected by the client.
|
||||
For earlier versions, it needs to be specified as an environment variable to the pod. A quick way to do this is as follows:
|
||||
|
||||
====
|
||||
[source]
|
||||
----
|
||||
env:
|
||||
@@ -15,9 +16,9 @@ For earlier versions, it needs to be specified as an environment variable to the
|
||||
fieldRef:
|
||||
fieldPath: "metadata.namespace"
|
||||
----
|
||||
====
|
||||
|
||||
=== Service Account
|
||||
[[service-account]]
|
||||
== Service Account
|
||||
|
||||
For distributions 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 or pod, you need to make sure they have the correct roles.
|
||||
@@ -46,7 +47,6 @@ For development purposes, you can add `cluster-reader` permissions to your `defa
|
||||
|
||||
The following Role and RoleBinding are an example for namespaced permissions for the `default` account:
|
||||
|
||||
====
|
||||
[source,yaml]
|
||||
----
|
||||
kind: Role
|
||||
@@ -75,4 +75,3 @@ roleRef:
|
||||
name: namespace-reader
|
||||
apiGroup: ""
|
||||
----
|
||||
====
|
||||
@@ -1,4 +1,6 @@
|
||||
== Service Registry Implementation
|
||||
[[service-registry-implementation]]
|
||||
= Service Registry Implementation
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
In Kubernetes service registration is controlled by the platform, the application itself does not control
|
||||
registration as it may do in other platforms. For this reason using `spring.cloud.service-registry.auto-registration.enabled`
|
||||
@@ -1,5 +1,5 @@
|
||||
[#spring-cloud-kubernetes-configserver]
|
||||
## Spring Cloud Kubernetes Config Server
|
||||
[spring-cloud-kubernetes-configserver]
|
||||
= Spring Cloud Kubernetes Config Server
|
||||
|
||||
The Spring Cloud Kubernetes Config Server, is based on https://spring.io/projects/spring-cloud-config[Spring Cloud Config Server] and adds an https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#_environment_repository[environment repository] for Kubernetes
|
||||
https://kubernetes.io/docs/concepts/configuration/configmap/[Config Maps] and https://kubernetes.io/docs/concepts/configuration/secret/[Secrets].
|
||||
@@ -11,17 +11,17 @@ A default image is located on https://hub.docker.com/r/springcloud/spring-cloud-
|
||||
the code and image yourself. However, if you need to customize the config server behavior or prefer to build the image yourself you can easily build your own
|
||||
image from the https://github.com/spring-cloud/spring-cloud-kubernetes/tree/main/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver[source code on GitHub] and use that.
|
||||
|
||||
### Configuration
|
||||
## Configuration
|
||||
|
||||
#### Enabling The Kubernetes Environment Repository
|
||||
### Enabling The Kubernetes Environment Repository
|
||||
To enable the Kubernetes environment repository the `kubernetes` profile must be included in the list of active profiles.
|
||||
You may activate other profiles as well to use other environment repository implementations.
|
||||
|
||||
#### Config Map and Secret PropertySources
|
||||
### Config Map and Secret PropertySources
|
||||
By default, only Config Map data will be fetched. To enable Secrets as well you will need to set `spring.cloud.kubernetes.secrets.enableApi=true`.
|
||||
You can disable the Config Map `PropertySource` by setting `spring.cloud.kubernetes.config.enableApi=false`.
|
||||
|
||||
#### Fetching Config Map and Secret Data From Additional Namespaces
|
||||
### Fetching Config Map and Secret Data From Additional Namespaces
|
||||
By default, the Kubernetes environment repository will only fetch Config Map and Secrets from the namespace in which it is deployed.
|
||||
If you want to include data from other namespaces you can set `spring.cloud.kubernetes.configserver.config-map-namespaces` and/or `spring.cloud.kubernetes.configserver.secrets-namespaces` to a comma separated
|
||||
list of namespace values.
|
||||
@@ -29,15 +29,14 @@ list of namespace values.
|
||||
NOTE: If you set `spring.cloud.kubernetes.configserver.config-map-namespaces` and/or `spring.cloud.kubernetes.configserver.secrets-namespaces`
|
||||
you will need to include the namespace in which the Config Server is deployed in order to continue to fetch Config Map and Secret data from that namespace.
|
||||
|
||||
#### Kubernetes Access Controls
|
||||
### Kubernetes Access Controls
|
||||
The Kubernetes Config Server uses the Kubernetes API server to fetch Config Map and Secret data. In order for it to do that
|
||||
it needs ability to `get` and `list` Config Map and Secrets (depending on what you enable/disable).
|
||||
|
||||
### Deployment Yaml
|
||||
## Deployment Yaml
|
||||
|
||||
Below is a sample deployment, service and permissions configuration you can use to deploy a basic Config Server to Kubernetes.
|
||||
|
||||
====
|
||||
[source,yaml]
|
||||
----
|
||||
---
|
||||
@@ -119,4 +118,3 @@ items:
|
||||
- containerPort: 8888
|
||||
|
||||
----
|
||||
====
|
||||
@@ -1,5 +1,5 @@
|
||||
[#spring-cloud-kubernetes-configuration-watcher]
|
||||
## Spring Cloud Kubernetes Configuration Watcher
|
||||
[spring-cloud-kubernetes-configuration-watcher]
|
||||
= Spring Cloud Kubernetes Configuration Watcher
|
||||
|
||||
Kubernetes provides the ability to https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume[mount a ConfigMap or Secret as a volume]
|
||||
in the container of your application. When the contents of the ConfigMap or Secret changes, the https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#mounted-configmaps-are-updated-automatically[mounted volume will be updated with those changes].
|
||||
@@ -20,11 +20,10 @@ Spring Cloud Kubernetes Configuration Watcher can send refresh notifications to
|
||||
1. Over HTTP in which case the application being notified must of the `/refresh` actuator endpoint exposed and accessible from within the cluster
|
||||
2. Using Spring Cloud Bus, in which case you will need a message broker deployed to your custer for the application to use.
|
||||
|
||||
### Deployment YAML
|
||||
## Deployment YAML
|
||||
|
||||
Below is a sample deployment YAML you can use to deploy the Kubernetes Configuration Watcher to Kubernetes.
|
||||
|
||||
====
|
||||
[source,yaml]
|
||||
----
|
||||
---
|
||||
@@ -103,12 +102,11 @@ items:
|
||||
- containerPort: 8888
|
||||
|
||||
----
|
||||
====
|
||||
|
||||
The Service Account and associated Role Binding is important for Spring Cloud Kubernetes Configuration to work properly.
|
||||
The controller needs access to read data about ConfigMaps, Pods, Services, Endpoints and Secrets in the Kubernetes cluster.
|
||||
|
||||
### Monitoring ConfigMaps and Secrets
|
||||
## Monitoring ConfigMaps and Secrets
|
||||
|
||||
Spring Cloud Kubernetes Configuration Watcher will react to changes in ConfigMaps with a label of `spring.cloud.kubernetes.config` with the value `true`
|
||||
or any Secret with a label of `spring.cloud.kubernetes.secret` with the value `true`. If the ConfigMap or Secret does not have either of those labels
|
||||
@@ -127,7 +125,6 @@ that specifies the names of applications that will receive a notification when c
|
||||
|
||||
For example:
|
||||
|
||||
====
|
||||
[source,yaml]
|
||||
----
|
||||
kind: ConfigMap
|
||||
@@ -139,21 +136,19 @@ metadata:
|
||||
annotations:
|
||||
spring.cloud.kubernetes.configmap.apps: "app-a, app-b"
|
||||
----
|
||||
====
|
||||
|
||||
### HTTP Implementation
|
||||
## HTTP Implementation
|
||||
|
||||
The HTTP implementation is what is used by default. When this implementation is used Spring Cloud Kubernetes Configuration Watcher and a
|
||||
change to a ConfigMap or Secret occurs then the HTTP implementation will use the Spring Cloud Kubernetes Discovery Client to fetch all
|
||||
instances of the application which match the name of the ConfigMap or Secret and send an HTTP POST request to the application's actuator
|
||||
`/refresh` endpoint. By default it will send the post request to `/actuator/refresh` using the port registered in the discovery client.
|
||||
|
||||
#### Non-Default Management Port and Actuator Path
|
||||
### Non-Default Management Port and Actuator Path
|
||||
|
||||
If the application is using a non-default actuator path and/or using a different port for the management endpoints, the Kubernetes service for the application
|
||||
can add an annotation called `boot.spring.io/actuator` and set its value to the path and port used by the application. For example
|
||||
|
||||
====
|
||||
[source,yaml]
|
||||
----
|
||||
apiVersion: v1
|
||||
@@ -172,24 +167,22 @@ spec:
|
||||
selector:
|
||||
app: config-map-demo
|
||||
----
|
||||
====
|
||||
|
||||
|
||||
Another way you can choose to configure the actuator path and/or management port is by setting
|
||||
`spring.cloud.kubernetes.configuration.watcher.actuatorPath` and `spring.cloud.kubernetes.configuration.watcher.actuatorPort`.
|
||||
|
||||
### Messaging Implementation
|
||||
## Messaging Implementation
|
||||
|
||||
The messaging implementation can be enabled by setting profile to either `bus-amqp` (RabbitMQ) or `bus-kafka` (Kafka) when the Spring Cloud Kubernetes Configuration Watcher
|
||||
application is deployed to Kubernetes.
|
||||
|
||||
### Configuring RabbitMQ
|
||||
## Configuring RabbitMQ
|
||||
|
||||
When the `bus-amqp` profile is enabled you will need to configure Spring RabbitMQ to point it to the location of the RabbitMQ
|
||||
instance you would like to use as well as any credentials necessary to authenticate. This can be done
|
||||
by setting the standard Spring RabbitMQ properties, for example
|
||||
|
||||
====
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
@@ -198,14 +191,12 @@ spring:
|
||||
password: password
|
||||
host: rabbitmq
|
||||
----
|
||||
====
|
||||
|
||||
### Configuring Kafka
|
||||
## Configuring Kafka
|
||||
|
||||
When the `bus-kafka` profile is enabled you will need to configure Spring Kafka to point it to the location of the Kafka Broker
|
||||
instance you would like to use. This can be done by setting the standard Spring Kafka properties, for example
|
||||
|
||||
====
|
||||
[source,yaml]
|
||||
----
|
||||
spring:
|
||||
@@ -213,4 +204,3 @@ spring:
|
||||
producer:
|
||||
bootstrap-servers: localhost:9092
|
||||
----
|
||||
====
|
||||
@@ -1,27 +1,26 @@
|
||||
[#spring-cloud-kubernetes-discoveryserver]
|
||||
## Spring Cloud Kubernetes Discovery Server
|
||||
[spring-cloud-kubernetes-discoveryserver]
|
||||
= Spring Cloud Kubernetes Discovery Server
|
||||
|
||||
The Spring Cloud Kubernetes Discovery Server provides HTTP endpoints apps can use to gather information
|
||||
about services available within a Kubernetes cluster. The Spring Cloud Kubernetes Discovery Server
|
||||
can be used by apps using the `spring-cloud-starter-kubernetes-discoveryclient` to provide data to
|
||||
the `DiscoveryClient` implementation provided by that starter.
|
||||
|
||||
### Permissions
|
||||
## Permissions
|
||||
The Spring Cloud Discovery server uses
|
||||
the Kubernetes API server to get data about Service and Endpoint resrouces so it needs list, watch, and
|
||||
get permissions to use those endpoints. See the below sample Kubernetes deployment YAML for an
|
||||
examlpe of how to configure the Service Account on Kubernetes.
|
||||
|
||||
|
||||
### Endpoints
|
||||
## Endpoints
|
||||
There are three endpoints exposed by the server.
|
||||
|
||||
#### `/apps`
|
||||
### `/apps`
|
||||
|
||||
A `GET` request sent to `/apps` will return a JSON array of available services. Each item contains
|
||||
the name of the Kubernetes service and service instance information. Below is a sample response.
|
||||
|
||||
====
|
||||
[source,json]
|
||||
----
|
||||
[
|
||||
@@ -67,14 +66,12 @@ the name of the Kubernetes service and service instance information. Below is a
|
||||
}
|
||||
]
|
||||
----
|
||||
====
|
||||
|
||||
#### `/apps/{name}`
|
||||
### `/apps/\{name}`
|
||||
|
||||
A `GET` request to `/apps/{name}` can be used to get instance data for all instances of a given
|
||||
A `GET` request to `/apps/\{name}` can be used to get instance data for all instances of a given
|
||||
service. Below is a sample response when a `GET` request is made to `/apps/kubernetes`.
|
||||
|
||||
====
|
||||
[source,json]
|
||||
----
|
||||
[
|
||||
@@ -95,14 +92,12 @@ service. Below is a sample response when a `GET` request is made to `/apps/kube
|
||||
}
|
||||
]
|
||||
----
|
||||
====
|
||||
|
||||
#### `/app/{name}/{instanceid}`
|
||||
### `/app/\{name}/\{instanceid}`
|
||||
|
||||
A `GET` request made to `/app/{name}/{instanceid}` will return the instance data for a specific
|
||||
A `GET` request made to `/app/\{name}/\{instanceid}` will return the instance data for a specific
|
||||
instance of a given service. Below is a sample response when a `GET` request is made to `/app/kubernetes/1234`.
|
||||
|
||||
====
|
||||
[source,json]
|
||||
----
|
||||
{
|
||||
@@ -121,9 +116,8 @@ instance of a given service. Below is a sample response when a `GET` request is
|
||||
"scheme":"http"
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
### Deployment YAML
|
||||
## Deployment YAML
|
||||
|
||||
An image of the Spring Cloud Discovery Server is hosted on https://hub.docker.com/r/springcloud/spring-cloud-kubernetes-discoveryserver[Docker Hub].
|
||||
However, if you need to customize the discovery server behavior or prefer to build the image yourself you can easily build your own
|
||||
@@ -131,7 +125,6 @@ image from the https://github.com/spring-cloud/spring-cloud-kubernetes/tree/main
|
||||
|
||||
Below is a sample deployment YAML you can use to deploy the Kubernetes Configuration Watcher to Kubernetes.
|
||||
|
||||
====
|
||||
[source,yaml]
|
||||
----
|
||||
---
|
||||
@@ -211,4 +204,3 @@ items:
|
||||
|
||||
|
||||
----
|
||||
====
|
||||
@@ -1,52 +1,41 @@
|
||||
[[spring-cloud-kubernetes]]
|
||||
= Spring Cloud Kubernetes
|
||||
include::_attributes.adoc[]
|
||||
|
||||
This reference guide covers how to use Spring Cloud Kubernetes.
|
||||
|
||||
[[why-do-you-need-spring-cloud-kubernetes]]
|
||||
== Why do you need Spring Cloud Kubernetes?
|
||||
|
||||
Spring Cloud Kubernetes provides implementations of well known Spring Cloud interfaces allowing developers to build and run Spring Cloud applications on Kubernetes. While this project may be useful to you when building a cloud native application, it is also not a requirement in order to deploy a Spring Boot app on Kubernetes. If you are just getting started in your journey to running your Spring Boot app on Kubernetes you can accomplish a lot with nothing more than a basic Spring Boot app and Kubernetes itself. To learn more, you can get started by reading the https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#cloud-deployment-kubernetes[Spring Boot reference documentation for deploying to Kubernetes ] and also working through the workshop material https://hackmd.io/@ryanjbaxter/spring-on-k8s-workshop[Spring and Kubernetes].
|
||||
|
||||
include::getting-started.adoc[]
|
||||
|
||||
include::discovery-client.adoc[]
|
||||
|
||||
include::discovery-kubernetes-native.adoc[]
|
||||
|
||||
include::property-source-config.adoc[]
|
||||
|
||||
include::kubernetes-awareness.adoc[]
|
||||
|
||||
include::pod-health-indicator.adoc[]
|
||||
|
||||
include::info-contributor.adoc[]
|
||||
|
||||
include::leader-election.adoc[]
|
||||
|
||||
include::load-balancer.adoc[]
|
||||
|
||||
include::security-service-accounts.adoc[]
|
||||
|
||||
include::service-registry.adoc[]
|
||||
|
||||
include::spring-cloud-kubernetes-configuration-watcher.adoc[]
|
||||
|
||||
include::spring-cloud-kubernetes-configserver.adoc[]
|
||||
|
||||
include::spring-cloud-kubernetes-discoveryserver.adoc[]
|
||||
|
||||
include::examples.adoc[]
|
||||
|
||||
include::other-resources.adoc[]
|
||||
|
||||
[[configuration-properties]]
|
||||
== Configuration properties
|
||||
|
||||
To see the list of all Kubernetes related configuration properties please check link:appendix.html[the Appendix page].
|
||||
|
||||
[[building]]
|
||||
== Building
|
||||
|
||||
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/building.adoc[]
|
||||
Click https://docs.spring.io/spring-cloud-build/reference/building.html[here] for basic building instructions.
|
||||
|
||||
|
||||
[[building-docker-images-on-arm64]]
|
||||
=== Building Docker Images On ARM64
|
||||
|
||||
If you run the Spring Cloud Kuberentes build on an ARM64 machine the docker images
|
||||
@@ -60,10 +49,13 @@ For example:
|
||||
```
|
||||
|
||||
|
||||
[[contributing]]
|
||||
== Contributing
|
||||
|
||||
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/contributing.adoc[]
|
||||
Click https://docs.spring.io/spring-cloud-build/reference/contributing.html[here] for instructions on contributing to this project.
|
||||
|
||||
|
||||
[[aot-and-native-image-support]]
|
||||
== AOT and native image support
|
||||
|
||||
At this point, Spring Cloud Kubernetes does not support Spring Boot AOT transformations or native images. Partial support might be added in future releases.
|
||||
24
docs/pom.xml
24
docs/pom.xml
@@ -9,6 +9,7 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes</artifactId>
|
||||
<version>3.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring Cloud Kubernetes Docs</name>
|
||||
@@ -17,7 +18,6 @@
|
||||
<docs.main>spring-cloud-kubernetes</docs.main>
|
||||
<main.basedir>${basedir}/..</main.basedir>
|
||||
<configprops.inclusionPattern>spring.cloud.kubernetes.*</configprops.inclusionPattern>
|
||||
<upload-docs-zip.phase>deploy</upload-docs-zip.phase>
|
||||
<!-- Don't upload docs jar to central / repo.spring.io -->
|
||||
<maven-deploy-plugin-default.phase>none</maven-deploy-plugin-default.phase>
|
||||
</properties>
|
||||
@@ -42,26 +42,32 @@
|
||||
<profile>
|
||||
<id>docs</id>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/antora/resources/antora-resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||
<groupId>io.spring.maven.antora</groupId>
|
||||
<artifactId>antora-component-version-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>io.spring.maven.antora</groupId>
|
||||
<artifactId>antora-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
||||
20
docs/src/main/antora/resources/antora-resources/antora.yml
Normal file
20
docs/src/main/antora/resources/antora-resources/antora.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
version: @antora-component.version@
|
||||
prerelease: @antora-component.prerelease@
|
||||
|
||||
asciidoc:
|
||||
attributes:
|
||||
attribute-missing: 'warn'
|
||||
chomp: 'all'
|
||||
project-root: @maven.multiModuleProjectDirectory@
|
||||
github-repo: @docs.main@
|
||||
github-raw: https://raw.githubusercontent.com/spring-cloud/@docs.main@/@github-tag@
|
||||
github-code: https://github.com/spring-cloud/@docs.main@/tree/@github-tag@
|
||||
github-issues: https://github.com/spring-cloud/@docs.main@/issues/
|
||||
github-wiki: https://github.com/spring-cloud/@docs.main@/wiki
|
||||
spring-cloud-version: @project.version@
|
||||
github-tag: @github-tag@
|
||||
version-type: @version-type@
|
||||
docs-url: https://docs.spring.io/@docs.main@/docs/@project.version@
|
||||
raw-docs-url: https://raw.githubusercontent.com/spring-cloud/@docs.main@/@github-tag@
|
||||
project-version: @project.version@
|
||||
project-name: @docs.main@
|
||||
@@ -1 +0,0 @@
|
||||
include::spring-cloud-kubernetes.adoc[]
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
include::spring-cloud-kubernetes.adoc[]
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,12 +0,0 @@
|
||||
Spring Cloud Kubernetes provide Spring Cloud common interface implementations that consume Kubernetes native services.
|
||||
The main objective of the projects provided in this repository is to facilitate the integration of Spring Cloud and Spring Boot applications running inside Kubernetes.
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
* Kubernetes awareness
|
||||
* `DiscoveryClient` implementation
|
||||
* `PropertySource` objects configured via ConfigMaps
|
||||
|
||||
## Getting Started
|
||||
The easiest way to get started is by including the Spring Cloud BOM and then adding `spring-cloud-starter-kubernetes-client-all` to your application's classpath. If you don't want to include all of the Spring Cloud Kubernetes features you can add individual starters for the features you would like. By default Spring Cloud Kubernetes will enable the `kubernetes` profile when it detects it is running inside a Kubernetes cluster. You can take advantage of this by creating a `kubernetes-application` configuration properties for anything specific to Kubernetes you might want to configure. Once the starter is on the classpath the application should behave as any other Spring Cloud application.
|
||||
Reference in New Issue
Block a user