|
| 1 | +# Split Horizon DNS |
| 2 | + |
| 3 | +Split horizon DNS allows you to serve different DNS responses based on the client's location - internal clients receive private IPs while external clients receive public IPs. External-DNS supports split horizon DNS by running multiple instances with different annotation prefixes. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +By default, all external-dns instances use the same annotation prefix: `external-dns.alpha.kubernetes.io/`. This means all instances process the same annotations. To enable split horizon DNS, you can configure each instance to use a different annotation prefix via the `--annotation-prefix` flag. |
| 8 | + |
| 9 | +## Use Cases |
| 10 | + |
| 11 | +- **Internal/External separation**: Internal DNS points to private IPs (ClusterIP), external DNS points to public Load Balancer IPs |
| 12 | +- **Multiple DNS providers**: Route different services to different DNS providers (e.g., internal to CoreDNS, external to Route53) |
| 13 | +- **Geographic split**: Different DNS records for different regions |
| 14 | + |
| 15 | +## Configuration |
| 16 | + |
| 17 | +### Basic Split Horizon Setup |
| 18 | + |
| 19 | +**Internal DNS Instance:** |
| 20 | + |
| 21 | +```bash |
| 22 | +external-dns \ |
| 23 | + --annotation-prefix=internal.company.io/ \ |
| 24 | + --source=service \ |
| 25 | + --source=ingress \ |
| 26 | + --provider=aws \ |
| 27 | + --aws-zone-type=private \ |
| 28 | + --domain-filter=internal.company.com \ |
| 29 | + --txt-owner-id=internal-dns |
| 30 | +``` |
| 31 | + |
| 32 | +**External DNS Instance:** |
| 33 | + |
| 34 | +```bash |
| 35 | +external-dns \ |
| 36 | + --annotation-prefix=external-dns.alpha.kubernetes.io/ \ # default, can be omitted |
| 37 | + --source=service \ |
| 38 | + --source=ingress \ |
| 39 | + --provider=aws \ |
| 40 | + --aws-zone-type=public \ |
| 41 | + --domain-filter=company.com \ |
| 42 | + --txt-owner-id=external-dns |
| 43 | +``` |
| 44 | + |
| 45 | +### Service with Both Annotations |
| 46 | + |
| 47 | +```yaml |
| 48 | +apiVersion: v1 |
| 49 | +kind: Service |
| 50 | +metadata: |
| 51 | + name: myapp |
| 52 | + annotations: |
| 53 | + # Internal DNS reads this |
| 54 | + internal.company.io/hostname: myapp.internal.company.com |
| 55 | + internal.company.io/ttl: "300" |
| 56 | + internal.company.io/target: 10.0.1.50 # Private IP |
| 57 | + |
| 58 | + # External DNS reads this |
| 59 | + external-dns.alpha.kubernetes.io/hostname: myapp.company.com |
| 60 | + external-dns.alpha.kubernetes.io/ttl: "60" |
| 61 | + # No target = uses LoadBalancer IP automatically |
| 62 | +spec: |
| 63 | + type: LoadBalancer |
| 64 | + clusterIP: 10.0.1.50 |
| 65 | + ports: |
| 66 | + - port: 80 |
| 67 | + targetPort: 8080 |
| 68 | + selector: |
| 69 | + app: myapp |
| 70 | +``` |
| 71 | +
|
| 72 | +**Result:** |
| 73 | +
|
| 74 | +- **Internal DNS** (Route53 Private Zone `internal.company.com`): `myapp.internal.company.com → 10.0.1.50` |
| 75 | +- **External DNS** (Route53 Public Zone `company.com`): `myapp.company.com → 203.0.113.10` (LoadBalancer IP) |
| 76 | + |
| 77 | +### Helm Chart Configuration |
| 78 | + |
| 79 | +You can use the Helm chart to deploy multiple instances: |
| 80 | + |
| 81 | +**values-internal.yaml:** |
| 82 | + |
| 83 | +```yaml |
| 84 | +annotationPrefix: "internal.company.io/" |
| 85 | +
|
| 86 | +provider: |
| 87 | + name: aws |
| 88 | +
|
| 89 | +aws: |
| 90 | + zoneType: private |
| 91 | +
|
| 92 | +domainFilters: |
| 93 | + - internal.company.com |
| 94 | +
|
| 95 | +txtOwnerId: internal-dns |
| 96 | +
|
| 97 | +sources: |
| 98 | + - service |
| 99 | + - ingress |
| 100 | +``` |
| 101 | + |
| 102 | +**values-external.yaml:** |
| 103 | + |
| 104 | +```yaml |
| 105 | +# annotationPrefix defaults to "external-dns.alpha.kubernetes.io/" |
| 106 | +# can be omitted or set explicitly: |
| 107 | +# annotationPrefix: "external-dns.alpha.kubernetes.io/" |
| 108 | +
|
| 109 | +provider: |
| 110 | + name: aws |
| 111 | +
|
| 112 | +aws: |
| 113 | + zoneType: public |
| 114 | +
|
| 115 | +domainFilters: |
| 116 | + - company.com |
| 117 | +
|
| 118 | +txtOwnerId: external-dns |
| 119 | +
|
| 120 | +sources: |
| 121 | + - service |
| 122 | + - ingress |
| 123 | +``` |
| 124 | + |
| 125 | +**Deploy:** |
| 126 | + |
| 127 | +```bash |
| 128 | +# Internal instance |
| 129 | +helm install external-dns-internal external-dns/external-dns \ |
| 130 | + --namespace external-dns-internal \ |
| 131 | + --create-namespace \ |
| 132 | + --values values-internal.yaml |
| 133 | +
|
| 134 | +# External instance |
| 135 | +helm install external-dns-external external-dns/external-dns \ |
| 136 | + --namespace external-dns-external \ |
| 137 | + --create-namespace \ |
| 138 | + --values values-external.yaml |
| 139 | +``` |
| 140 | + |
| 141 | +## Advanced Examples |
| 142 | + |
| 143 | +### Three-Way Split (Internal / DMZ / External) |
| 144 | + |
| 145 | +```yaml |
| 146 | +apiVersion: v1 |
| 147 | +kind: Service |
| 148 | +metadata: |
| 149 | + name: api |
| 150 | + annotations: |
| 151 | + # Internal (private network only) |
| 152 | + internal.company.io/hostname: api.internal.company.com |
| 153 | + internal.company.io/ttl: "300" |
| 154 | +
|
| 155 | + # DMZ (accessible from office network) |
| 156 | + dmz.company.io/hostname: api.dmz.company.com |
| 157 | + dmz.company.io/ttl: "120" |
| 158 | +
|
| 159 | + # External (public internet) |
| 160 | + external-dns.alpha.kubernetes.io/hostname: api.company.com |
| 161 | + external-dns.alpha.kubernetes.io/ttl: "60" |
| 162 | + external-dns.alpha.kubernetes.io/cloudflare-proxied: "true" |
| 163 | +spec: |
| 164 | + type: LoadBalancer |
| 165 | + # ... |
| 166 | +``` |
| 167 | + |
| 168 | +**Deploy three instances:** |
| 169 | + |
| 170 | +```bash |
| 171 | +# Internal |
| 172 | +--annotation-prefix=internal.company.io/ --provider=aws --aws-zone-type=private |
| 173 | +
|
| 174 | +# DMZ |
| 175 | +--annotation-prefix=dmz.company.io/ --provider=aws --aws-zone-type=private |
| 176 | +
|
| 177 | +# External |
| 178 | +--annotation-prefix=external-dns.alpha.kubernetes.io/ --provider=cloudflare |
| 179 | +``` |
| 180 | + |
| 181 | +### Different Providers Per Instance |
| 182 | + |
| 183 | +```yaml |
| 184 | +apiVersion: v1 |
| 185 | +kind: Service |
| 186 | +metadata: |
| 187 | + name: webapp |
| 188 | + annotations: |
| 189 | + # Route53 for AWS internal |
| 190 | + aws.company.io/hostname: webapp.aws.company.com |
| 191 | + aws.company.io/aws-alias: "true" |
| 192 | +
|
| 193 | + # Cloudflare for public |
| 194 | + cf.company.io/hostname: webapp.company.com |
| 195 | + cf.company.io/cloudflare-proxied: "true" |
| 196 | +spec: |
| 197 | + type: LoadBalancer |
| 198 | + # ... |
| 199 | +``` |
| 200 | + |
| 201 | +**Deploy:** |
| 202 | + |
| 203 | +```bash |
| 204 | +# AWS instance |
| 205 | +--annotation-prefix=aws.company.io/ --provider=aws |
| 206 | +
|
| 207 | +# Cloudflare instance |
| 208 | +--annotation-prefix=cf.company.io/ --provider=cloudflare |
| 209 | +``` |
| 210 | + |
| 211 | +## Important Notes |
| 212 | + |
| 213 | +1. **Annotation prefix must end with `/`** - The validation will fail if the prefix doesn't end with a forward slash. |
| 214 | +2. **Backward compatibility** - If you don't specify `--annotation-prefix`, the default `external-dns.alpha.kubernetes.io/` is used, maintaining full backward compatibility. |
| 215 | +3. **All annotations use the same prefix** - When you set a custom prefix, ALL external-dns annotations (hostname, ttl, target, cloudflare-proxied, etc.) must use that prefix. |
| 216 | +4. **TXT ownership records** - Each instance should have a unique `--txt-owner-id` to avoid conflicts in ownership tracking. |
| 217 | +5. **Provider-specific annotations** - Provider-specific annotations (like `cloudflare-proxied`, `aws-alias`) also use the custom prefix: |
| 218 | + |
| 219 | +```yaml |
| 220 | +custom.io/hostname: example.com |
| 221 | +custom.io/cloudflare-proxied: "true" # NOT external-dns.alpha.kubernetes.io/cloudflare-proxied |
| 222 | +``` |
| 223 | + |
| 224 | +## Troubleshooting |
| 225 | + |
| 226 | +### Both instances processing the same resources |
| 227 | + |
| 228 | +**Problem:** Both internal and external instances are creating records for the same service. |
| 229 | + |
| 230 | +**Solution:** Make sure you're using different annotation prefixes and that your services have the correct annotations: |
| 231 | + |
| 232 | +```yaml |
| 233 | +# ✅ Correct - different prefixes |
| 234 | +internal.company.io/hostname: internal.example.com |
| 235 | +external-dns.alpha.kubernetes.io/hostname: example.com |
| 236 | +
|
| 237 | +# ❌ Wrong - same prefix |
| 238 | +external-dns.alpha.kubernetes.io/hostname: internal.example.com |
| 239 | +external-dns.alpha.kubernetes.io/hostname: example.com # Second one overwrites first |
| 240 | +``` |
| 241 | + |
| 242 | +### Validation error: "annotation-prefix must end with '/'" |
| 243 | + |
| 244 | +**Problem:** The annotation prefix doesn't end with a forward slash. |
| 245 | + |
| 246 | +**Solution:** Always end your custom prefix with `/`: |
| 247 | + |
| 248 | +```bash |
| 249 | +# ✅ Correct |
| 250 | +--annotation-prefix=custom.io/ |
| 251 | +
|
| 252 | +# ❌ Wrong |
| 253 | +--annotation-prefix=custom.io |
| 254 | +``` |
| 255 | + |
| 256 | +### Provider-specific annotations not working |
| 257 | + |
| 258 | +**Problem:** Cloudflare/AWS-specific annotations are not being applied. |
| 259 | + |
| 260 | +**Solution:** Provider-specific annotations must use the same prefix as the hostname: |
| 261 | + |
| 262 | +```yaml |
| 263 | +# If using custom prefix |
| 264 | +custom.io/hostname: example.com |
| 265 | +custom.io/cloudflare-proxied: "true" |
| 266 | +custom.io/ttl: "60" |
| 267 | +``` |
| 268 | + |
| 269 | +## See Also |
| 270 | + |
| 271 | +- [Configuration Precedence](configuration-precedence.md) - Understanding how external-dns processes configuration |
| 272 | +- [FAQ](../faq.md) - Frequently asked questions |
| 273 | +- [AWS Provider](../tutorials/aws.md) - AWS Route53 configuration |
| 274 | +- [Cloudflare Provider](../tutorials/cloudflare.md) - Cloudflare configuration |
0 commit comments