ExternalDNS for Managed Kubernetes
5 min
overview externaldns https //github com/kubernetes sigs/external dns#externaldns is a kubernetes add on that automates the management of public dns records for kubernetes resources, such as services and ingresses exposed outside the cluster unlike kubernetes' internal dns management, which is limited to internal cluster communication, externaldns extends this functionality by delegating dns record management to external dns providers, such as dns the externaldns solution offers the following capabilities empowers developers to manage dns resources traditionally handled manually by infrastructure teams ensures that dns records are synchronized with the current state of the kubernetes cluster automates the management of many dns records, reducing manual effort simplifies dns management while improving security by integrating externaldns with the webhook, you can manage your domains directly within your kubernetes cluster this integration requires an api key or token from the account managing your domains the following tutorial provides detailed technical instructions for deploying externaldns with the webhook using the helm chart target audience this tutorial is intended to help both developers and technical decision makers what you will learn the following tutorial provides detailed technical instructions for deploying externaldns with the webhook using the helm chart before you begin ensure that you have the following before you begin a domain name registered with your domain provider, domain registrar, or a subdomain under your control an managed kubernetes cluster the kubectl https //kubernetes io/docs/tasks/tools/ installed on your local machine the helm tool for installing a helm chart procedure follow these steps to set up externaldns for your managed kubernetes https //docs ionos com/cloud/containers/managed kubernetes with dns provider create a domain name you must first create a primary zone https //docs ionos com/cloud/network services/cloud dns/api how tos/create primary zone for your domain name with cloud dns and then connect domain name to cloud dns https //docs ionos com/cloud/network services/cloud dns/api how tos/connect domain name to cloud dns add helm chart add the external dns helm repository, which contains the official external dns helm chart helm repo add external dns https //kubernetes sigs github io/external dns/ create a kubernetes secret create a kubernetes secret to store your api token using the following command kubectl create secret generic ionos cloud credentials from literal=api key='\<ionos cloud token>' note replace the token with your actual token for more information on managing authentication tokens, see token manager https //docs ionos com/cloud/management/identity access management/token manager remember to refresh the token for automatic certificate renewal create configuration create a helm values file for the externaldns helm chart that includes the webhook configuration in this example, the values file is called external dns ionos cloud values yaml \# externaldns log level loglevel debug # reduce in production \# if true, externaldns will run in a namespaced scope (role and rolebinding will be namespaced too) namespaced false triggerlooponevent true # if true, externaldns will trigger a loop on every event (create/update/delete) on the resources it watches \# kubernetes resources to monitor for dns entries sources \ ingress \ service provider name webhook webhook image repository ghcr io/ionos cloud/external dns ionos webhook tag latest pullpolicy ifnotpresent env \ name log level value debug \ name ionos cloud api key valuefrom secretkeyref name ionos cloud credentials key api key \# the webhook server listens on localhost by default otherwise, you can set server host \ name server port value "8888" # default and recommended port for exposing webhook provider eps \# the exposed server listens on all interfaces (0 0 0 0) by default otherwise, you can set metrics host \ name metrics port value "8080" # default and recommended port for exposing metrics and health eps \ name ionos cloud debug value "false" # change to "true" if you want see details of the http requests \ name dry run value "false" # set to "false" when you want to allow making changes to your dns resources install externaldns to install externaldns with the helm chart, use the following command helm upgrade external dns ionos cloud external dns/external dns f external dns ionos cloud values yaml install \ create application manifest execute the following command to create an echo server application manifest in the echoserver app yaml file apiversion apps/v1 kind deployment metadata name echoserver namespace echoserver spec replicas 1 selector matchlabels app echoserver template metadata labels app echoserver spec containers \ image ealen/echo server\ latest imagepullpolicy ifnotpresent name echoserver ports \ containerport 80 env \ name port value "80" create echoserver namespace issue the following command to create a echoserver namespace kubectl create namespace echoserver apply echo server application manifest execute the following command to apply the deployment resource to your kubernetes cluster kubectl apply f echoserver app yaml you can check the pods of echoserver deployment by running the following command kubectl get pods n echoserver l app=echoserver create service for echo server application use the following content to create a service manifest in the echoserver svc yaml file apiversion v1 kind service metadata name echoserver namespace echoserver spec ports \ port 80 targetport 80 protocol tcp type clusterip selector app echoserver apply service resource apply the service resource to your kubernetes cluster by running the following command kubectl apply f echoserver svc yaml install nginx ingress controller execute the following commands to install the nginx ingress controller in your cluster helm repo add ingress nginx https //kubernetes github io/ingress nginx helm repo update helm install ingress nginx ingress nginx/ingress nginx namespace ingress nginx create namespace create ingress resource using the following content, create a ingress manifest in the echoserver ingress yaml file apiversion networking k8s io/v1 kind ingress metadata name echoserver namespace echoserver annotations kubernetes io/ingress class nginx spec rules \ host app example1 com #this is your subdomain / record name http paths \ path / pathtype prefix backend service name echoserver port number 80 note the host field in the ingress resource must be defined according to the primary zone you have configured in dns for example, if your primary zone is example1 com , you can use a subdomain like app example1 com apply ingress resource apply the ingress resource to your kubernetes cluster by running the following command kubectl apply f echoserver ingress yaml final result the deployment of externaldns on managed kubernetes is complete you can verify that the application deployed is functioning as expected using one of the following options check that the echo server app runs on the subdomain you have specified by using the following command curl i app example1 com/?echo\\ code=404 300 result http/1 1 404 not found http/1 1 300 multiple choices use the following command to ensure that new a and txt records are created curl location request get 'https //dns de fra ionos com/records?filter name=app' \ header 'authorization bearer eyj0exaioijkv1qilcjrawqioii4mme5' \ data '' consclusion by following this tutorial, you have successfully deployed externaldns with the webhook on a managed kubernetes cluster, enabling automated dns record management for your applications this integration streamlines dns operations, reduces manual intervention, and ensures your dns records stay synchronized with your cluster resources you can now confidently manage dns for your kubernetes workloads using dns
