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

KEP-4762: Allows setting any FQDN as the pod's hostname #4768

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HirazawaUi
Copy link
Contributor

  • One-line PR description: Allows users to set any FQDN as the hostname of a pod
  • Other comments:

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 18, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: HirazawaUi
Once this PR has been reviewed and has the lgtm label, please assign deads2k, thockin for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/network Categorizes an issue or PR as relevant to SIG Network. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 18, 2024

This can ultimately simplify `Kubelet` as it can remove legacy behavior, but it means teaching the `kube-apiserver` about the `cluster-suffix`.

However, it is challenging to find an existing or grace way to pass the `kube-apiserver`’s configuration options in the REST or default logic.
Copy link
Contributor Author

@HirazawaUi HirazawaUi Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned here, during the POC, I was unable to find a good method to pass the kube-apiserver configuration options to the default or REST logic, so I listed it as an alternative. I'd really appreciate any suggestions on this. If there are any ways I haven’t thought of to pass the kube-apiserver configuration options, I will revise it to be our main solution and list the current solution as an alternative.

Copy link
Contributor Author

@HirazawaUi HirazawaUi Aug 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the cluster-domain as an argument to the ApiServer and generating the actualPodHostname in the REST based on the hostname in the PodSpec, the setHostnameAsFQDN field, and the ApiServer's cluster-domain args, the POC can be found here:

HirazawaUi/kubernetes@a55bc1a

This is one of the options I envisioned. Although it’s not good, I still pushed the code and hope to get more feedback.


## Summary

This proposal allows users to set arbitrary Fully Qualified Domain Name (FQDN) as the hostname of a pod, introduces a new field `actualPodHostname` for the podSpec, which, if set, will always be respected by the Kubelet (otherwise it will fall back to legacy behavior), and no longer cares about the `hostname` as well as the `setHostnameAsFQDN` values.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a new field?

this will make this more complicated than it is today, no?

why is not an alternative to allow to relax the validation of the current pod.spec.hostname field to be able to set a fqdn there?

Copy link
Contributor Author

@HirazawaUi HirazawaUi Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, adding it will make everything more complex, but now we will create DNS records based on the hostname field in podSpec. If we set the FQDN in the hostname, it is undoubtedly a disruption to the existing behavior.
ref: https://github.com/kubernetes/kubernetes/blob/e1aa8197eddd277fb82be0b8bbc2ba2b4ca67af7/pkg/controller/endpoint/endpoints_controller.go#L439-L441

https://github.com/coredns/coredns/blob/a6338e924e29d318e7a1e971b5bde23f36d083af/plugin/kubernetes/kubernetes.go#L463-L497

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is disruptive? are those controllers not copying the field verbatim?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we set the hostname field in the podSpec to an FQDN, such as www.google.com, and also set the subdomain field, we end up with an FQDN hostname that appends the cluster-suffix, resulting in www.google.com.subdomain.default.svc.cluster.local. Additionally, we get a DNS record for www.google.com.subdomain.default.svc.cluster.local. I believe this does not align with our current design patterns, and it also can't meet our current needs.

Of course, we can also state that when the hostname in the podSpec is set to an FQDN, we can ignore the subdomain field. I will add this to the Alternatives section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... or to keep the current hostname and be able to override or omit the default.svc.cluster.local part , right ? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, added.

@HirazawaUi HirazawaUi force-pushed the overwrite-pod-hostname branch 3 times, most recently from 8728dcf to d935541 Compare July 21, 2024 13:35
@HirazawaUi
Copy link
Contributor Author

/cc @thockin

@HirazawaUi HirazawaUi force-pushed the overwrite-pod-hostname branch 2 times, most recently from 9daccf9 to 18d6ffd Compare July 27, 2024 15:49
@HirazawaUi HirazawaUi force-pushed the overwrite-pod-hostname branch 2 times, most recently from 5a59d1f to 12dc314 Compare October 21, 2024 12:54
@HirazawaUi HirazawaUi force-pushed the overwrite-pod-hostname branch from 12dc314 to f2c3e30 Compare October 21, 2024 13:01
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 19, 2025
@HirazawaUi
Copy link
Contributor Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 20, 2025
@HirazawaUi
Copy link
Contributor Author

ping @thockin


This is not a standard Kubernetes use case; it is undoubtedly in conflict with the current pod's potential DNS records, and using it will bring more confusion to users. Moreover, we are not sure how much it can help traditional services that can benefit from being migrated to Kubernetes.

## Alternatives
Copy link
Member

@aojea aojea Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

people can use an init container, no?

apiVersion: v1
kind: Pod
metadata:
  name: myapp-fqdn
  labels:
    app.kubernetes.io/name: MyApp
spec:
  containers:
  - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'echo "Hostname $(hostname) fqdn $(hostname -f)" && sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', "hostname mypod.fqdn.com"]
    securityContext:
      privileged: true
$ kubectl apply -f init-hostname.yaml
pod/myapp-fqdn created
$ kubectl logs pod/myapp-fqdn
Defaulted container "myapp-container" out of: myapp-container, init-myservice (init)

Hostname mypod.fqdn.com fqdn mypod.fqdn.com <----

I think the effort and complexity this introduces is not giving enough benefit , specially if there is an alternative

This is not a standard Kubernetes use case; it is undoubtedly in conflict with the current pod's potential DNS records, and using it will bring more confusion to users. Moreover, we are not sure how much it can help traditional services that can benefit from being migrated to Kubernetes.

## Alternatives

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per #4768 (comment), let's list several alternatives including that one (it's good if each has its own subheading).

Remember that actions like "write documentation for…" are valid alternatives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/network Categorizes an issue or PR as relevant to SIG Network. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants