You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some Spring Cloud components use the `DiscoveryClient` in order to obtain information about the local service instance. For
125
125
this to work, you need to align the Kubernetes service name with the `spring.application.name` property.
126
126
127
+
Spring Cloud Kubernetes can also watch the Kubernetes service catalog for changes and update the
128
+
`DiscoveryClient` implementation accordingly. In order to enable this functionality you need to add
129
+
`@EnableScheduling` on a configuration class in your application.
130
+
127
131
== Kubernetes native service discovery
128
132
129
133
Kubernetes itself is capable of (server side) service discovery (see: https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services).
@@ -138,7 +142,7 @@ Additionally, you can use Hystrix for:
138
142
139
143
== Kubernetes PropertySource implementations
140
144
141
-
The most common approach to configuring your Spring Boot application is to create an `application.properties` or `applicaiton.yaml` or
145
+
The most common approach to configuring your Spring Boot application is to create an `application.properties` or `application.yaml` or
142
146
an `application-profile.properties` or `application-profile.yaml` file that contains key-value pairs that provide customization values to your
143
147
application or Spring Boot starters. You can override these properties by specifying system properties or environment
144
148
variables.
@@ -320,26 +324,89 @@ However, if the `production` profile is active, the configuration becomes:
320
324
321
325
If both profiles are active, the property that appears last within the `ConfigMap` overwrites any preceding values.
322
326
323
-
324
-
To tell Spring Boot which `profile` should be enabled at bootstrap, you can pass a system property to the Java
325
-
command. To do so, you can launch your Spring Boot application with an environment variable that you can define with the OpenShift
326
-
`DeploymentConfig` or Kubernetes `ReplicationConfig` resource file, as follows:
327
+
Another option is to create a different config map per profile and spring boot will automatically fetch it based
328
+
on active profiles
327
329
328
330
====
329
331
[source,yaml]
330
332
----
333
+
kind: ConfigMap
331
334
apiVersion: v1
332
-
kind: DeploymentConfig
335
+
metadata:
336
+
name: demo
337
+
data:
338
+
application.yml: |-
339
+
greeting:
340
+
message: Say Hello to the World
341
+
farewell:
342
+
message: Say Goodbye
343
+
----
344
+
====
345
+
====
346
+
[source,yaml]
347
+
----
348
+
kind: ConfigMap
349
+
apiVersion: v1
350
+
metadata:
351
+
name: demo-development
352
+
data:
353
+
application.yml: |-
354
+
spring:
355
+
profiles: development
356
+
greeting:
357
+
message: Say Hello to the Developers
358
+
farewell:
359
+
message: Say Goodbye to the Developers
360
+
----
361
+
====
362
+
====
363
+
[source,yaml]
364
+
----
365
+
kind: ConfigMap
366
+
apiVersion: v1
367
+
metadata:
368
+
name: demo-production
369
+
data:
370
+
application.yml: |-
371
+
spring:
372
+
profiles: production
373
+
greeting:
374
+
message: Say Hello to the Ops
375
+
farewell:
376
+
message: Say Goodbye
377
+
----
378
+
====
379
+
380
+
381
+
To tell Spring Boot which `profile` should be enabled at bootstrap, you can pass `SPRING_PROFILES_ACTIVE` environment variable.
382
+
To do so, you can launch your Spring Boot application with an environment variable that you can define it in the PodSpec at the container specification.
383
+
Deployment resource file, as follows:
384
+
385
+
====
386
+
[source,yaml]
387
+
----
388
+
apiVersion: apps/v1
389
+
kind: Deployment
390
+
metadata:
391
+
name: deployment-name
392
+
labels:
393
+
app: deployment-name
333
394
spec:
334
395
replicas: 1
335
-
...
336
-
spec:
337
-
containers:
338
-
- env:
339
-
- name: JAVA_APP_DIR
340
-
value: /deployments
341
-
- name: JAVA_OPTIONS
342
-
value: -Dspring.profiles.active=developer
396
+
selector:
397
+
matchLabels:
398
+
app: deployment-name
399
+
template:
400
+
metadata:
401
+
labels:
402
+
app: deployment-name
403
+
spec:
404
+
containers:
405
+
- name: container-name
406
+
image: your-image
407
+
env:
408
+
- name: SPRING_PROFILES_ACTIVE
409
+
value: "development"
343
410
----
344
411
====
345
412
@@ -483,6 +550,36 @@ If you have all the secrets mapped to a common root, you can set them like:
483
550
----
484
551
====
485
552
553
+
As the case with `ConfigMap`, more advanced configuration is also possible where you can use multiple `Secret`
554
+
instances. The `spring.cloud.kubernetes.secrets.sources` list makes this possible.
555
+
For example, you could define the following `Secret` instances:
556
+
557
+
====
558
+
[source,yaml]
559
+
----
560
+
spring:
561
+
application:
562
+
name: cloud-k8s-app
563
+
cloud:
564
+
kubernetes:
565
+
secrets:
566
+
name: default-name
567
+
namespace: default-namespace
568
+
sources:
569
+
# Spring Cloud Kubernetes looks up a Secret named s1 in namespace default-namespace
570
+
- name: s1
571
+
# Spring Cloud Kubernetes looks up a Secret named default-name in whatever namespace n2
572
+
- namespace: n2
573
+
# Spring Cloud Kubernetes looks up a Secret named s3 in namespace n3
574
+
- namespace: n3
575
+
name: s3
576
+
----
577
+
====
578
+
579
+
In the preceding example, if `spring.cloud.kubernetes.secrets.namespace` had not been set,
580
+
the `Secret` named `s1` would be looked up in the namespace that the application runs.
581
+
582
+
486
583
.Properties:
487
584
[options="header,footer"]
488
585
|===
@@ -584,7 +681,7 @@ The reload feature supports two operating modes:
584
681
Any event produces a re-check on the configuration and, in case of changes, a reload.
585
682
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
586
683
(by default, secrets are not monitored).
587
-
* Polling: Oeriodically re-creates the configuration from config maps and secrets to see if it has changed.
684
+
* Polling: Periodically re-creates the configuration from config maps and secrets to see if it has changed.
588
685
You can configure the polling period by using the `spring.cloud.kubernetes.reload.period` property and defaults to 15 seconds.
589
686
It requires the same role as the monitored property source.
590
687
This means, for example, that using polling on file-mounted secret sources does not require particular privileges.
@@ -596,7 +693,7 @@ This means, for example, that using polling on file-mounted secret sources does
596
693
| `spring.cloud.kubernetes.reload.enabled` | `Boolean` | `false` | Enables monitoring of property sources and configuration reload
| `spring.cloud.kubernetes.reload.strategy` | `Enum` | `refresh` | The strategy to use when firing a reload (`refresh`, `restart_context`, or `shutdown`)
696
+
| `spring.cloud.kubernetes.reload.strategy` | `Enum` | `refresh` | The strategy to use when firing a reload (`refresh`, `restart_context`, or `shutdown`)
600
697
| `spring.cloud.kubernetes.reload.mode` | `Enum` | `event` | Specifies how to listen for changes in property sources (`event` or `polling`)
601
698
| `spring.cloud.kubernetes.reload.period` | `Duration`| `15s` | The period for verifying changes when using the `polling` strategy
602
699
|===
@@ -652,7 +749,6 @@ the `PortName` key. If you want to specify in which Kubernetes namespace the tar
652
749
the `KubernetesNamespace` key, remembering in both instances to prefix these keys with your service name and
653
750
`ribbon` prefix, as specified earlier.
654
751
655
-
656
752
.Spring Cloud Kubernetes Ribbon Configuration
657
753
|===
658
754
|Property Key |Type |Default Value
@@ -679,7 +775,6 @@ the `SERVICE` mode uses load balancing of the Kubernetes service to support Isti
679
775
680
776
* `spring.cloud.kubernetes.ribbon.cluster-domain` Set the custom Kubernetes cluster domain suffix. The default value is: 'cluster.local'
681
777
682
-
683
778
The following examples use this module for ribbon discovery:
684
779
685
780
* link:./spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example[Spring Cloud Circuitbreaker and Ribbon]
@@ -1011,6 +1106,7 @@ $ touch .springformat
1011
1106
==== Intellij IDEA
1012
1107
1013
1108
In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.
1109
+
The following files can be found in the https://github.com/spring-cloud/spring-cloud-build/tree/master/spring-cloud-build-tools[Spring Cloud Build] project.
1014
1110
1015
1111
.spring-cloud-build-tools/
1016
1112
----
@@ -1055,4 +1151,4 @@ Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on t
1055
1151
- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL.
1056
1152
- `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`.
1057
1153
1058
-
IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources.
1154
+
IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources.
Copy file name to clipboardExpand all lines: spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigMapPropertySource.java
Copy file name to clipboardExpand all lines: spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/SecretsConfigProperties.java
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -95,16 +95,16 @@ public List<SecretsConfigProperties.NormalizedSource> determineSources() {
Copy file name to clipboardExpand all lines: spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/SecretsPropertySource.java
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -42,21 +42,21 @@ public class SecretsPropertySource extends MapPropertySource {
0 commit comments