Skip to content

Commit 37d947d

Browse files
authored
Update coredns-custom.md
Fixed formatting for clean staging
1 parent 0953259 commit 37d947d

File tree

1 file changed

+109
-109
lines changed

1 file changed

+109
-109
lines changed

articles/aks/coredns-custom.md

Lines changed: 109 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -37,148 +37,148 @@ You can customize CoreDNS with AKS to perform on-the-fly DNS name rewrites.
3737

3838
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.
3939

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.
6161
6262
2. Create the ConfigMap using the [`kubectl apply configmap`][kubectl-apply] command and specify the name of your YAML manifest.
6363

64-
```console
65-
kubectl apply -f corednsms.yaml
66-
```
64+
```console
65+
kubectl apply -f corednsms.yaml
66+
```
6767

6868
3. Verify the customizations have been applied using the [`kubectl get configmaps`][kubectl-get] and specify your *coredns-custom* ConfigMap.
6969

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+
```
7373

7474
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.
7575

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+
```
7979

8080
## Custom forward server
8181

8282
If you need to specify a forward server for your network traffic, you can create a ConfigMap to customize DNS.
8383

8484
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.
8585

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+
```
9898

9999
2. Create the ConfigMap using the [`kubectl apply configmap`][kubectl-apply] command and specify the name of your YAML manifest.
100100

101-
```console
102-
kubectl apply -f corednsms.yaml
103-
```
101+
```console
102+
kubectl apply -f corednsms.yaml
103+
```
104104

105105
3. Force CoreDNS to reload the ConfigMap using the [`kubectl delete pod`][kubectl delete] so the Kubernetes Scheduler can recreate them.
106106

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+
```
110110

111111
## Use custom domains
112112

113113
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.
114114

115115
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.
116116

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+
```
131131

132132
2. Create the ConfigMap using the [`kubectl apply configmap`][kubectl-apply] command and specify the name of your YAML manifest.
133133

134-
```console
135-
kubectl apply -f corednsms.yaml
136-
```
134+
```console
135+
kubectl apply -f corednsms.yaml
136+
```
137137

138138
3. Force CoreDNS to reload the ConfigMap using the [`kubectl delete pod`][kubectl delete] so the Kubernetes Scheduler can recreate them.
139139

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+
```
143143

144144
## Stub domains
145145

146146
CoreDNS can also be used to configure stub domains.
147147

148148
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.
149149

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 {
159159
errors
160160
cache 30
161161
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+
}
168168
169-
```
169+
```
170170

171171
2. Create the ConfigMap using the [`kubectl apply configmap`][kubectl-apply] command and specify the name of your YAML manifest.
172172

173-
```console
174-
kubectl apply -f corednsms.yaml
175-
```
173+
```console
174+
kubectl apply -f corednsms.yaml
175+
```
176176

177177
3. Force CoreDNS to reload the ConfigMap using the [`kubectl delete pod`][kubectl delete] so the Kubernetes Scheduler can recreate them.
178178

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+
```
182182

183183
## Hosts plugin
184184

@@ -208,32 +208,32 @@ For general CoreDNS troubleshooting steps, such as checking the endpoints or res
208208

209209
1. Add the following configuration to your coredns-custom ConfigMap:
210210

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+
```
221221

222222
2. Apply the configuration changes and force CoreDNS to reload the ConfigMap using the following commands:
223223

224-
```console
225-
# Apply configuration changes
226-
kubectl apply -f corednsms.yaml
224+
```console
225+
# Apply configuration changes
226+
kubectl apply -f corednsms.yaml
227227
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+
```
231231

232232
3. View the CoreDNS debug logging using the `kubectl logs` command.
233233

234-
```console
235-
kubectl logs --namespace kube-system -l k8s-app=kube-dns
236-
```
234+
```console
235+
kubectl logs --namespace kube-system -l k8s-app=kube-dns
236+
```
237237

238238
## Next steps
239239

0 commit comments

Comments
 (0)