Skip to content

Commit 74e36d4

Browse files
committed
docs(cloud-config-demo): enhence Kubernetes cluster usages
Signed-off-by: lony2003 <zhangke200377@outlook.com>
1 parent 29fa755 commit 74e36d4

File tree

8 files changed

+104
-32
lines changed

8 files changed

+104
-32
lines changed

spring-boot-examples/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ This example consists of three applications:
99
- Subscribe to messages
1010
- Cloud Config Demo:
1111
- Import and use configs
12-
- Can not run in Kubernetes currently, as lack of redis pre-fill data supported
1312

1413
## Running these examples from source code
1514

@@ -71,6 +70,29 @@ cd consumer-app/
7170
<!-- END_STEP -->
7271
The `consumer-app` starts in port `8081` by default.
7372

73+
To run `cloud-config-demo`, you should run in a terminal (`cloud-config-demo` doesn't depends on two applications above):
74+
<!-- STEP
75+
name: Run Demo Producer Service
76+
match_order: none
77+
output_match_mode: substring
78+
expected_stdout_lines:
79+
- 'Started ProducerApplication'
80+
background: true
81+
expected_return_code: 143
82+
sleep: 30
83+
timeout_seconds: 45
84+
-->
85+
<!-- Timeout for above service must be more than sleep + timeout for the client-->
86+
87+
```sh
88+
cd cloud-config-demo/
89+
../../mvnw -Dspring-boot.run.arguments="--reuse=true" spring-boot:test-run
90+
```
91+
92+
<!-- END_STEP -->
93+
94+
It will work and gain secrets from secret store. you can also uncomment the lines in application.yaml to enable more configuration imports.
95+
7496
## Interacting with the applications
7597

7698
Now that both applications are up you can place an order by sending a POST request to `:8080/orders/`

spring-boot-examples/cloud-config-demo/src/main/java/io/dapr/springboot/examples/cloudconfig/config/MultipleConfig.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ public class MultipleConfig {
1313
@Value("${dapr.spring.demo-config-secret.multivalue.v2}")
1414
private String multipleSecretConfigV2;
1515

16-
//should be cloud
17-
@Value("${dapr.spring.demo-config-config.multivalue.v3}")
18-
private String multipleConfigurationConfigV3;
1916

2017
public String getMultipleSecretConfigV1() {
2118
return multipleSecretConfigV1;
@@ -32,12 +29,4 @@ public String getMultipleSecretConfigV2() {
3229
public void setMultipleSecretConfigV2(String multipleSecretConfigV2) {
3330
this.multipleSecretConfigV2 = multipleSecretConfigV2;
3431
}
35-
36-
public String getMultipleConfigurationConfigV3() {
37-
return multipleConfigurationConfigV3;
38-
}
39-
40-
public void setMultipleConfigurationConfigV3(String multipleConfigurationConfigV3) {
41-
this.multipleConfigurationConfigV3 = multipleConfigurationConfigV3;
42-
}
4332
}

spring-boot-examples/cloud-config-demo/src/main/java/io/dapr/springboot/examples/cloudconfig/config/SingleConfig.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,11 @@ public class SingleConfig {
1010
@Value("${dapr.spring.demo-config-secret.singlevalue}")
1111
private String singleValueSecret;
1212

13-
// should be testvalue
14-
@Value("${dapr.spring.demo-config-config.singlevalue}")
15-
private String singleValueConfig;
16-
1713
public String getSingleValueSecret() {
1814
return singleValueSecret;
1915
}
2016

2117
public void setSingleValueSecret(String singleValueSecret) {
2218
this.singleValueSecret = singleValueSecret;
2319
}
24-
25-
public String getSingleValueConfig() {
26-
return singleValueConfig;
27-
}
28-
29-
public void setSingleValueConfig(String singleValueConfig) {
30-
this.singleValueConfig = singleValueConfig;
31-
}
3220
}

spring-boot-examples/cloud-config-demo/src/main/resources/application.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ spring:
55
import:
66
- dapr:secret:democonfig/multivalue-properties?type=doc
77
- dapr:secret:democonfig/dapr.spring.demo-config-secret.singlevalue?type=value
8-
#- dapr:secret:democonfigmulti/value1?type=value
9-
- dapr:config:democonfigconf/dapr.spring.demo-config-config.singlevalue?type=value
10-
- dapr:config:democonfigconf/multivalue-yaml?type=doc&doc-type=yaml
11-
8+
# Following line works by default even if no secret store components defined in dapr running
9+
# inside kubernetes cluster
10+
# To maintain the compatibility of local version, we defined a secret store to dapr kubernetes,
11+
# so following lines are commented.
12+
# - dapr:secret:kubernetes/multivalue-properties?type=doc
13+
# - dapr:secret:kubernetes/dapr.spring.demo-config-secret.singlevalue?type=value
1214

15+
# Following line includes dapr configuration schema of Cloud Config
16+
# Unfortunately current dapr runtime doesn't support Kubernetes ConfigMap for configuration,
17+
# so to maintain the compatibility of Kubernetes, following lines are commented.
18+
# - dapr:config:democonfigconf/dapr.spring.demo-config-config.singlevalue?type=value
19+
# - dapr:config:democonfigconf/multivalue-yaml?type=doc&doc-type=yaml

spring-boot-examples/cloud-config-demo/src/test/java/io/dapr/springboot/examples/cloudconfig/CloudConfigTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ void testCloudConfig() {
145145
assertEquals("testvalue", singleConfig.getSingleValueSecret());
146146
assertEquals("spring", multipleConfig.getMultipleSecretConfigV1());
147147
assertEquals("dapr", multipleConfig.getMultipleSecretConfigV2());
148-
149-
assertEquals("testvalue", singleConfig.getSingleValueConfig());
150-
151-
assertEquals("cloud", multipleConfig.getMultipleConfigurationConfigV3());
152148
}
153149

154150
}

spring-boot-examples/kubernetes/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
To run this example on Kubernetes, you can use any Kubernetes distribution.
44
We install Dapr on a Kubernetes cluster and then we will deploy both the `producer-app` and `consumer-app`.
55

6+
You can also deploy `cloud-config-demo` if you like, but actually it doesn't have any feature.
7+
8+
> Remind that only Kubernetes Secret works on dapr secret, Kubernetes ConfigMap doesn't support in dapr runtime, and there is no easy way to fill data to redis running in cluster before container started automatically, so configuration schema are commented by default.
9+
610
## Creating a cluster and installing Dapr
711

812
If you don't have any Kubernetes cluster you can use Kubernetes KIND to create a local cluster. We will create a cluster
@@ -35,6 +39,32 @@ helm upgrade --install dapr dapr/dapr \
3539
--create-namespace \
3640
--wait
3741
```
42+
__Optional: pre-configure data needed by `cloud-config-demo`__
43+
44+
If you want to run `cloud-config-demo` on your cluster, you should apply the secrets file from `secrets/kubernates-secrets-multivalue.yaml`, or you can just run following command:
45+
46+
```bash
47+
cat <<EOF | kubectl apply -f -
48+
apiVersion: v1
49+
kind: Secret
50+
metadata:
51+
name: multivalue-properties
52+
type: Opaque
53+
stringData:
54+
value1: |
55+
dapr.spring.demo-config-secret.multivalue.v1=spring
56+
dapr.spring.demo-config-secret.multivalue.v2=dapr
57+
value2: "dapr.spring.demo-config-secret.multivalue.v3=cloud"
58+
---
59+
apiVersion: v1
60+
kind: Secret
61+
metadata:
62+
name: dapr.spring.demo-config-secret.singlevalue
63+
type: Opaque
64+
stringData:
65+
value: "dapr.spring.demo-config-secret.singlevalue=testvalue"
66+
EOF
67+
```
3868

3969
## Creating containers using Spring Boot and pushing to local registry
4070

@@ -77,6 +107,21 @@ docker push localhost:5001/sb-consumer-app
77107
podman push localhost:5001/sb-consumer-app --tls-verify=false
78108
```
79109

110+
__Optional: deploy `cloud-config-demo`__
111+
112+
From inside the `spring-boot-examples/cloud-config-demo` directory you can run the following command to create a container:
113+
```bash
114+
mvn spring-boot:build-image
115+
```
116+
117+
Once we have the container image created, we need to tag and push to the local registry, so the image can be used from our local cluster.
118+
Alternatively, you can push the images to a public registry and update the Kubernetes manifests accordingly.
119+
120+
```bash
121+
docker tag cloud-config-demo:0.15.0-SNAPSHOT localhost:5001/sb-cloud-config-demo
122+
docker push localhost:5001/sb-cloud-config-demo
123+
```
124+
80125
Now we are ready to install our application into the cluster.
81126

82127
## Installing and interacting with the application
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: multivalue-properties
5+
type: Opaque
6+
stringData:
7+
value1: |
8+
dapr.spring.demo-config-secret.multivalue.v1=spring
9+
dapr.spring.demo-config-secret.multivalue.v2=dapr
10+
value2: "dapr.spring.demo-config-secret.multivalue.v3=cloud"
11+
---
12+
apiVersion: v1
13+
kind: Secret
14+
metadata:
15+
name: dapr.spring.demo-config-secret.singlevalue
16+
type: Opaque
17+
stringData:
18+
value: "dapr.spring.demo-config-secret.singlevalue=testvalue"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: democonfig
5+
spec:
6+
type: secretstores.kubernetes
7+
version: v1

0 commit comments

Comments
 (0)