-
Notifications
You must be signed in to change notification settings - Fork 715
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
Implement a canonical way for getting the node name #1098
Comments
@fabriziopandini I can have look on this, it is OK for you? |
Thanks @MalloZup |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@MalloZup are you still working on this? If not, I would like to give it a try. :) |
@nzoueidi |
what if the user do not use the kubelet component config... |
kubeadm always writes the config file. |
@neolit123 is there any roadmap of this? |
there is this tracking issue: |
I think we need to know the node name at first, then we can amend the copy of kubelet component config with the node name... os, it seems we can not get the node name form kubelet component config, am I right? |
i'd agree. maybe this should be considered the canonical way: |
this func ( https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/util/config/cluster.go#L136 ) is mainly used by https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/util/config/cluster.go#L64 ,and this func will build the https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/cmd/phases/join/kubelet.go#L130 will use value from the os, is there any other way to get the name of node, besides from parsing the content of kubelet.config? |
the sequence of events feels wrong in the existing kubeadm logic. i think the key here is that we need to construct a NodeRegistrationOptions object during upgrades: kubeadm upgrade should not be doing that. |
seems this is used in other cases too, besides kubeadm upgrade: maybe we should store the node name somewhere. then when we need the node name, we get it directly. |
our logic around node name still feels wrong, because if a "configuration" is fetched from the cluster, then this should be the ClusterConfiguration object (not InitConfiguration), which does not include the node name.
one way of doing that would be for kubeadm to write the node name in a file once init / join finishes, but this adds more disk state which is overall undesired. instead of adding something like that i think we should narrow down / enumerate the cases when a node name is actually needed and also long-term make ClusterConfiguration not include ComponentConfigs and InitConfiguration not include ClusterConfiguration. |
Was working with using spire for node attestation for kubelet -> kube-apiserver. Ran into this issue as part of it. doing a kubeadm upgrade plan, it chokes on not being able to find the node name out of the certs in the kubelet kubeconfig, because I'm not using an x509 plugin to authenticate. Would it be possible to make a command line flag to pass the node name in explicitly? |
Or, maybe it could just use the file to grab a token, then use token introspection on it to get the hostname?
|
sorry can you clarify what you mean by "not using an x509 plugin", how is the kubelet authenticating to the apiserver exactly and does it not have a client cert on disk?
adding more flags is not ideal.
as in setting the active KUBECONFIG to the kubelet client like so: and then parsing |
I tweaked /etc/kubernetes/kublet.conf with:
With it setup this way, I have a node attesting with a hardware tpm against a spire server, and able to get valid jwt tokens for kubelet automatically. No join tokens needed. :) Happy to discuss this setup in detail if you want to know more about it. Or may be worth a discussion at Kubecon, for interested parties.
100%
Yeah.
Running it with -v=255 it looks like its calling the rest endpoint:
So, maybe something in https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/authentication/v1 ? |
-v=10 is the maximum level, btw.
seems like it's SelfSubjectReviews(). i guess this can be attempted as the replacement for what kubeadm has now. also, would you be able to help us with a PR for that? |
This seems to work:
|
yes, that seems correct. the problem function is: it seems to be called only here: which is in a code path that already assumes there is a working apiserver as it has an active API client. |
Should we switch it to always do the self subject call, removing the old code, or only do the call if not x509 as a fallback? |
i think given the circumstances (code paths) the function contents can be replaced to use the new way. |
@kfox1111 thinking more about this. the same code might end up being called by kubeadm reset. |
After kubernetes/kubernetes#67944 kubeadm retrives
NodeRegistration
attributes directly from the node.The solution implemented for getting the node name uses the authentication info contained in the
kubelet.conf
file; however in future we want to switch to a more canonical way for doing this e.g. by reading those information from the local copy of the kubelet component config (that should be amended with the node name beforehand 😉)rif code
EDIT: neolit123 another problem here is that the current error is misleading:
we should be more descriptive of what is going on; we are parsing the client cert common name and it must be in the
system:node:foo
format:The text was updated successfully, but these errors were encountered: