Month: December 2017

External-dns with Kubernetes

External-dns with Kubernetes

One of the thing I’ve done enough at work is to get cname associated with any new web service I am deploying. The process was straight forward:

1. decide a cname
2. open a ticket for team that manages LAB DNS
3. someone from the team checks the ticket and create a new DNS entry

This all looks reasonable until you use external-dns, a Kubernetes incubator project, to start managing your domains. When deploying a load balancer or ingress, just add an annotation and external-dns will go and update your DNS entry automatically. in the DNS of your choice !!

apiVersion: v1
kind: Service
  name: your-service
    app: your-service
  annotations: https '*' your-arn-address-for-cert https
  type: LoadBalancer
    - port: 8443
      targetPort: 8443
      name: https
    app: your-service

Observe the annotation

To get this functionality, you need to start external-dns pod whose typical deployment looks like below:

apiVersion: extensions/v1beta1
kind: Deployment
    app: external-dns
  name: external-dns
        app: external-dns
        - name: external-dns
          imagePullPolicy: IfNotPresent
            - --log-level=info
            - --policy=sync
            - --provider=aws
            - --source=service
            - --source=ingress
            - --registry=txt
            - --txt-owner-id=any-identifier-string
      serviceAccountName: external-dns

–domain-filter specify the parent domain for which subdomains will be managed
–source specify which sources to consider when scraping the annotations
–policy specify which if you want to keep DNS records in sync or just want to add new records
–provider specify which DNS provider to use

–registry=txt and
–txt-owner-id=any-identifier-string if specified, add a TXT record for every record to identify itself as owner of that record

Once you start using it, its addicting. No longer need to remember those ugly load balancer names or IP address. Power to #Kubernetes community.

helm charts identify last element of list in range

helm charts identify last element of list in range

If you are reading this then most likely you are struggling to identify last element of the list in helm templates. go on read on for answer:

Helm template:

[{{- $root := . -}}
{{- $lastIndex := sub (len $root.Values.config.hosts) 1}}
{{- range $i, $host := $root.Values.config.hosts }}
    "host" : {{ $host }},
    "index" : {{ $i }}
  }{{- if ne $i $lastIndex -}}, {{ end }}
{{- end }}

when provided following values:

  hosts: ["host1", "host2"]

results in:

    "host" : "host1",
    "index" : "0"
    "host" : "host2",
    "index" : "1"

Observe there is no comma after 2nd hash object.