Skip to content

Commit 0b493e3

Browse files
authored
Merge pull request #53000 from MicrosoftDocs/NEW-configure-apps-azure-kubernetes-service
New configure apps azure kubernetes service module
2 parents bf14005 + 7569724 commit 0b493e3

15 files changed

Lines changed: 539 additions & 0 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.configure-apps-azure-kubernetes-service.introduction
3+
title: Introduction
4+
metadata:
5+
title: Introduction
6+
description: Introduction
7+
ms.date: 12/14/2025
8+
author: jeffkoms
9+
ms.author: jeffko
10+
ms.topic: unit
11+
azureSandbox: false
12+
durationInMinutes: 3
13+
content: |
14+
[!include[](includes/1-introduction.md)]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.configure-apps-azure-kubernetes-service.define-configmaps
3+
title: Define ConfigMaps for application settings
4+
metadata:
5+
title: Define ConfigMaps for Application Settings
6+
description: Define ConfigMaps for application settings
7+
ms.date: 12/14/2025
8+
author: jeffkoms
9+
ms.author: jeffko
10+
ms.topic: unit
11+
azureSandbox: false
12+
durationInMinutes: 10
13+
content: |
14+
[!include[](includes/2-define-configmaps.md)]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.configure-apps-azure-kubernetes-service.implement-secrets
3+
title: Implement secrets for sensitive data
4+
metadata:
5+
title: Implement Secrets for Sensitive Data
6+
description: Implement secrets for sensitive data
7+
ms.date: 12/14/2025
8+
author: jeffkoms
9+
ms.author: jeffko
10+
ms.topic: unit
11+
azureSandbox: false
12+
durationInMinutes: 10
13+
content: |
14+
[!include[](includes/3-implement-secrets.md)]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.configure-apps-azure-kubernetes-service.persistent-storage
3+
title: Attach persistent storage to an app
4+
metadata:
5+
title: Attach Persistent Storage to an App
6+
description: Attach persistent storage to an app
7+
ms.date: 12/14/2025
8+
author: jeffkoms
9+
ms.author: jeffko
10+
ms.topic: unit
11+
azureSandbox: false
12+
durationInMinutes: 12
13+
content: |
14+
[!include[](includes/4-persistent-storage.md)]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.configure-apps-azure-kubernetes-service.exercise-configure-apps
3+
title: Exercise - Configure apps on Azure Kubernetes Service
4+
metadata:
5+
title: Exercise - Configure Apps on Azure Kubernetes Service
6+
description: Exercise - Configure apps on Azure Kubernetes Service
7+
ms.date: 12/14/2025
8+
author: jeffkoms
9+
ms.author: jeffko
10+
ms.topic: unit
11+
azureSandbox: false
12+
durationInMinutes: 30
13+
content: |
14+
[!include[](includes/5-exercise-configure-apps.md)]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.configure-apps-azure-kubernetes-service.module-assessment
3+
title: Module assessment
4+
metadata:
5+
title: Module Assessment
6+
description: Module assessment
7+
ms.date: 12/16/2025
8+
author: jeffkoms
9+
ms.author: jeffko
10+
ms.topic: unit
11+
azureSandbox: false
12+
durationInMinutes: 5
13+
content: |
14+
quiz:
15+
questions:
16+
- content: "You need to store a database connection string for your application running on AKS. The connection string contains a password and shouldn't be visible in your source code repository. Which Kubernetes resource should you use?"
17+
choices:
18+
- content: "ConfigMap, because it stores configuration data"
19+
isCorrect: false
20+
explanation: "ConfigMaps are designed for nonsensitive configuration. While they keep data out of container images, they shouldn't be used for credentials or passwords."
21+
- content: "Secret, because it stores sensitive values and keeps credentials out of source control"
22+
isCorrect: true
23+
explanation: "Secrets are the correct choice for storing sensitive values like connection strings with passwords. They keep credentials out of source control and can be protected with RBAC policies."
24+
- content: "PersistentVolumeClaim, because it provides storage for application data"
25+
isCorrect: false
26+
explanation: "PersistentVolumeClaims provide durable filesystem storage, not a mechanism for storing and injecting credentials into Pods."
27+
- content: "Your AI application reads feature flags and service endpoints from environment variables. You want to update these settings without rebuilding your container image. How should you inject these nonsensitive values into your Pods?"
28+
choices:
29+
- content: "Create a ConfigMap with the settings and reference the keys using configMapKeyRef in the Deployment"
30+
isCorrect: true
31+
explanation: "ConfigMaps are designed for nonsensitive configuration. Using configMapKeyRef lets you inject values as environment variables and update them without rebuilding images."
32+
- content: "Store the values in a Secret and mount it as a volume"
33+
isCorrect: false
34+
explanation: "While this would work technically, Secrets are intended for sensitive data. ConfigMaps are the appropriate resource for nonsensitive configuration like feature flags."
35+
- content: "Hardcode the values in the Deployment manifest and update the manifest when settings change"
36+
isCorrect: false
37+
explanation: "Hardcoding values in the Deployment manifest couples configuration to the deployment definition. ConfigMaps let you change settings independently of the Deployment."
38+
- content: "You create a PersistentVolumeClaim in your AKS cluster. What happens when you apply the PVC manifest?"
39+
choices:
40+
- content: "You must manually create an Azure Disk in the Azure portal before the PVC can bind"
41+
isCorrect: false
42+
explanation: "AKS StorageClasses handle dynamic provisioning automatically. You don't need to manually create Azure storage resources."
43+
- content: "AKS uses the specified StorageClass to automatically provision Azure storage that backs the PVC"
44+
isCorrect: true
45+
explanation: "AKS includes preconfigured StorageClasses that dynamically provision Azure Disk or Azure Files resources when you create a PVC. No manual storage creation is required."
46+
- content: "The PVC remains unbound until you create a matching PersistentVolume manifest"
47+
isCorrect: false
48+
explanation: "With dynamic provisioning through StorageClasses, you don't need to manually create PersistentVolume manifests. AKS creates them automatically."
49+
- content: "Your application needs to access API keys stored in a Kubernetes Secret. You want to make the keys available as environment variables in the container. Which field should you use in the Deployment manifest to reference the Secret?"
50+
choices:
51+
- content: "valueFrom with secretKeyRef"
52+
isCorrect: true
53+
explanation: "The valueFrom field with secretKeyRef is the correct way to inject Secret values as environment variables. This resolves the Secret key at Pod start time."
54+
- content: "Volumes with secret type"
55+
isCorrect: false
56+
explanation: "This approach mounts the Secret as files in the container filesystem, not as environment variables. Use this when your application reads secrets from files."
57+
- content: "configMapKeyRef pointing to the Secret name"
58+
isCorrect: false
59+
explanation: "configMapKeyRef is used to reference ConfigMaps, not Secrets. You must use secretKeyRef to reference Secret keys."
60+
- content: "You need to decide between mounting a ConfigMap as environment variables or as files. Your application reads a JSON configuration file at startup. Which approach should you choose?"
61+
choices:
62+
- content: "Mount the ConfigMap as environment variables because all applications can read environment variables"
63+
isCorrect: false
64+
explanation: "While applications can read environment variables, this approach doesn't provide a JSON file on disk. The application expects a file, not environment variables."
65+
- content: "Mount the ConfigMap as files using a volume so the JSON file appears on disk where the application expects it"
66+
isCorrect: true
67+
explanation: "When an application expects configuration files on disk, mount the ConfigMap as a volume. Each key becomes a file in the mount directory."
68+
- content: "Store the JSON content in a Secret and use secretKeyRef to inject it as an environment variable"
69+
isCorrect: false
70+
explanation: "This approach doesn't match the requirement. The application needs a file on disk, not an environment variable. Also, Secrets are for sensitive data, and this appears to be nonsensitive configuration."
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.configure-apps-azure-kubernetes-service.summary
3+
title: Summary
4+
metadata:
5+
title: Summary
6+
description: Summary
7+
ms.date: 12/14/2025
8+
author: jeffkoms
9+
ms.author: jeffko
10+
ms.topic: unit
11+
azureSandbox: false
12+
durationInMinutes: 2
13+
content: |
14+
[!include[](includes/7-summary.md)]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
AI applications on Azure need safe configuration, strong secret handling, and durable storage. These capabilities help you meet latency, reliability, and governance goals. Configuring applications on Azure Kubernetes Service (AKS) lets you externalize settings. You can also secure sensitive values and attach persistent storage for stateful AI workloads.
2+
3+
Imagine you deploy an AI inference API that serves models at scale. The service needs environment-specific settings for endpoints. It also needs API keys for upstream services and a durable location for temporary artifacts and user uploads. You aim for predictable rollouts and secure operations. Without Kubernetes features, teams hardcode values into containers. They risk leaking credentials or losing state when Pods restart. ConfigMaps let you separate configuration from code. Secrets protect sensitive values like API keys and connection strings. PersistentVolumeClaims (PVCs) give you durable storage that survives Pod restarts. Together, these features help you run stateful AI workloads securely on AKS.
4+
5+
## After completing this module, you'll be able to:
6+
7+
- Explain why externalized configuration and secret handling matter for AI solutions on Azure
8+
- Implement ConfigMaps for nonsensitive settings and inject them into Pods
9+
- Implement Secrets for sensitive values and consume them securely in Pods
10+
- Attach persistent storage using PersistentVolume and PersistentVolumeClaim for stateful AI workloads
11+
- Deploy and verify configuration and storage on AKS using `kubectl`
12+
13+
> [!NOTE]
14+
> All examples in this module follow current Kubernetes resource APIs. Validate fields against official Kubernetes and AKS documentation when adapting to your environment.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
AI inference services on Azure often require different settings across environments. You want to change these settings without rebuilding containers. ConfigMaps store non-sensitive configuration, such as feature flags and service endpoints. They keep configuration out of images and source code. This approach lets you make fast, controlled changes to settings. You can inject ConfigMap values into Pods as environment variables or as mounted files. Choose environment variables when your application reads from the process environment. Choose mounted files when your application expects configuration files on disk.
2+
3+
> [!NOTE]
4+
> All code examples in this module show configuration patterns for Kubernetes resources. The specific values and resource names are examples. Adapt them to match your application requirements and naming conventions.
5+
6+
## Define a ConfigMap
7+
8+
A ConfigMap is a Kubernetes resource that stores configuration data as key-value pairs. You declare it using YAML and apply it to your cluster. The `data` field holds your configuration keys and their string values. ConfigMap data is limited to 1 MiB total size per ConfigMap. This limit ensures fast synchronization to nodes and efficient etcd storage. For larger configuration files or binary data, use persistent volumes or external configuration services. Use the `binaryData` field for base64-encoded binary values when necessary. ConfigMap keys must consist of alphanumeric characters, dashes, underscores, or dots.
9+
10+
```yaml
11+
apiVersion: v1
12+
kind: ConfigMap
13+
metadata:
14+
name: app-settings
15+
data:
16+
FEATURE_X_ENABLED: "true"
17+
SERVICE_ENDPOINT: "https://api.example.com"
18+
# File-like configuration can use multi-line values
19+
app.config: |
20+
log_level=info
21+
timeout_seconds=30
22+
```
23+
24+
## Consume ConfigMap values in a Deployment
25+
26+
You inject configuration into Pods through environment variables. This approach uses the `valueFrom` field with `configMapKeyRef` to reference specific keys from your ConfigMap. When the Pod starts, Kubernetes reads the ConfigMap and sets the environment variables in the container. You can also use `envFrom` with `configMapRef` to load all keys from a ConfigMap as environment variables in one declaration. This bulk loading approach works well when you have many configuration values and want to avoid repetitive YAML. After you deploy, validate that Pods receive expected values. Use `kubectl describe pod` and check your application logs to confirm the settings are correct.
27+
28+
```yaml
29+
apiVersion: apps/v1
30+
kind: Deployment
31+
metadata:
32+
name: web-api
33+
spec:
34+
replicas: 2
35+
selector:
36+
matchLabels:
37+
app: web-api
38+
template:
39+
metadata:
40+
labels:
41+
app: web-api
42+
spec:
43+
containers:
44+
- name: api
45+
image: myregistry.azurecr.io/web-api:v1
46+
env:
47+
- name: FEATURE_X_ENABLED
48+
valueFrom:
49+
configMapKeyRef:
50+
name: app-settings
51+
key: FEATURE_X_ENABLED
52+
- name: SERVICE_ENDPOINT
53+
valueFrom:
54+
configMapKeyRef:
55+
name: app-settings
56+
key: SERVICE_ENDPOINT
57+
# Alternative: load all keys as environment variables
58+
# envFrom:
59+
# - configMapRef:
60+
# name: app-settings
61+
```
62+
63+
## Mount ConfigMap as files
64+
65+
Some applications expect configuration files on disk rather than environment variables. You can mount a ConfigMap as files in the container filesystem. This approach uses a volume backed by the ConfigMap. You then add a `volumeMount` entry in the container spec to mount that volume at a specific path. Each key in the ConfigMap becomes a file in the mount directory. When you mount ConfigMaps as volumes, Kubernetes automatically updates the files when you modify the ConfigMap. The kubelet checks for updates on each sync period. However, containers using ConfigMaps as environment variables do not receive automatic updates and require Pod restarts. The automatic update behavior does not apply when you use `subPath` mounts. The following snippet shows the volume and mount configuration. Include these sections inside your Pod or Deployment spec.
66+
67+
```yaml
68+
# Code fragment - focus on volume mount
69+
volumes:
70+
- name: config-volume
71+
configMap:
72+
name: app-settings
73+
# Optional: select specific keys to mount as files
74+
# items:
75+
# - key: app.config
76+
# path: application.conf
77+
containers:
78+
- name: api
79+
volumeMounts:
80+
- name: config-volume
81+
mountPath: /app/config
82+
readOnly: true
83+
```
84+
85+
## Use immutable ConfigMaps
86+
87+
You can mark a ConfigMap as immutable to protect against accidental changes that could disrupt running applications. Immutable ConfigMaps offer performance benefits in large clusters by allowing Kubernetes to close watches on these resources. This reduces load on the API server when you have many ConfigMaps. Once you set a ConfigMap to immutable, you cannot change its data or revert the immutable setting. You must delete and recreate the ConfigMap to make changes. Existing Pods maintain mount points to the deleted ConfigMap until they restart. Use immutable ConfigMaps for configuration that should not change during application runtime. This pattern works well for configuration tied to specific application versions where changes require redeployment.
88+
89+
```yaml
90+
apiVersion: v1
91+
kind: ConfigMap
92+
metadata:
93+
name: app-settings-v2
94+
data:
95+
FEATURE_X_ENABLED: "true"
96+
SERVICE_ENDPOINT: "https://api.example.com"
97+
immutable: true
98+
```
99+
100+
## Integrate with Azure App Configuration
101+
102+
You can use [Azure App Configuration](/azure/azure-app-configuration/overview) for centralized configuration management across multiple applications and environments. The [Azure App Configuration Kubernetes Provider](/azure/azure-app-configuration/quickstart-azure-kubernetes-service) runs in your cluster and generates ConfigMaps from data stored in App Configuration. This provider creates standard Kubernetes ConfigMaps that your applications consume through environment variables or volume mounts. The provider synchronizes changes from App Configuration to your cluster automatically. You can manage feature flags, configuration values, and Key Vault references in App Configuration and have them appear as ConfigMaps in your cluster. This approach separates configuration management from cluster operations and provides a centralized view of settings across multiple AKS clusters.
103+
104+
## Verify with kubectl
105+
106+
You can apply the manifests and inspect resources to confirm the configuration is available to your Pods. These manifests are typically stored in files named *configmap.yaml* (ConfigMap) and *deployment.yaml* (Deployment).
107+
108+
```bash
109+
kubectl apply -f configmap.yaml
110+
kubectl apply -f deployment.yaml
111+
kubectl describe configmap app-settings
112+
kubectl describe deployment web-api
113+
# Check if Pod received configuration as environment variables
114+
kubectl exec <pod-name> -- printenv | grep FEATURE
115+
```

0 commit comments

Comments
 (0)