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
@@ -37,148 +37,148 @@ You can customize CoreDNS with AKS to perform on-the-fly DNS name rewrites.
37
37
38
38
1. Create a file named `corednsms.yaml` and paste the following example configuration. Make sure to replace `<domain to be rewritten>` with your own fully qualified domain name.
39
39
40
-
```yaml
41
-
apiVersion: v1
42
-
kind: ConfigMap
43
-
metadata:
44
-
name: coredns-custom
45
-
namespace: kube-system
46
-
data:
47
-
test.override: |
48
-
<domain to be rewritten>.com:53 {
49
-
log
50
-
errors
51
-
rewrite stop {
52
-
name regex (.*)\.<domain to be rewritten>.com {1}.default.svc.cluster.local
53
-
answer name (.*)\.default\.svc\.cluster\.local {1}.<domain to be rewritten>.com
54
-
}
55
-
forward . /etc/resolv.conf # you can redirect this to a specific DNS server such as 10.0.0.10, but that server must be able to resolve the rewritten domain name
56
-
}
57
-
```
58
-
59
-
> [!IMPORTANT]
60
-
> If you redirect to a DNS server, such as the CoreDNS service IP, that DNS server must be able to resolve the rewritten domain name.
40
+
```yaml
41
+
apiVersion: v1
42
+
kind: ConfigMap
43
+
metadata:
44
+
name: coredns-custom
45
+
namespace: kube-system
46
+
data:
47
+
test.override: |
48
+
<domain to be rewritten>.com:53 {
49
+
log
50
+
errors
51
+
rewrite stop {
52
+
name regex (.*)\.<domain to be rewritten>.com {1}.default.svc.cluster.local
53
+
answer name (.*)\.default\.svc\.cluster\.local {1}.<domain to be rewritten>.com
54
+
}
55
+
forward . /etc/resolv.conf # you can redirect this to a specific DNS server such as 10.0.0.10, but that server must be able to resolve the rewritten domain name
56
+
}
57
+
```
58
+
59
+
> [!IMPORTANT]
60
+
> If you redirect to a DNS server, such as the CoreDNS service IP, that DNS server must be able to resolve the rewritten domain name.
61
61
62
62
2. Create the ConfigMap using the [`kubectl apply configmap`][kubectl-apply] command and specify the name of your YAML manifest.
63
63
64
-
```console
65
-
kubectl apply -f corednsms.yaml
66
-
```
64
+
```console
65
+
kubectl apply -f corednsms.yaml
66
+
```
67
67
68
68
3. Verify the customizations have been applied using the [`kubectl get configmaps`][kubectl-get] and specify your *coredns-custom* ConfigMap.
69
69
70
-
```console
71
-
kubectl get configmaps --namespace=kube-system coredns-custom -o yaml
72
-
```
70
+
```console
71
+
kubectl get configmaps --namespace=kube-system coredns-custom -o yaml
72
+
```
73
73
74
74
4. Force CoreDNS to reload the ConfigMap using the [`kubectl delete pod`][kubectl delete] command and the `kube-dns` label. This command deletes the `kube-dns` pods, and then the Kubernetes Scheduler recreates them. The new pods contain the change in TTL value.
75
75
76
-
```console
77
-
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns
78
-
```
76
+
```console
77
+
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns
78
+
```
79
79
80
80
## Custom forward server
81
81
82
82
If you need to specify a forward server for your network traffic, you can create a ConfigMap to customize DNS.
83
83
84
84
1. Create a file named `corednsms.yaml` and paste the following example configuration. Make sure to replace the `forward` name and the address with the values for your own environment.
85
85
86
-
```yaml
87
-
apiVersion: v1
88
-
kind: ConfigMap
89
-
metadata:
90
-
name: coredns-custom
91
-
namespace: kube-system
92
-
data:
93
-
test.server: | # you may select any name here, but it must end with the .server file extension
94
-
<domain to be rewritten>.com:53 {
95
-
forward foo.com 1.1.1.1
96
-
}
97
-
```
86
+
```yaml
87
+
apiVersion: v1
88
+
kind: ConfigMap
89
+
metadata:
90
+
name: coredns-custom
91
+
namespace: kube-system
92
+
data:
93
+
test.server: | # you may select any name here, but it must end with the .server file extension
94
+
<domain to be rewritten>.com:53 {
95
+
forward foo.com 1.1.1.1
96
+
}
97
+
```
98
98
99
99
2. Create the ConfigMap using the [`kubectl apply configmap`][kubectl-apply] command and specify the name of your YAML manifest.
100
100
101
-
```console
102
-
kubectl apply -f corednsms.yaml
103
-
```
101
+
```console
102
+
kubectl apply -f corednsms.yaml
103
+
```
104
104
105
105
3. Force CoreDNS to reload the ConfigMap using the [`kubectl delete pod`][kubectl delete] so the Kubernetes Scheduler can recreate them.
106
106
107
-
```console
108
-
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns
109
-
```
107
+
```console
108
+
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns
109
+
```
110
110
111
111
## Use custom domains
112
112
113
113
You may want to configure custom domains that can only be resolved internally. For example, you may want to resolve the custom domain *puglife.local*, which isn't a valid top-level domain. Without a custom domain ConfigMap, the AKS cluster can't resolve the address.
114
114
115
115
1. Create a new file named `corednsms.yaml` and paste the following example configuration. Make sure to update the custom domain and IP address with the values for your own environment.
116
116
117
-
```yaml
118
-
apiVersion: v1
119
-
kind: ConfigMap
120
-
metadata:
121
-
name: coredns-custom
122
-
namespace: kube-system
123
-
data:
124
-
puglife.server: | # you may select any name here, but it must end with the .server file extension
125
-
puglife.local:53 {
126
-
errors
127
-
cache 30
128
-
forward . 192.11.0.1 # this is my test/dev DNS server
129
-
}
130
-
```
117
+
```yaml
118
+
apiVersion: v1
119
+
kind: ConfigMap
120
+
metadata:
121
+
name: coredns-custom
122
+
namespace: kube-system
123
+
data:
124
+
puglife.server: | # you may select any name here, but it must end with the .server file extension
125
+
puglife.local:53 {
126
+
errors
127
+
cache 30
128
+
forward . 192.11.0.1 # this is my test/dev DNS server
129
+
}
130
+
```
131
131
132
132
2. Create the ConfigMap using the [`kubectl apply configmap`][kubectl-apply] command and specify the name of your YAML manifest.
133
133
134
-
```console
135
-
kubectl apply -f corednsms.yaml
136
-
```
134
+
```console
135
+
kubectl apply -f corednsms.yaml
136
+
```
137
137
138
138
3. Force CoreDNS to reload the ConfigMap using the [`kubectl delete pod`][kubectl delete] so the Kubernetes Scheduler can recreate them.
139
139
140
-
```console
141
-
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns
142
-
```
140
+
```console
141
+
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns
142
+
```
143
143
144
144
## Stub domains
145
145
146
146
CoreDNS can also be used to configure stub domains.
147
147
148
148
1. Create a file named `corednsms.yaml` and paste the following example configuration. Make sure to update the custom domains and IP addresses with the values for your own environment.
149
149
150
-
```yaml
151
-
apiVersion: v1
152
-
kind: ConfigMap
153
-
metadata:
154
-
name: coredns-custom
155
-
namespace: kube-system
156
-
data:
157
-
test.server: | # you may select any name here, but it must end with the .server file extension
158
-
abc.com:53 {
150
+
```yaml
151
+
apiVersion: v1
152
+
kind: ConfigMap
153
+
metadata:
154
+
name: coredns-custom
155
+
namespace: kube-system
156
+
data:
157
+
test.server: | # you may select any name here, but it must end with the .server file extension
158
+
abc.com:53 {
159
159
errors
160
160
cache 30
161
161
forward . 1.2.3.4
162
-
}
163
-
my.cluster.local:53 {
164
-
errors
165
-
cache 30
166
-
forward . 2.3.4.5
167
-
}
162
+
}
163
+
my.cluster.local:53 {
164
+
errors
165
+
cache 30
166
+
forward . 2.3.4.5
167
+
}
168
168
169
-
```
169
+
```
170
170
171
171
2. Create the ConfigMap using the [`kubectl apply configmap`][kubectl-apply] command and specify the name of your YAML manifest.
172
172
173
-
```console
174
-
kubectl apply -f corednsms.yaml
175
-
```
173
+
```console
174
+
kubectl apply -f corednsms.yaml
175
+
```
176
176
177
177
3. Force CoreDNS to reload the ConfigMap using the [`kubectl delete pod`][kubectl delete] so the Kubernetes Scheduler can recreate them.
178
178
179
-
```console
180
-
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns
181
-
```
179
+
```console
180
+
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns
181
+
```
182
182
183
183
## Hosts plugin
184
184
@@ -208,32 +208,32 @@ For general CoreDNS troubleshooting steps, such as checking the endpoints or res
208
208
209
209
1. Add the following configuration to your coredns-custom ConfigMap:
210
210
211
-
```yaml
212
-
apiVersion: v1
213
-
kind: ConfigMap
214
-
metadata:
215
-
name: coredns-custom
216
-
namespace: kube-system
217
-
data:
218
-
log.override: | # you may select any name here, but it must end with the .override file extension
219
-
log
220
-
```
211
+
```yaml
212
+
apiVersion: v1
213
+
kind: ConfigMap
214
+
metadata:
215
+
name: coredns-custom
216
+
namespace: kube-system
217
+
data:
218
+
log.override: | # you may select any name here, but it must end with the .override file extension
219
+
log
220
+
```
221
221
222
222
2. Apply the configuration changes and force CoreDNS to reload the ConfigMap using the following commands:
223
223
224
-
```console
225
-
# Apply configuration changes
226
-
kubectl apply -f corednsms.yaml
224
+
```console
225
+
# Apply configuration changes
226
+
kubectl apply -f corednsms.yaml
227
227
228
-
# Force CoreDNS to reload the ConfigMap
229
-
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns
230
-
```
228
+
# Force CoreDNS to reload the ConfigMap
229
+
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns
230
+
```
231
231
232
232
3. View the CoreDNS debug logging using the `kubectl logs` command.
0 commit comments