A Guide to Flexibile DNS Configuration

How to configure Custom DNS mode for Domain or ClusterDomain

Overview

Configuring DNS settings can be a daunting task, but with Custom DNS mode, you can leverage Go templates to streamline the process. This guide will walk you through the essentials of setting up Custom DNS for your Domain or ClusterDomain resources.

What is Custom DNS Mode?

Custom DNS mode allows users to utilize Go templates to generate DNS entries dynamically. This is particularly useful for managing complex DNS configurations with ease. The dnsTemplates field is where you specify your desired setup. You can enhance your templates with functions from the Slim Sprig library, detailed here.

Allowed Variables in DNSTemplate

  • {{.domain}}: Represents the value of spec.domain.
  • {{.dnsTarget}}: The effective ingress target, specified by spec.dnsTarget or derived from spec.istioIngressSelector.
  • {{.subDomain}}: Refers to the subdomain of a CAPTenant or a tenant-independent workload.

DNS Record Behavior

  • Each template typically results in one DNS record.
  • If the name contains {{.subDomain}}, a DNS record is created for each valid subdomain from tenants or service exposures.
  • {{.subDomain}} may appear in the target only if it appears in the name.

Example Configuration

Below is an example of how to configure Custom DNSMode for a Domain resource:

apiVersion: sme.sap.com/v1alpha1
kind: Domain
metadata:
  namespace: cap-app-01
  name: cap-app-01-primary
spec:
  domain: my.cluster.shoot.url.k8s.example.com
  ingressSelector:
    app: istio-ingressgateway
    istio: ingressgateway
  dnsMode: Custom
  dnsTemplates:
  - name: '*.{{ .domain }}'
    target: '{{ .dnsTarget }}'
  - name: '{{ .subDomain }}.{{ .domain }}'
    target: '{{ .dnsTarget }}'
  - name: '{{ .subDomain }}.myapp.com'
    target: '{{ .subDomain }}.{{ .domain }}'

This configuration can be applied to both Domain and ClusterDomain resources, offering flexibility and control over your DNS configurations.