Followers

Kuberenetes- Headless Services

 To get the DNS record of a Kubernetes service or pod, you can use the following methods and commands depending on what you're trying to...

 To get the DNS record of a Kubernetes service or pod, you can use the following methods and commands depending on what you're trying to resolve.

1. Getting the DNS Record for a Service:

If you have a service (e.g., mysql-headless-service) and you want to resolve its DNS name, you can simply use the nslookup command from any pod in the same Kubernetes cluster. The format will be:


<service-name>.<namespace>.svc.cluster.local

Example:


nslookup mysql-headless-service.default.svc.cluster.local
  • This will resolve the DNS name of the service (for a headless service, it will resolve to the service's IP or directly to the pod's DNS name, depending on how it’s configured).

2. Getting the DNS Record for Individual Pods (in the case of Headless Service):

For a headless service, each pod will have its own DNS record. The format for pod DNS records will be:


<pod-name>.<service-name>.<namespace>.svc.cluster.local

Example:

If you want to resolve the DNS name for individual pods:


nslookup mysql-0.mysql-headless-service.default.svc.cluster.local nslookup mysql-1.mysql-headless-service.default.svc.cluster.local
  • These commands resolve to the IP addresses of the individual pods in the StatefulSet, assuming the pods are correctly set up and running.

3. Using kubectl to Get Pod Information:

If you're unsure of the exact pod names or want to list the pods under a specific service, you can use kubectl to get the details of your pods and then perform a DNS lookup for each pod.

Example:


kubectl get pods -l app=mysql -o wide

This command will list all pods with the label app=mysql, and it will display additional information like the pod's IP address. You can then use the pod's name to resolve its DNS record using nslookup.

4. Checking DNS Configuration in a Pod:

To check whether DNS resolution is working inside a Kubernetes pod, you can run nslookup or dig from within any pod. Here's an example:


kubectl run -i --tty --rm debug --image=busybox --restart=Never -- nslookup mysql-headless-service.default.svc.cluster.local

This command starts a temporary pod using the busybox image, runs the nslookup command to resolve the service's DNS name, and then deletes the pod after completion.

Alternatively, if you want to see all the available DNS names and troubleshoot DNS resolution, you can also try:


kubectl exec -it <pod-name> -- nslookup <service-name>.<namespace>.svc.cluster.local

Where:

  • <pod-name>: The name of a pod in your cluster.
  • <service-name>: The name of your service.
  • <namespace>: The namespace where the service is running (e.g., default).

5. Checking the DNS Record for Services in the Cluster:

You can also use the kubectl get services command to list all the services in a particular namespace and verify their ClusterIP or DNS names:


kubectl get svc -n <namespace>

Example:


kubectl get svc -n default

This will list all services in the default namespace, showing their names, cluster IPs, and ports. You can then derive the DNS record for the service based on the service name and namespace.


COMMENTS

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker file with buildkit,1,Docker file with buildx,1,Docker Image Scan,1,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,git quiz,1,Git Worksheet,1,headless service DNS service record,1,ITIL,1,ITSM,1,Jira,3,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SDLC Quiz,5,SonarQube,3,Splunk,2,vagrant kubernetes,1,Windows,1,YAML Basics,1,
ltr
item
DevOpsWorld: Kuberenetes- Headless Services
Kuberenetes- Headless Services
DevOpsWorld
https://www.devopsworld.co.in/2025/02/kuberenetes-headless-services.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/2025/02/kuberenetes-headless-services.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content