Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pod's dns subdomain cannot be resolved if headless service name not same as StatefulSet name #74950

Closed
dunjut opened this issue Mar 5, 2019 · 10 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/network Categorizes an issue or PR as relevant to SIG Network. triage/unresolved Indicates an issue that can not or will not be resolved.

Comments

@dunjut
Copy link

dunjut commented Mar 5, 2019

What happened:

case A:
In namespace foo, create a StatefulSet named database and a headless service named database, I can successfully resolve database-0.database.foo.svc.cluster.local.

case B:
In namespace foo, create a StatefulSet named database and a headless service named db-svc, I failed to resolve database-0.db-svc.foo.svc.cluster.local.

What you expected to happen:

In case B, Pod's subdomain should be successfully resolved.

How to reproduce it (as minimally and precisely as possible):
Just create a StatefulSet and a headless service...

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version):
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.6", GitCommit:"9f8ebd171479bec0ada837d7ee641dec2f8c6dd1", GitTreeState:"clean", BuildDate:"2018-03-21T15:21:50Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.6", GitCommit:"9f8ebd171479bec0ada837d7ee641dec2f8c6dd1", GitTreeState:"clean", BuildDate:"2018-03-21T15:13:31Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
  • Cloud provider or hardware configuration:
  • OS (e.g: cat /etc/os-release): Ubuntu 16.04.2 LTS
  • Kernel (e.g. uname -a): Linux master 4.4.0-62-generic add travis integration #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  • Install tools: kubeadm
  • Others: kubedns docker image version 1.14.7
@dunjut dunjut added the kind/bug Categorizes issue or PR as related to a bug. label Mar 5, 2019
@k8s-ci-robot k8s-ci-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Mar 5, 2019
@dunjut
Copy link
Author

dunjut commented Mar 5, 2019

/sig network

@k8s-ci-robot k8s-ci-robot added sig/network Categorizes an issue or PR as relevant to SIG Network. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 5, 2019
@prameshj
Copy link
Contributor

prameshj commented Mar 7, 2019

I just tried this using the yaml here - https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#creating-a-statefulset

Verified the the service 'nginx` is indeed headless, returns the pod ips when resolving the service name - nginx.

I was able to resolve:
host web-0.nginx
web-0.nginx.default.svc.cluster.local has address 10.0.2.6

Can you share the yaml you were using?

@prameshj
Copy link
Contributor

prameshj commented Mar 7, 2019

/assign @dunjut

@k8s-ci-robot
Copy link
Contributor

@prameshj: GitHub didn't allow me to assign the following users: dastan.

Note that only kubernetes members and repo collaborators can be assigned and that issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

/assign @dunjut dastan

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@dunjut
Copy link
Author

dunjut commented Mar 8, 2019

@prameshj Could you try to remove the spec.serviceName field in StatefulSet and resolve again?

Now I think this may be by design but I don't understand why serviceName is needed since we already have a name for Service...

@thockin thockin added the triage/unresolved Indicates an issue that can not or will not be resolved. label Mar 8, 2019
@prameshj
Copy link
Contributor

prameshj commented Mar 8, 2019

I can't remove the serviceName : 'missing required field "serviceName" in io.k8s.api.apps.v1.StatefulSetSpec'

if you don't specify serviceName, I don't see how the endpoints for the headless service can be updated to include the pods in the statefulSet. Can you share the yamls for how you created the service and statefulSets? It looks like this is working as intended.

@dunjut
Copy link
Author

dunjut commented Mar 13, 2019

@prameshj Sorry I just noticed your reply.

This should be easy to reproduce, you can change serviceName to 'web' and keep the real headless service's name being 'nginx', then dns fails.

The headless service with a selector already includes the pods in StatefulSet, I just don't understand why serviceName is needed.

@prameshj
Copy link
Contributor

I understood the issue now, maybe it should read "Pod's dns subdomain cannot be resolved if headless service name not same as serviceName in StatefulSet spec"? This is working as intended. From the api doc:

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#statefulset-v1-apps

"selector is a label query over pods that should match the replica count. It must match the pod template's labels."

"serviceName is the name of the service that governs this StatefulSet. This service must exist before the StatefulSet, and is responsible for the network identity of the set. Pods get DNS/hostnames that follow the pattern: pod-specific-string.serviceName.default.svc.cluster.local where "pod-specific-string" is managed by the StatefulSet controller.
templatePodTemplateSpec"

serviceName is used for dns records, selector is for determining count of replicas.

Closing issue since this is working as intended. Please reopen if needed.
/close

@k8s-ci-robot
Copy link
Contributor

@prameshj: Closing this issue.

In response to this:

I understood the issue now, maybe it should read "Pod's dns subdomain cannot be resolved if headless service name not same as serviceName in StatefulSet spec"? This is working as intended. From the api doc:

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#statefulset-v1-apps

"selector is a label query over pods that should match the replica count. It must match the pod template's labels."

"serviceName is the name of the service that governs this StatefulSet. This service must exist before the StatefulSet, and is responsible for the network identity of the set. Pods get DNS/hostnames that follow the pattern: pod-specific-string.serviceName.default.svc.cluster.local where "pod-specific-string" is managed by the StatefulSet controller.
templatePodTemplateSpec"

serviceName is used for dns records, selector is for determining count of replicas.

Closing issue since this is working as intended. Please reopen if needed.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@vadasambar
Copy link
Member

vadasambar commented Sep 2, 2020

If anyone is wondering why this is said to be working as intended when the api reference does not mention anything about headless service, the docs talk about this under Limitations.

StatefulSets currently require a Headless Service to be responsible for the network identity of the Pods. You are responsible for creating this Service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/network Categorizes an issue or PR as relevant to SIG Network. triage/unresolved Indicates an issue that can not or will not be resolved.
Projects
None yet
Development

No branches or pull requests

5 participants