[Fix] ‘Unable to connect to the server: dial tcp: lookup *.eks.amazonaws.com’ Error on kubectl

Kubernetes

Share Post Now :

HOW TO GET HIGH PAYING JOBS IN AWS CLOUD

Even as a beginner with NO Experience Coding Language

Explore Free course Now

Table of Contents

Loading

The error message “Unable to connect to the server: dial tcp: lookup *.eks.amazonaws.com on IP:53: no such host” is a common issue encountered when using kubectl, the command-line interface for Kubernetes. This error occurs when kubectl is unable to establish a connection to the Kubernetes API server.

The main cause of this error is a failure to resolve the hostname of the API server. The hostname is typically specified in the kubeconfig file, which is used to configure the connection between kubectl and the API server. In this case, the hostname contains a wildcard, which is causing the DNS resolver to fail to find the correct IP address for the API server.

How to Resolve the Kubectl Command Error

If you are encountering the error “Unable to connect to the server: dial tcp: lookup *.eks.amazonaws.com on IP:53: no such host” while using kubectl with an Amazon EKS cluster, you can follow the steps to resolve the issue:

  1. Backup your existing kubeconfig file: This step is optional, but it’s always a good idea to back up your existing configuration before making any changes. You can run the following command:

mv $HOME/.kube/config $HOME/.kube/config.old

  1. kubectlConfigure kubectl with the EKS API server credentials: To do this, run the following command, replacing [EKS_Region] and [EKS_Cluster_Name] with the appropriate values for your cluster:

aws eks --region [EKS_Region] update-kubeconfig --name [EKS_Cluster_Name]

For example, if your EKS cluster is in the us-east-1 region and the name of your cluster is k21-eks-cluster-cli, you would run the following command:

aws eks --region us-east-1 update-kubeconfig --name k21-eks-cluster-cli

  1. kubectl 1 Test the connection: After updating the kubeconfig file, run the following command to check the connection to the API server:

kubectl get svc

If the connection is successful, you should see a list of services running in your EKS cluster.

In conclusion, if you are encountering the error “Unable to connect to the server: dial tcp: lookup *.eks.amazonaws.com on IP:53: no such host” when using kubectl with an Amazon EKS cluster, you can resolve the issue by configuring kubectl with the correct API server credentials using the aws eks update-kubeconfig command.

Frequently Asked Questions

Why does kubectl have issues resolving the hostname for EKS clusters?

The hostname resolution issue typically stems from wildcard entries in the kubeconfig file. Wildcards in DNS hostnames can lead to failures in resolving to the correct IP address, as DNS resolvers may not correctly handle them.

How can I back up my current kubeconfig file before making changes?

You can back up your kubeconfig file by renaming it. Use the command mv $HOME/.kube/config $HOME/.kube/config.old to rename the existing config file, preserving it before you make changes.

How can I test if my kubectl connection to the EKS cluster is now working?

After updating the kubeconfig file, test the connection by running kubectl get svc. If the connection is set up correctly, you will see a list of services running in your EKS cluster.

What should I do if I continue to encounter the same error after updating the kubeconfig file?

If the error persists, check for any typos in your AWS CLI command and ensure that your AWS credentials are up-to-date and have the necessary permissions. Also, verify that your EKS cluster is active and that you have network connectivity to the AWS region hosting your cluster.

Related Post

Join FREE Class

Begin your journey towards becoming a Certified Kubernetes Administrator [CKA]  from our Certified Kubernetes Administrator (CKA) training program. To know about the Roles and Responsibilities of a Kubernetes administrator, why learn Docker and KubernetesJob opportunities for Kubernetes administrator in the market. Also, know about Hands-On labs you must perform to clear the Certified Kubernetes Administrator (CKA) Certification exam by registering for our FREE class.

Docker & Kubernetes Free class

Picture of mike

mike

I started my IT career in 2000 as an Oracle DBA/Apps DBA. The first few years were tough (<$100/month), with very little growth. In 2004, I moved to the UK. After working really hard, I landed a job that paid me £2700 per month. In February 2005, I saw a job that was £450 per day, which was nearly 4 times of my then salary.