|
| 1 | +# Ambassador / Emissary-ingress Host |
| 2 | + |
| 3 | +This tutorial describes how to configure ExternalDNS to use the `ambassador-host` source. |
| 4 | +It reads `Host.getambassador.io` resources |
| 5 | +([Emissary-ingress](https://www.getambassador.io/docs/emissary), formerly Ambassador) |
| 6 | +and creates DNS records for the hostnames they declare. |
| 7 | + |
| 8 | +ExternalDNS uses the `getambassador.io/v3alpha1` CRD version. This requires |
| 9 | +Emissary-ingress 3.x (the `datawire/ambassador` v2 CRDs are no longer installed by the |
| 10 | +3.10 quickstart). For older deployments still serving only the v2 CRD, stay on |
| 11 | +ExternalDNS v0.21.0 or earlier. |
| 12 | + |
| 13 | +## How it works |
| 14 | + |
| 15 | +For each `Host`, the source looks at the `external-dns.ambassador-service` annotation. The |
| 16 | +value points to the Emissary-ingress `LoadBalancer` Service whose address is used as the |
| 17 | +record target: |
| 18 | + |
| 19 | +- `name` – service in the same namespace as the `Host`. |
| 20 | +- `namespace/name` – service in an explicit namespace. |
| 21 | +- `name.namespace` – Ambassador's historical cross-namespace syntax. |
| 22 | + |
| 23 | +The hostname comes from `spec.hostname`. A `Host` without the |
| 24 | +`external-dns.ambassador-service` annotation is ignored. The target can be overridden with |
| 25 | +the standard `external-dns.kubernetes.io/target` annotation; TTL and provider-specific |
| 26 | +annotations are honored as well. |
| 27 | + |
| 28 | +## Run it locally with kind |
| 29 | + |
| 30 | +The steps below run end to end on a local [kind](https://kind.sigs.k8s.io/) cluster using |
| 31 | +the `inmemory` provider, so no cloud credentials are needed – the DNS changes |
| 32 | +ExternalDNS would apply are printed to its log. |
| 33 | + |
| 34 | +### 1. Create a cluster |
| 35 | + |
| 36 | +```bash |
| 37 | +kind create cluster --name external-dns-ambassador |
| 38 | +``` |
| 39 | + |
| 40 | +### 2. Install Emissary-ingress 3.10 |
| 41 | + |
| 42 | +```bash |
| 43 | +kubectl apply -f https://app.getambassador.io/yaml/emissary/3.10.0/emissary-crds.yaml |
| 44 | +kubectl wait --timeout=90s --for=condition=available deployment emissary-apiext -n emissary-system |
| 45 | + |
| 46 | +kubectl create namespace emissary |
| 47 | +kubectl apply -f https://app.getambassador.io/yaml/emissary/3.10.0/emissary-emissaryns.yaml |
| 48 | +kubectl -n emissary rollout status deployment/emissary-ingress |
| 49 | +``` |
| 50 | + |
| 51 | +### 3. Deploy ExternalDNS |
| 52 | + |
| 53 | +```yaml |
| 54 | +apiVersion: v1 |
| 55 | +kind: ServiceAccount |
| 56 | +metadata: |
| 57 | + name: external-dns |
| 58 | + namespace: default |
| 59 | +--- |
| 60 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 61 | +kind: ClusterRole |
| 62 | +metadata: |
| 63 | + name: external-dns |
| 64 | +rules: |
| 65 | +- apiGroups: [""] |
| 66 | + resources: ["services","endpoints","pods"] |
| 67 | + verbs: ["get","watch","list"] |
| 68 | +- apiGroups: ["getambassador.io"] |
| 69 | + resources: ["hosts"] |
| 70 | + verbs: ["get","watch","list"] |
| 71 | +--- |
| 72 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 73 | +kind: ClusterRoleBinding |
| 74 | +metadata: |
| 75 | + name: external-dns-viewer |
| 76 | +roleRef: |
| 77 | + apiGroup: rbac.authorization.k8s.io |
| 78 | + kind: ClusterRole |
| 79 | + name: external-dns |
| 80 | +subjects: |
| 81 | +- kind: ServiceAccount |
| 82 | + name: external-dns |
| 83 | + namespace: default |
| 84 | +--- |
| 85 | +apiVersion: apps/v1 |
| 86 | +kind: Deployment |
| 87 | +metadata: |
| 88 | + name: external-dns |
| 89 | + namespace: default |
| 90 | +spec: |
| 91 | + strategy: |
| 92 | + type: Recreate |
| 93 | + selector: |
| 94 | + matchLabels: |
| 95 | + app: external-dns |
| 96 | + template: |
| 97 | + metadata: |
| 98 | + labels: |
| 99 | + app: external-dns |
| 100 | + spec: |
| 101 | + serviceAccountName: external-dns |
| 102 | + containers: |
| 103 | + - name: external-dns |
| 104 | + image: registry.k8s.io/external-dns/external-dns:v0.21.0 |
| 105 | + args: |
| 106 | + - --source=ambassador-host |
| 107 | + - --provider=inmemory |
| 108 | + - --inmemory-zone=example.com # persist records so updates/deletes are observable |
| 109 | + - --log-level=debug # show the records that would be created |
| 110 | + # for a real provider, replace the two lines above, e.g.: |
| 111 | + # - --provider=xxx |
| 112 | + # - --domain-filter=example.com |
| 113 | + # - --registry=txt |
| 114 | + # - --txt-owner-id=my-identifier |
| 115 | +``` |
| 116 | + |
| 117 | +Apply it: |
| 118 | + |
| 119 | +```bash |
| 120 | +kubectl apply -f external-dns.yaml |
| 121 | +``` |
| 122 | + |
| 123 | +Or run it on the host from sources (handy for testing local changes to the source). This |
| 124 | +uses your current kubeconfig context (the kind cluster), so no in-cluster RBAC is needed: |
| 125 | + |
| 126 | +```bash |
| 127 | +go run main.go \ |
| 128 | + --source=ambassador-host \ |
| 129 | + --provider=inmemory \ |
| 130 | + --inmemory-zone=example.com \ |
| 131 | + --interval=10s \ |
| 132 | + --log-level=debug |
| 133 | +``` |
| 134 | + |
| 135 | +`--inmemory-zone=example.com` gives the `inmemory` provider a zone to store records in. |
| 136 | +Without it the provider keeps no state between reconcile loops, so it re-emits the same |
| 137 | +`CREATE` every cycle and you never see an `UPDATE` or `DELETE`. `--interval=10s` shortens |
| 138 | +the wait between reconcile loops (default is one minute). |
| 139 | + |
| 140 | +### 4. Create a Host |
| 141 | + |
| 142 | +The `inmemory` provider has no cloud LoadBalancer, so set the target explicitly with the |
| 143 | +`external-dns.kubernetes.io/target` annotation. The `external-dns.ambassador-service` |
| 144 | +annotation is still required for the `Host` to be processed. |
| 145 | + |
| 146 | +```bash |
| 147 | +kubectl apply -f - <<EOF |
| 148 | +apiVersion: getambassador.io/v3alpha1 |
| 149 | +kind: Host |
| 150 | +metadata: |
| 151 | + name: my-host |
| 152 | + namespace: default |
| 153 | + annotations: |
| 154 | + external-dns.ambassador-service: emissary/emissary-ingress |
| 155 | + external-dns.kubernetes.io/target: 203.0.113.10 |
| 156 | +spec: |
| 157 | + hostname: my-host.example.com |
| 158 | + acmeProvider: |
| 159 | + authority: none |
| 160 | +EOF |
| 161 | +``` |
| 162 | + |
| 163 | +### 5. Verify |
| 164 | + |
| 165 | +```bash |
| 166 | +kubectl logs -l app=external-dns -f |
| 167 | +``` |
| 168 | + |
| 169 | +You should see ExternalDNS pick up the `Host` and create an A record for |
| 170 | +`my-host.example.com` pointing at `203.0.113.10`: |
| 171 | + |
| 172 | +```text |
| 173 | +... level=debug msg="Endpoints generated from Host: default/my-host: [my-host.example.com 0 IN A 203.0.113.10 []]" |
| 174 | +... level=info msg="CREATE: my-host.example.com 0 IN A 203.0.113.10 []" |
| 175 | +``` |
| 176 | + |
| 177 | +With a real provider and a `LoadBalancer` Service, drop the `target` annotation and point |
| 178 | +`external-dns.ambassador-service` at the Emissary-ingress Service |
| 179 | +(`emissary/emissary-ingress` in the manifests above); ExternalDNS resolves the Service's |
| 180 | +external address as the target. |
| 181 | + |
| 182 | +### Cleanup |
| 183 | + |
| 184 | +```bash |
| 185 | +kind delete cluster --name external-dns-ambassador |
| 186 | +``` |
0 commit comments