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
# Tutorial: Connect to a managed Config Server for Spring in Azure Container Apps (preview)
14
14
15
15
Config Server for Spring provides a centralized location to make configuration data available to multiple applications. In this article, you learn to connect an app hosted in Azure Container Apps to a Java Config Server for Spring instance.
16
16
17
-
The Config Server for Spring component uses a GitHub repository as the source for configuration settings. Configuration values are made available to your container app via a binding between the component and your container app. As values change in the configuration server, they automatically flow to your application, all without requiring you to recompile or redeploy your application.
17
+
The Config Server for Spring Java component uses a GitHub repository as the source for configuration settings. Configuration values are made available to your container app via a binding between the component and your container app. As values change in the configuration server, they automatically flow to your application, all without requiring you to recompile or redeploy your application.
18
18
19
19
In this tutorial, you learn to:
20
20
@@ -45,22 +45,24 @@ When running in Config Server for Spring in Azure Container Apps, be aware of th
45
45
|**Scope**| The Config Server for Spring runs in the same environment as the connected container app. |
46
46
|**Scaling**| To maintain a single source of truth, the Config Server for Spring doesn't scale. The scaling properties `minReplicas` and `maxReplicas` are both set to `1`. |
47
47
|**Resources**| The container resource allocation for Config Server for Spring is fixed, the number of the CPU cores is 0.5, and the memory size is 1Gi. |
48
-
|**Pricing**| The Config Server for Spring billing falls under consumption-based pricing. Resources consumed by managed Java components are billed at the active/idle rates. You may delete components that are no longer in use to stop billing. |
48
+
|**Pricing**| The Config Server for Spring billing falls under consumption-based pricing. Resources consumed by managed Java components are billed at the active/idle rates. You can delete components that are no longer in use to stop billing. |
49
49
|**Binding**| The container app connects to a Config Server for Spring via a binding. The binding injects configurations into container app environment variables. Once a binding is established, the container app can read configuration values from environment variables. |
50
50
51
51
## Setup
52
52
53
53
Before you begin to work with the Config Server for Spring, you first need to create the required resources.
54
54
55
+
### [Azure CLI](#tab/azure-cli)
56
+
55
57
Execute the following commands to create your resource group and Container Apps environment.
56
58
57
59
1. Create variables to support your application configuration. These values are provided for you for the purposes of this lesson.
@@ -75,7 +77,7 @@ Execute the following commands to create your resource group and Container Apps
75
77
|`IMAGE`| The container image used in your container app. |
76
78
|`URI`| You can replace the URI with your git repo url, if it's private, add the related authentication configurations such as `spring.cloud.config.server.git.username` and `spring.cloud.config.server.git.password`. |
77
79
78
-
1. Log in to Azure with the Azure CLI.
80
+
1. Sign in to Azure with the Azure CLI.
79
81
80
82
```azurecli
81
83
az login
@@ -96,11 +98,66 @@ Execute the following commands to create your resource group and Container Apps
96
98
--location $LOCATION
97
99
```
98
100
99
-
This environment is used to host both the Config Server for Spring component and your container app.
101
+
### [Azure portal](#tab/azure-portal)
102
+
103
+
Use the following steps to create each of the resources necessary to create a container app.
104
+
105
+
1. Search for **Container Apps** in the Azure portal and select **Create**.
106
+
107
+
1. Enter the following values to *Basics* tab.
108
+
109
+
| Property | Value |
110
+
|---|---|
111
+
| **Subscription** | Select your Azure subscription. |
112
+
| **Resource group** | Select **Create new** link to create a new resource group named **my-resource-group**. |
113
+
| **Container app name** | Enter **my-config-client**. |
| **Container Apps environment** | Select the **Create new** link to create a new environment. |
117
+
118
+
1. In the *Create Container Apps environment* window, enter the following values.
119
+
120
+
| Property | Value |
121
+
|---|---|
122
+
| **Environment name** | Enter **my-environment**. |
123
+
| **Zone redundancy** | Select **Disabled**. |
124
+
125
+
Select the **Create** button, and then select the **Container** tab.
126
+
127
+
1. In *Container* tab, enter the following values.
128
+
129
+
| Property | Value |
130
+
|---|---|
131
+
| **Name** | Enter **my-config-client**. |
132
+
| **Image source** | Select **Docker Hub or other registries**. |
133
+
| **Image type** | Select **Public**. |
134
+
| **Registry login server** | Enter **mcr.microsoft.com**. |
135
+
| **Image and tag** | Enter **javacomponents/samples/sample-service-config-client:latest**. |
136
+
137
+
Select the **Ingress** tab.
138
+
139
+
1. In *Ingress* tab, enter the following and leave the rest of the form with their default values.
140
+
141
+
| Property | Value |
142
+
|---|---|
143
+
| **Ingress** | Select **Enabled**. |
144
+
| **Ingress traffic** | Select **Accept traffic from anywhere**. |
145
+
| **Ingress type** | Select **HTTP**. |
146
+
| **Target port** | Enter **8080**. |
147
+
148
+
Select **Review + create**.
149
+
150
+
1. Once the validation checks pass, select **Create** to create your container app.
151
+
152
+
---
153
+
154
+
This environment is used to host both the Config Server for Spring java component and your container app.
100
155
101
-
## Use the Config Server for Spring Java component
156
+
## Create the Config Server for Spring Java component
102
157
103
-
Now that you have a Container Apps environment, you can create your container app and bind it to a Config Server for Spring component. When you bind your container app, configuration values automatically synchronize from the Config Server component to your application.
158
+
Now that you have a Container Apps environment, you can create your container app and bind it to a Config Server for Spring java component. When you bind your container app, configuration values automatically synchronize from the Config Server component to your application.
159
+
160
+
### [Azure CLI](#tab/azure-cli)
104
161
105
162
1. Create the Config Server for Spring Java component.
106
163
@@ -124,6 +181,42 @@ Now that you have a Container Apps environment, you can create your container ap
124
181
125
182
Here, you're telling the component where to find the repository that holds your configuration information via the `uri` property. The `refresh-rate` property tells Container Apps how often to check forchangesin your git repository.
126
183
184
+
### [Azure portal](#tab/azure-portal)
185
+
186
+
Now that you have an existing environment and config server client container app, you can create a Java component instance of Config Server for Spring.
187
+
188
+
1. Go to your container app's environment in the portal.
189
+
190
+
1. From the left menu, under *Services* category, select **Services**.
191
+
192
+
1. Select **+ Configure** drop down, and select **Java component**.
193
+
194
+
1. In the *Configure Java component* panel, enter the following values.
195
+
196
+
| Property | Value |
197
+
|---|---|
198
+
| **Java component type** | Select **Config Server for Spring**. |
199
+
| **Java component name** | Enter **configserver**. |
200
+
201
+
1. In the *Git repositories* section, select the **+ Add** button and enter the following values.
202
+
203
+
| Property | Value |
204
+
|---|---|
205
+
| **Type** | Select **HTTP**. |
206
+
| **URI** | Enter **https://github.com/Azure-Samples/azure-spring-cloud-config-java-aca.git**. |
207
+
208
+
Leave the rest of the fields with the default values and select **Add**.
209
+
210
+
1. Select **Next**.
211
+
212
+
1. On the *Review* tab, select **Configure**.
213
+
214
+
---
215
+
216
+
## Bind your container app to the Config Server for Spring Java component
217
+
218
+
### [Azure CLI](#tab/azure-cli)
219
+
127
220
1. Create the container app that consumes configuration data.
128
221
129
222
```azurecli
@@ -143,7 +236,7 @@ Now that you have a Container Apps environment, you can create your container ap
143
236
144
237
If you visit your app in a browser, the `connectTimeout` value returned is the default value of `0`.
145
238
146
-
1. Bind to the Config Server for Spring.
239
+
2. Bind to the Config Server for Spring.
147
240
148
241
Now that the container app and Config Server are created, you bind them together with the `update` command to your container app.
149
242
@@ -156,36 +249,73 @@ Now that you have a Container Apps environment, you can create your container ap
156
249
157
250
The `--bind $JAVA_COMPONENT_NAME` parameter creates the link between your container app and the configuration component.
158
251
159
-
Once the container app and the Config Server component are bound together, configuration changes are automatically synchronized to the container app.
252
+
### [Azure portal](#tab/azure-portal)
160
253
161
-
When you visit the app's URL again, the value of `connectTimeout` is now `10000`. This value comes from the git repo set in the `$URI` variable originally set as the source of the configuration component. Specifically, this value is drawn from the `connectionTimeout` property in the repo's *application.yml* file.
254
+
1. Go to your container app environment in the portal.
162
255
163
-
The bind request injects configuration setting into the application as environment variables. These values are now available to the application code to use when fetching configuration settings from the config server.
256
+
1. From the left menu, under *Services* category, select **Services**.
164
257
165
-
In this case, the following environment variables are available to the application:
1. Under *bindings, select the *App name* drop-down and select **my-config-client**.
172
261
173
-
If you want to customize your own `SPRING_CONFIG_IMPORT`, you can refer to the environment variable `SPRING_CLOUD_CONFIG_COMPONENT_URI`, for example, you can override by command line arguments, like `Java -Dspring.config.import=optional:configserver:${SPRING_CLOUD_CONFIG_COMPONENT_URI}?fail-fast=true`.
262
+
1. Select the **Review** tab.
174
263
175
-
You can also remove a binding from your application.
264
+
1. Select the **Configure** button.
176
265
177
-
1. Unbind the Config Server for Spring Java component.
266
+
1. Return to your container app in the portal and copy the URL of your app to a text editor so you can use it in a coming step.
178
267
179
-
To remove a binding from a container app, use the `--unbind` option.
268
+
---
180
269
181
-
``` azurecli
182
-
az containerapp update \
183
-
--name $APP_NAME \
184
-
--unbind $JAVA_COMPONENT_NAME \
185
-
--resource-group $RESOURCE_GROUP
186
-
```
270
+
Once the container app and the Config Server component are bound together, configuration changes are automatically synchronized to the container app.
271
+
272
+
When you visit the app's URL again, the value of `connectTimeout` is now `10000`. This value comes from the git repo setin the `$URI` variable originally set as the source of the configuration component. Specifically, this value is drawn from the `connectionTimeout` property in the repo's *application.yml* file.
273
+
274
+
The bind request injects configuration setting into the application as environment variables. These values are now available to the application code to use when fetching configuration settings from the config server.
275
+
276
+
In this case, the following environment variables are available to the application:
If you want to customize your own `SPRING_CONFIG_IMPORT`, you can refer to the environment variable `SPRING_CLOUD_CONFIG_COMPONENT_URI`, for example, you can override by command line arguments, like `Java -Dspring.config.import=optional:configserver:${SPRING_CLOUD_CONFIG_COMPONENT_URI}?fail-fast=true`.
285
+
286
+
You can also remove a binding from your application.
287
+
288
+
## Unbind your container app from the Config Server for Spring Java component
289
+
290
+
### [Azure CLI](#tab/azure-cli)
291
+
To remove a binding from a container app, use the `--unbind` option.
292
+
293
+
``` azurecli
294
+
az containerapp update \
295
+
--name $APP_NAME \
296
+
--unbind $JAVA_COMPONENT_NAME \
297
+
--resource-group $RESOURCE_GROUP
298
+
```
299
+
300
+
### [Azure portal](#tab/azure-portal)
301
+
302
+
1. Go to your container app environment in the portal.
303
+
304
+
1. From the left menu, under *Services* category, select **Services**.
187
305
188
-
When you visit the app's URL again, the value of `connectTimeout` changes to back to `0`.
306
+
1. From the list, select **configserver**.
307
+
308
+
1. Under *Bindings*, find the line for *my-config-client* select and select **Delete**.
309
+
310
+
1. Select **Next**.
311
+
312
+
1. Select the **Review** tab.
313
+
314
+
1. Select the **Configure** button.
315
+
316
+
---
317
+
318
+
When you visit the app's URL again, the value of `connectTimeout` changes to back to `0`.
189
319
190
320
## Clean up resources
191
321
@@ -200,4 +330,3 @@ az group delete \
200
330
201
331
> [!div class="nextstepaction"]
202
332
> [Customize Config Server for Spring settings](java-config-server-usage.md)
0 commit comments