Deploy External DNS with AWS EKS
Tags: devops, kubernetes, awseks, dns
Published: 2023-07-13 10:42:00

---
title: Deploy External DNS with AWS EKS
published: true
date: 2023-04-16 13:07:14 UTC
tags: devops,kubernetes,awseks,dns
canonical_url: https://ravijkyada.medium.com/deploy-external-dns-with-aws-eks-3d0157174169
---

![](https://cdn-images-1.medium.com/max/1024/0*MojM1HrderdJuvrO)

Amazon Web Services (AWS) Elastic Kubernetes Service (EKS) is a managed service that simplifies the deployment, scaling, and management of containerized applications using Kubernetes.

One of the key benefits of EKS is its ability to integrate with other AWS services, such as Route 53, to provide DNS resolution for your Kubernetes clusters.

In this article, we will discuss how to deploy External DNS on AWS EKS to automate the creation and deletion of DNS records for Kubernetes services.

### Overview of External DNS:

External DNS is a Kubernetes add-on that automatically creates and deletes DNS records in an external DNS provider based on Kubernetes service and ingress resources.

This enables you to use custom domain names for your Kubernetes services without having to manually create and update DNS records. External DNS supports a variety of DNS providers, including Route 53, Google Cloud DNS, Azure DNS, and more.

### Deploying External DNS on AWS EKS:

To deploy External DNS on AWS EKS, you will need to follow the steps below:

First, you need to create an IAM policy that grants External DNS permissions to manage Route 53 resources. You can use the following policy as a starting point:

{% gist https://gist.github.com/RAVIKYADA/438f708fd4f7ce78bac49c0f977694ca %}

First, you need to create an IAM policy that grants External DNS permissions to manage Route 53 resources. You can use the following policy as a starting point:

Next, you need to create an IAM Service Account that External DNS can assume to manage Route 53 resources. You can use the following command to create the role:

```
eksctl create iamserviceaccount --name --namespace --cluster --attach-policy-arn --approve --profile
```

Please Replace the Values between hyphens <> in this command, Here I had given you Sample Command. Please be sure you are using the same namespace during the whole tutorial.

```
eksctl create iamserviceaccount --name external-dns --namespace default --cluster demo-cluster --attach-policy-arnarn:aws:iam::012345678901:policy/ExternalDNSPolicy--approve --profile demo-keys
```

In Backend, this command will create a Cloudformation stack in your was account. so you can check the status and resources created by this command in the AWS cloud formation stack Dashboard.

After Completing this Cloudformation stack, you can check ServiceAccount created in the default namespace.

```
kubectl get sa -n default
```

Now We are done with the AWS Side Configurations, Now let’s have some work done for the Kubernetes side to give Cluster access to change the DNS Changes at Route53 Hosted Zone from Kubernetes Files.

### Create ClusterRole and ClusterRole Binding:

Let’s Create Cluster Role and Clusterrole binding files so that external-dns-controller can do change to the Route53 DNS.

{% gist https://gist.github.com/RAVIKYADA/b9aec8329d29c2a682356a8130c20d5e %}

Now Let’s Create a ClusterRoleBinding.yaml file for the Clusterrole we created.

{% gist https://gist.github.com/RAVIKYADA/db1a3d1480674f5778951a3a06039bae %}

Now, For the Acess, we have done all the work with Cluster and cluster role binding, Just Apply both files with the command.

```
kubectl apply -f <filename.yaml>
```

Now we will create One Deployment File for external-dns-controller which will do all the work for us.

### Create a Deployment file for External DNS Controller

{% gist https://gist.github.com/RAVIKYADA/d85cc203e5e04d2058d91dc041b97911 %}

This Deployment Managed Pod will deploy the External DNS controller in your Kubernetes cluster. The controller will monitor your Kubernetes services and ingresses and automatically create and delete Route 53 DNS records as necessary.

After Deploying this Deployment File Now Check for the Deployment with 1 Pod is Up And Running.

```
kubectl get deployments
```

Also, You can check the Logs of the Pod Created by the Deployment By:

```
kubectl logs <pod name> -n default
```

Now, After Full Deployment, you are Ready with the External DNS and you don’t need to add External DNS to all your API Of the Cluster Services. It will automatically add all your Services and Ingresses automatically to the Route53 Hosted Zone.

### Configuring External DNS in K8s Files

Once External DNS is deployed, you can configure it to create and manage DNS records for your Kubernetes services. To do this, you can add annotations to your Kubernetes services or ingresses that specify the desired DNS name and DNS provider.

For example, to create a DNS record for a Kubernetes service named “my-service” with a DNS name of “ [my-service.example.com](http://my-service.example.com) “ in Route 53, you can add the following annotation to your service:

{% gist https://gist.github.com/RAVIKYADA/21c74394fc987a71e3117e7922ea7995 %}

Congrats! You have successfully deployed external DNS with AWS EKS. With external DNS, you can now easily expose your Kubernetes services to the internet or other parts of your infrastructure by automatically creating DNS records.

Remember to regularly monitor your DNS records to ensure that they are accurate and up-to-date. You can also customize external DNS to meet your specific needs by modifying the configuration options.

Overall, deploying external DNS with AWS EKS is a straightforward process that can provide significant benefits for your applications. With this guide, you should be well-equipped to get started with external DNS and take advantage of its powerful features.

_Originally published at_ [_https://hashnode.ravikyada.in_](https://hashnode.ravikyada.in/deploying-external-dns-with-aws-eks)_._