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
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/integrate-ci-cd-pipeline.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,4 +93,4 @@ To do a cloud build, with Azure DevOps for example, make sure the [Azure CLI](ht
93
93
In this tutorial, you exported Azure App Configuration data to be used in a deployment pipeline. To learn more about how to use App Configuration, continue to the Azure CLI samples.
title: "Integrate Azure App Configuration with Kubernetes Deployment using Helm"
3
3
description: Learn how to use dynamic configurations in Kubernetes deployment with Helm.
4
4
services: azure-app-configuration
5
-
author: shuawan
6
-
manager: zhenlwa
5
+
author: shenmuxiaosen
6
+
manager: zhenlan
7
7
8
8
ms.service: azure-app-configuration
9
9
ms.topic: tutorial
@@ -14,21 +14,49 @@ ms.author: shuawan
14
14
---
15
15
# Integrate with Kubernetes Deployment Using Helm
16
16
17
-
This article explains how to use data from Azure App Configuration in Kubernetes deployment with Helm.
17
+
In this tutorial, we will use a sample Helm chart and show how to generate configurations and secrets from the App Configuration that can be used in Kubernetes deployment.
- Background knowledge for installing applications with Helm in [Azure Kubernetes Service](https://docs.microsoft.com/azure/aks/kubernetes-helm)
22
+
- Install [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest) (version 2.4.0 or later)
23
+
- Install [Helm](https://helm.sh/docs/intro/install/) (version 2.14.0 or later)
24
+
- A Kubernetes cluster.
25
+
26
+
This tutorial assumes basic understanding of managing Kubernetes with Helm. Learn more about installing applications with Helm in [Azure Kubernetes Service](https://docs.microsoft.com/azure/aks/kubernetes-helm).
6. Select **Configuration Explorer** > **Create** to add the following key-value pairs:
33
+
34
+
| Key | Value |
35
+
|---|---|
36
+
| settings.color | White |
37
+
| settings.message | Data from Azure App Configuration |
38
+
39
+
Leave **Label** and **Content Type** empty for now.
40
+
41
+
## Add a Key Vault reference to App Configuration
42
+
1. Sign in to the [Azure portal](https://portal.azure.com) and add a secret to [Key Vault](https://docs.microsoft.com/en-us/azure/key-vault/secrets/quick-create-portal#add-a-secret-to-key-vault) with name **Password** and value **myPassword**.
43
+
2. Select the App Configuration store instance that you created in previous section.
44
+
45
+
1. Select **Configuration Explorer**.
46
+
47
+
1. Select **+ Create** > **Key vault reference**, and then specify the following values:
48
+
-**Key**: Select **secrets.password**.
49
+
-**Label**: Leave this value blank.
50
+
-**Subscription**, **Resource group**, and **Key vault**: Enter the values corresponding to those in the key vault you created in previous step.
51
+
-**Secret**: Select the secret named **Password** that you created in the previous section.
25
52
26
53
## Create Helm chart ##
27
-
```powershell
28
-
# Create sample Helm chart
54
+
First, we will create a sample Helm chart with the following command
55
+
```console
29
56
helm create mychart
30
57
```
31
-
Helm will create a new directory in your project called mychart with the structure shown below.
58
+
59
+
Helm will create a new directory called mychart with the structure shown below. You can follow the [charts guide](https://helm.sh/docs/chart_template_guide/getting_started/) to learn more.
32
60
```
33
61
mychart
34
62
|-- Chart.yaml
@@ -42,19 +70,17 @@ mychart
42
70
`-- values.yaml
43
71
```
44
72
45
-
Details to understand [mychart](https://helm.sh/docs/chart_template_guide/getting_started/)
46
-
47
-
Based on the sample **deployment.yaml** file, we modify the chart to add some environment variables to container under ```spec:template:spec:containers```. Although this setting won't be used by the application, it shows as an example for how to dynamically pass configurations into Helm deployment.
73
+
Next, we will update the *deployment.yaml* file and add the following snippet which adds two environment variables to the container under **spec:template:spec:containers**. It shows how to dynamically pass configurations into deployment.
48
74
49
75
```yaml
50
76
env:
51
77
- name: Color
52
-
value: {{ .Values.color }}
78
+
value: {{ .Values.settings.color }}
53
79
- name: Message
54
-
value: {{ .Values.message }}
80
+
value: {{ .Values.settings.message }}
55
81
```
56
82
57
-
The modified deployment.yamlshould look like below.
83
+
The complete *deployment.yaml* file after the update should look like below.
58
84
59
85
```yaml
60
86
apiVersion: apps/v1beta2
@@ -84,9 +110,9 @@ spec:
84
110
imagePullPolicy: {{ .Values.image.pullPolicy }}
85
111
env:
86
112
- name: Color
87
-
value: {{ .Values.color }}
113
+
value: {{ .Values.settings.color }}
88
114
- name: Message
89
-
value: {{ .Values.message }}
115
+
value: {{ .Values.settings.message }}
90
116
ports:
91
117
- name: http
92
118
containerPort: 80
@@ -115,146 +141,65 @@ spec:
115
141
{{- end }}
116
142
```
117
143
118
-
In addition, add **secrets.yaml** under templates for Kubernetes Secrets, which is used to store and manage sensitive information, such as passwords. Same with environment variables, Secrets can also be referenced by application.
144
+
Then we add a *secrets.yaml* file under the templates folder with following content. It will be used to store Kubernetes Secrets, such as passwords. The secrets will be accessible from inside the container. Learn more about how to use [Kubernetes Secrets](https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets).
145
+
119
146
```yaml
120
147
apiVersion: v1
121
148
kind: Secret
122
149
metadata:
123
150
name: mysecret
124
151
type: Opaque
125
152
data:
126
-
password: {{ .Values.password }}
153
+
password: {{ .Values.secrets.password }}
127
154
```
128
155
129
-
In **values.yaml**, there are some default settings used for chart. Let's add some place holder for configurations we added above. Settings in **values.yaml** can be later on combined and overwritten by configurations pulled from App Configuration.
156
+
Finally, we can update the *values.yaml* file with the following content to optionally provide default values of the configuration settings and secrets that we referenced in the *deployment.yaml* and *secrets.yaml* files earlier. Their actual values will be overwritten by configuration pulled from the App Configuration.
130
157
131
158
```yaml
132
-
# Default values for mychart.
133
-
# This is a YAML-formatted file.
134
-
# Declare variables to be passed into your templates.
135
-
136
-
replicaCount: 1
137
-
138
-
image:
139
-
repository: nginx
140
-
tag: stable
141
-
pullPolicy: IfNotPresent
142
-
143
-
nameOverride: ""
144
-
fullnameOverride: ""
145
-
146
-
service:
147
-
type: ClusterIP
148
-
port: 80
149
-
150
-
ingress:
151
-
enabled: false
152
-
annotations: {}
153
-
# kubernetes.io/ingress.class: nginx
154
-
# kubernetes.io/tls-acme: "true"
155
-
path: /
156
-
hosts:
157
-
- chart-example.local
158
-
tls: []
159
-
# - secretName: chart-example-tls
160
-
# hosts:
161
-
# - chart-example.local
162
-
163
-
resources: {}
164
-
# We usually recommend not to specify default resources and to leave this as a conscious
165
-
# choice for the user. This also increases chances charts run on environments with little
166
-
# resources, such as Minikube. If you do want to specify resources, uncomment the following
167
-
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
168
-
# limits:
169
-
# cpu: 100m
170
-
# memory: 128Mi
171
-
# requests:
172
-
# cpu: 100m
173
-
# memory: 128Mi
174
-
175
-
nodeSelector: {}
176
-
177
-
tolerations: []
178
-
179
-
affinity: {}
180
-
181
159
# settings will be overwritten by App Configuration
6. Select **Configuration Explorer** > **Create** to add the following key-value pairs:
193
-
194
-
| Key | Value |
195
-
|---|---|
196
-
| color | White |
197
-
| message | Data from Azure App Configuration |
198
-
199
-
Leave **Label** and **Content Type** empty for now.
200
-
201
-
## Add a secret to Key Vault
202
-
203
-
To add a secret to the vault, you need to take just a few additional steps. In this case, add a message that you can use to test Key Vault retrieval. The message is called **Message**, and you store the value "Hello from Key Vault" in it.
204
-
205
-
1. From the Key Vault properties pages, select **Secrets**.
206
-
1. Select **Generate/Import**.
207
-
1. In the **Create a secret** pane, enter the following values:
208
-
- **Upload options**: Enter **Manual**.
209
-
- **Name**: Enter **Password**.
210
-
- **Value**: Enter **myPassword**.
211
-
1. Leave the other **Create a secret** properties with their default values.
212
-
1. Select **Create**.
213
-
214
-
## Add a Key Vault reference to App Configuration
215
-
216
-
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and then select the App Configuration store instance that you created in the quickstart.
217
-
218
-
1. Select **Configuration Explorer**.
219
-
220
-
1. Select **+ Create** > **Key vault reference**, and then specify the following values:
221
-
- **Key**: Select **KVRef_password**.
222
-
- **Label**: Leave this value blank.
223
-
- **Subscription**, **Resource group**, and **Key vault**: Enter the values corresponding to those in the key vault you created in the previous section.
224
-
- **Secret**: Select the secret named **Password** that you created in the previous section.
165
+
## Pass configuration data from App Configuration during Helm install ##
166
+
First, we download the configuration from App Configuration to a *myConfig.yaml* file. We use a key filter to only download those keys that start with **settings.**. If in your case the key filter is not sufficient to exclude keys of Key Vault references, you may use the argument **--skip-keyvault** to exclude them. Learn more about the [export command](https://docs.microsoft.com/en-us/cli/azure/appconfig/kv?view=azure-cli-latest#az-appconfig-kv-export).
In App Configuration, there are normal configurations along with key vault references and if no need to resolve those references in deployment time, then pull all data in one shot.
228
-
```PowerShell
229
-
$ConfigFilePath="config.yaml"
171
+
Then we download secrets to a *mySecrets.yaml* file. Note the parameter **--resolve-keyvault** is used so the Key Vault references will be resolved and the actual values in the Key Vault will be retrieved. Make sure the credential that is used to run this command has access permission to the corresponding Key Vault. As this file contains sensitive information, keep the file with care and clean up when it's not needed anymore.
If there is a need to resolve the content of key vault references like secrets, then separate them into two files.
236
-
```PowerShell
237
-
$ConfigFilePath=config.yaml
238
-
$SecretPath=secrets.yaml
181
+
If there is a concern for putting sensitive data in persistent storage, export content of key vault references to memory. Besides files Helm also allows passing literal key values with argument **--set**. Learn more about [Helm usage](https://helm.sh/docs/intro/using_helm/).
239
182
240
-
# Export configurations excluding key vault reference to local files
There are [two ways](https://helm.sh/docs/intro/using_helm/) to pass configuration data during helm install. Helm allow passing files or literal key values to overwrite settings specified in values.yaml.
We can verify by accessing [Kubernetes Dashboard](https://docs.microsoft.com/azure/aks/kubernetes-dashboard)
200
+
We can verify configurations and secrets are successfully pulled by accessing [Kubernetes Dashboard](https://docs.microsoft.com/azure/aks/kubernetes-dashboard). Two settings, **color** and **message**, stores in App Configuration were populated into container's environment variables.
@@ -266,4 +211,4 @@ We can verify by accessing [Kubernetes Dashboard](https://docs.microsoft.com/azu
266
211
In this tutorial, you exported Azure App Configuration data to be used in a Kubernetes deployment with Helm. To learn more about how to use App Configuration, continue to the Azure CLI samples.
0 commit comments