Configure automatically external dns on Kubernetes

Published 05-04-2018 00:00:00

External DNS

ExternalDNS’ current release is v0.5. This version allows you to keep selected zones (via --domain-filter) synchronized with Ingresses and Services of type=LoadBalancer in various cloud providers:

Example for Route 53 on AWS Kops kubernetes cluster with a ressouces files:

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: external-dns
  namespace: YOUR_NAME_SPACE
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: external-dns
    spec:
      containers:
      - name: external-dns
        image: registry.opensource.zalan.do/teapot/external-dns:v0.5.0
        args:
        - --source=service
        - --source=ingress
        - --domain-filter=MY-DOMAIN.ltd # will make ExternalDNS see only the hosted zones matching provided domain, omit to process all available hosted zones
        - --provider=aws
        - --policy=sync 
        - --aws-zone-type=public 
        - --registry=txt
        - --txt-owner-id=my-identifier


Example of Helm package:

Helm Folder:
external-dns\
    charts\
    templates\
        _helpers.tpl
        deployment.yaml
        NOTES.txt
    Chart.yaml
    values.yaml

values.yaml

# Default values for required.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
# Example:

replicaCount: 1
imagePullPolicy: Always

dns:
  name: external-dns
  domain: MY-DOMAIN.ltd
  aws_zone_type: public
  imageName: registry.opensource.zalan.do/teapot/external-dns
  imageTag: v0.5.0
  strategy: Recreate
  enabled: false

ingress: {}
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}

Charts.yaml

apiVersion: v1
appVersion: "1.0"
description: Everything you need to make the magic happend
name: external-dns
version: 0.1.0

templates/deployment.yaml

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "external-dns.fullname" . }}
  labels:
    app: {{ template "external-dns.name" . }}
    chart: {{ template "external-dns.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    type: {{ .Values.dns.strategy }}
  selector:
    matchLabels:
      app: {{ template "external-dns.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "external-dns.name" . }}
        release: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          imagePullPolicy: "{{ .Values.imagePullPolicy }}"
          image: "{{ .Values.dns.imageName }}:{{ .Values.dns.imageTag }}"
          args:
          - --source=service
          - --source=ingress
          - --domain-filter={{ .Values.dns.domain }} # will make ExternalDNS see only the hosted zones matching provided domain, omit to process all available hosted zones
          - --provider=aws
          - --policy=sync # would prevent ExternalDNS from deleting any records, omit to enable full synchronization
          - --aws-zone-type={{ .Values.dns.aws_zone_type }} # only look at public hosted zones (valid values are public, private or no value for both)
          - --registry=txt
          - --txt-owner-id={{ template "external-dns.fullname" . }}
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}