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
@@ -92,151 +92,6 @@ Backup in AKS has two types of hooks:
92
92
- Backup hooks
93
93
- Restore hooks
94
94
95
-
## Modify resource while restoring backups to AKS cluster
96
-
97
-
You can use the *Resource Modification* feature to modify backed-up Kubernetes resources during restore by specifying *JSON* patches as `configmap` deployed in the AKS cluster.
98
-
99
-
### Create and apply a resource modifier configmap during restore
100
-
101
-
To create and apply resource modification, follow these steps:
102
-
103
-
1. Create resource modifiers configmap.
104
-
105
-
You need to create one configmap in your preferred namespace from a *YAML* file that defined resource modifiers.
106
-
107
-
**Example for creating command**:
108
-
109
-
```json
110
-
version: v1
111
-
resourceModifierRules:
112
-
- conditions:
113
-
groupResource: persistentvolumeclaims
114
-
resourceNameRegex: "^mysql.*$"
115
-
namespaces:
116
-
- bar
117
-
- foo
118
-
labelSelector:
119
-
matchLabels:
120
-
foo: bar
121
-
patches:
122
-
- operation: replace
123
-
path: "/spec/storageClassName"
124
-
value: "premium"
125
-
- operation: remove
126
-
path: "/metadata/labels/test"
127
-
128
-
```
129
-
130
-
- The above *configmap* applies the *JSON* patch to all the Persistent Volume Copies in the *namespaces* bar and *foo* with name that starts with `mysql` and `match label foo: bar`. The JSON patch replaces the `storageClassName` with `premium` and removes the label `test` from the Persistent Volume Copies.
131
-
- Here, the *Namespace* is the original namespace of the backed-up resource, and not the new namespace where the resource is going to be restored.
132
-
- You can specify multiple JSON patches for a particular resource. The patches are applied as per the order specified in the *configmap*. A subsequent patch is applied in order. If multiple patches are specified for the same path, the last patch overrides the previous patches.
133
-
- You can specify multiple `resourceModifierRules` in the *configmap*. The rules are applied as per the order specified in the *configmap*.
134
-
135
-
136
-
2. Creating a resource modifier reference in the restore configuration
137
-
138
-
When you perform a restore operation, provide the *ConfigMap name* and the *Namespace* where it's deployed as part of restore configuration. These details need to be provided under **Resource Modifier Rules**.
139
-
140
-
:::image type="content" source="./media/azure-kubernetes-service-backup-overview/resource-modifier-rules.png" alt-text="Screenshot shows the location to provide resource details." lightbox="./media/azure-kubernetes-service-backup-overview/resource-modifier-rules.png":::
141
-
142
-
143
-
Operations supported by **Resource Modifier**
144
-
145
-
- **Add**
146
-
147
-
:::image type="content" source="./media/azure-kubernetes-service-backup-overview/add-resource-modifier.png" alt-text="Screenshot shows the addition of resource modifier. ":::
148
-
149
-
- **Remove**
150
-
151
-
:::image type="content" source="./media/azure-kubernetes-service-backup-overview/remove-resource-modifier.png" alt-text="Screenshot shows the option to remove resource.":::
152
-
153
-
- **Replace**
154
-
155
-
:::image type="content" source="./media/azure-kubernetes-service-backup-overview/replace-resource-modifier.png" alt-text="Screenshot shows the replacement option for resource modifier.":::
156
-
157
-
- **Move**
158
-
- **Copy**
159
-
160
-
:::image type="content" source="./media/azure-kubernetes-service-backup-overview/copy-resource-modifier.png" alt-text="Screenshot shows the option to copy resource modifier.":::
161
-
162
-
- **Test**
163
-
164
-
You can use the **Test** operation to check if a particular value is present in the resource. If the value is present, the patch is applied. If the value isn't present, the patch isn't applied.
165
-
166
-
:::image type="content" source="./media/azure-kubernetes-service-backup-overview/test-resource-modifier-value-present.png" alt-text="Screenshot shows the option to test if the resource value modifier is present.":::
167
-
168
-
### JSON patch
169
-
170
-
This *configmap* applies the JSON patch to all the deployments in the namespaces by default and `nginx` with the name that starts with `nginxdep`. The JSON patch updates the replica count to *12* for all such deployments.
171
-
172
-
173
-
```json
174
-
resourceModifierRules:
175
-
- conditions:
176
-
groupResource: deployments.apps
177
-
resourceNameRegex: "^nginxdep.*$"
178
-
namespaces:
179
-
- default
180
-
- nginx
181
-
patches:
182
-
- operation: replace
183
-
path: "/spec/replicas"
184
-
value: "12"
185
-
186
-
```
187
-
188
-
-**JSON Merge patch**: This config map will apply the JSON Merge Patch to all the deployments in the namespaces default and nginx with the name starting with nginxdep. The JSON Merge Patch will add/update the label "app" with the value "nginx1".
189
-
190
-
```json
191
-
192
-
193
-
version: v1
194
-
resourceModifierRules:
195
-
- conditions:
196
-
groupResource: deployments.apps
197
-
resourceNameRegex: "^nginxdep.*$"
198
-
namespaces:
199
-
- default
200
-
- nginx
201
-
mergePatches:
202
-
- patchData: |
203
-
{
204
-
"metadata" : {
205
-
"labels" : {
206
-
"app" : "nginx1"
207
-
}
208
-
}
209
-
}
210
-
211
-
212
-
```
213
-
214
-
-**Strategic Merge patch**: This config map will apply the Strategic Merge Patch to all the pods in the namespace default with the name starting with nginx. The Strategic Merge Patch will update the image of container nginx to mcr.microsoft.com/cbl-mariner/base/nginx:1.22
In a backup hook, you can configure the commands to run the hook before any custom action processing (pre-hooks), or after all custom actions are finished and any additional items specified by custom actions are backed up (post-hooks).
@@ -334,6 +189,236 @@ spec:
334
189
335
190
Learn [how to use hooks during AKS backup](azure-kubernetes-service-cluster-backup.md#use-hooks-during-aks-backup).
336
191
192
+
> [!NOTE]
193
+
> - During restore, backup extension waits for container to come up and then executes exec commands on them, defined in the restore hooks.
194
+
> - In case you are performing restore to the same namespace that was backed up, the restore hooks will not be executed as it only looks for new container that gets spawned. This is regardless of whether skip or patch policy is opted.
195
+
196
+
197
+
198
+
## Modify resource while restoring backups to AKS cluster
199
+
200
+
You can use the *Resource Modification* feature to modify backed-up Kubernetes resources during restore by specifying *JSON* patches as `configmap` deployed in the AKS cluster.
201
+
202
+
### Create and apply a resource modifier configmap during restore
203
+
204
+
To create and apply resource modification, follow these steps:
205
+
206
+
1. Create resource modifiers configmap.
207
+
208
+
You need to create one configmap in your preferred namespace from a *YAML* file that defined resource modifiers.
209
+
210
+
**Example for creating command**:
211
+
212
+
```json
213
+
version: v1
214
+
resourceModifierRules:
215
+
- conditions:
216
+
groupResource: persistentvolumeclaims
217
+
resourceNameRegex: "^mysql.*$"
218
+
namespaces:
219
+
- bar
220
+
- foo
221
+
labelSelector:
222
+
matchLabels:
223
+
foo: bar
224
+
patches:
225
+
- operation: replace
226
+
path: "/spec/storageClassName"
227
+
value: "premium"
228
+
- operation: remove
229
+
path: "/metadata/labels/test"
230
+
```
231
+
232
+
- The above *configmap* applies the *JSON* patch to all the Persistent Volume Copies in the *namespaces* bar and *foo* with name that starts with `mysql` and `match label foo: bar`. The JSON patch replaces the `storageClassName` with `premium` and removes the label `test` from the Persistent Volume Copies.
233
+
- Here, the *Namespace* is the original namespace of the backed-up resource, and not the new namespace where the resource is going to be restored.
234
+
- You can specify multiple JSON patches for a particular resource. The patches are applied as per the order specified in the *configmap*. A subsequent patch is applied in order. If multiple patches are specified for the same path, the last patch overrides the previous patches.
235
+
- You can specify multiple `resourceModifierRules` in the *configmap*. The rules are applied as per the order specified in the *configmap*.
236
+
237
+
238
+
2. Creating a resource modifier reference in the restore configuration
239
+
240
+
When you perform a restore operation, provide the *ConfigMap name* and the *Namespace* where it's deployed as part of restore configuration. These details need to be provided under **Resource Modifier Rules**.
241
+
242
+
:::image type="content" source="./media/azure-kubernetes-service-backup-overview/resource-modifier-rules.png" alt-text="Screenshot shows the location to provide resource details." lightbox="./media/azure-kubernetes-service-backup-overview/resource-modifier-rules.png":::
243
+
244
+
245
+
### Operations supported by **Resource Modifier**
246
+
247
+
- **Add**
248
+
249
+
You can use the **Add** operation to add a new block to the resource json. In the example below, the operation add a new container details to the spec with a deployment.
250
+
251
+
```json
252
+
version: v1
253
+
resourceModifierRules:
254
+
- conditions:
255
+
groupResource: deployments.apps
256
+
resourceNameRegex: "^test-.*$"
257
+
namespaces:
258
+
- bar
259
+
- foo
260
+
patches:
261
+
# Dealing with complex values by escaping the yaml
You can use the **Remove** operation to remove a key from the resource json. In the example below, the operation removes the label with test as key.
271
+
272
+
```json
273
+
version: v1
274
+
resourceModifierRules:
275
+
- conditions:
276
+
groupResource: persistentvolumeclaims
277
+
resourceNameRegex: "^mysql.*$"
278
+
namespaces:
279
+
- bar
280
+
- foo
281
+
labelSelector:
282
+
matchLabels:
283
+
foo: bar
284
+
patches:
285
+
- operation: remove
286
+
path: "/metadata/labels/test"
287
+
```
288
+
289
+
- **Replace**
290
+
291
+
You can use the **Replace** operation to replace a value for the path mentioned to an alternate one. In the example below, the operation replaces the storageClassName in the persistent volume claim with premium.
292
+
293
+
```json
294
+
version: v1
295
+
resourceModifierRules:
296
+
- conditions:
297
+
groupResource: persistentvolumeclaims
298
+
resourceNameRegex: "^mysql.*$"
299
+
namespaces:
300
+
- bar
301
+
- foo
302
+
labelSelector:
303
+
matchLabels:
304
+
foo: bar
305
+
patches:
306
+
- operation: replace
307
+
path: "/spec/storageClassName"
308
+
value: "premium"
309
+
```
310
+
311
+
- **Copy**
312
+
313
+
You can use the **Copy** operation to copy a value from one path from the resources defined to another path.
314
+
315
+
```json
316
+
version: v1
317
+
resourceModifierRules:
318
+
- conditions:
319
+
groupResource: deployments.apps
320
+
resourceNameRegex: "^test-.*$"
321
+
namespaces:
322
+
- bar
323
+
- foo
324
+
patches:
325
+
- operation: copy
326
+
from: "/spec/template/spec/containers/0"
327
+
path: "/spec/template/spec/containers/1"
328
+
```
329
+
330
+
- **Test**
331
+
332
+
You can use the **Test** operation to check if a particular value is present in the resource. If the value is present, the patch is applied. If the value isn't present, the patch isn't applied. In the example below, the operation checks whether the persistent volume claims have premium as StorageClassName and replaces if with standard, if true.
333
+
334
+
```json
335
+
version: v1
336
+
resourceModifierRules:
337
+
- conditions:
338
+
groupResource: persistentvolumeclaims
339
+
resourceNameRegex: ".*"
340
+
namespaces:
341
+
- bar
342
+
- foo
343
+
patches:
344
+
- operation: test
345
+
path: "/spec/storageClassName"
346
+
value: "premium"
347
+
- operation: replace
348
+
path: "/spec/storageClassName"
349
+
value: "standard"
350
+
```
351
+
352
+
- **JSON Patch**
353
+
354
+
This *configmap* applies the JSON patch to all the deployments in the namespaces by default and ``nginx` with the name that starts with `nginxdep`. The JSON patch updates the replica count to *12* for all such deployments.
355
+
356
+
357
+
```json
358
+
version: v1
359
+
resourceModifierRules:
360
+
- conditions:
361
+
groupResource: deployments.apps
362
+
resourceNameRegex: "^nginxdep.*$"
363
+
namespaces:
364
+
- default
365
+
- nginx
366
+
patches:
367
+
- operation: replace
368
+
path: "/spec/replicas"
369
+
value: "12"
370
+
```
371
+
372
+
- **JSON Merge Patch**
373
+
374
+
This config map will apply the JSON Merge Patch to all the deployments in the namespaces default and nginx with the name starting with nginxdep. The JSON Merge Patch will add/update the label "app" with the value "nginx1".
375
+
376
+
```json
377
+
version: v1
378
+
resourceModifierRules:
379
+
- conditions:
380
+
groupResource: deployments.apps
381
+
resourceNameRegex: "^nginxdep.*$"
382
+
namespaces:
383
+
- default
384
+
- nginx
385
+
mergePatches:
386
+
- patchData: |
387
+
{
388
+
"metadata" : {
389
+
"labels" : {
390
+
"app" : "nginx1"
391
+
}
392
+
}
393
+
}
394
+
```
395
+
396
+
- **Strategic Merge Patch**
397
+
398
+
This config map will apply the Strategic Merge Patch to all the pods in the namespace default with the name starting with nginx. The Strategic Merge Patch will update the image of container nginx to mcr.microsoft.com/cbl-mariner/base/nginx:1.22
0 commit comments