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
This example demonstrates how to use the `localdns_config` feature in the terraform-azurerm-aks module to configure LocalDNS settings for your AKS cluster.
4
+
5
+
## Overview
6
+
7
+
LocalDNS in AKS allows you to customize DNS resolution behavior for pods with different DNS policies:
8
+
9
+
-**VNet DNS Overrides**: Configuration for pods using `dnsPolicy: default` (uses VNet DNS)
10
+
-**Kube DNS Overrides**: Configuration for pods using `dnsPolicy: ClusterFirst` (uses Kubernetes CoreDNS)
11
+
12
+
## Configuration Features
13
+
14
+
This example configures:
15
+
16
+
1.**Mode**: Set to `Required` to enforce LocalDNS usage
17
+
2.**VNet DNS Overrides**:
18
+
- Root zone (`.`) configured to use VNet DNS with caching and stale serving
19
+
- Custom zone (`example.local`) with round-robin policy
20
+
3.**Kube DNS Overrides**:
21
+
- Cluster-local zone (`cluster.local`) using CoreDNS with enhanced caching
22
+
- Service discovery zone (`svc.cluster.local`) for Kubernetes services
23
+
24
+
## Key Configuration Options
25
+
26
+
### DNS Zone Configuration
27
+
28
+
Each zone can be configured with:
29
+
30
+
-**Query Logging**: Set to `Error` or `Log` for different verbosity levels
31
+
-**Protocol**: `PreferUDP` (default) or `ForceTCP` for transport protocol
32
+
-**Forward Destination**: `VnetDNS` or `ClusterCoreDNS` based on the zone type
33
+
-**Forward Policy**: `Random`, `RoundRobin`, or `Sequential` for upstream server selection
34
+
-**Caching**: Configure cache duration and stale serving policies
35
+
-**Concurrency**: Control maximum concurrent queries
36
+
37
+
### Important Constraints
38
+
39
+
- Root zone (`.`) under `vnet_dns_overrides` cannot use `ClusterCoreDNS`
40
+
- Zone `cluster.local` cannot use `VnetDNS` as forward destination
41
+
- When protocol is `ForceTCP`, serve_stale cannot be `Verify`
42
+
43
+
## Usage
44
+
45
+
1. Set your Azure credentials:
46
+
```bash
47
+
export ARM_CLIENT_ID="your-client-id"
48
+
export ARM_CLIENT_SECRET="your-client-secret"
49
+
export ARM_SUBSCRIPTION_ID="your-subscription-id"
50
+
export ARM_TENANT_ID="your-tenant-id"
51
+
```
52
+
53
+
2. Initialize and apply Terraform:
54
+
```bash
55
+
terraform init
56
+
terraform plan
57
+
terraform apply
58
+
```
59
+
60
+
3. Connect to your AKS cluster:
61
+
```bash
62
+
az aks get-credentials --resource-group $(terraform output -raw resource_group_name) --name $(terraform output -raw aks_cluster_name)
63
+
```
64
+
65
+
## Testing LocalDNS Configuration
66
+
67
+
After deployment, you can test the LocalDNS configuration:
68
+
69
+
```bash
70
+
# Test DNS resolution from a pod
71
+
kubectl run -it --rm debug --image=busybox --restart=Never -- nslookup kubernetes.default.svc.cluster.local
72
+
73
+
# Check LocalDNS pods
74
+
kubectl get pods -n kube-system -l k8s-app=node-local-dns
75
+
76
+
# View LocalDNS configuration
77
+
kubectl get configmap node-local-dns -n kube-system -o yaml
0 commit comments