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

Better usability for the join token #519

Closed
synergiator opened this issue Nov 4, 2017 · 22 comments · Fixed by kubernetes/kubernetes#56185
Closed

Better usability for the join token #519

synergiator opened this issue Nov 4, 2017 · 22 comments · Fixed by kubernetes/kubernetes#56185
Assignees
Labels
area/UX priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.
Milestone

Comments

@synergiator
Copy link

/kind feature
@kubernetes/sig-cli
What happened:
I have discovered that if it is not so easy to add new machines if you do not have original joun string output from kubeadm. "Is there a way to generate the whole join command? I feel like I have to reset the entire cluster to be able to "reach" the magic string" (c) @alexellis

What you expected to happen:
Likewise in Docker Swarm, you can always tell the master to print a copy-pastable join string to add.. or assimilate? more machines.

Example input:

kubeadm token string

Example output:

kubeadm join --token TOK MASTER_IP:6443 --discovery-token-ca-cert-hash sha256:HASH

Anything else we need to know?:
You are awesome!

(Follow-up from: kubernetes/kubernetes#41663)
@luxas @mattmoyer @jamiehannaford

@mattmoyer
Copy link

+1 on something like this.

Some riffs on this idea:

  • A new kubeadm ca-cert-hash command (name TBD) that just prints out the current CA hash. This would basically be the same thing as the openssl command we give in the kubeadm join docs.

  • Add a --print-join-command flag for kubeadm token create that prints out the whole join command just like kubeadm init does. This would hopefully make it easy to automate around by running something like kubeadm token create --print-join-command >> worker_init.sh during provisioning.

  • A new command kubeadm token get <token id> that gets the full token given the ID, with a --print-join-command flag to optionally print the full join command instead of just the token.

@alexellis
Copy link

Thanks for tagging me in this. Take a note from the UX of Docker Swarm - at any point you can type in docker swarm join-token worker and have a command to paste into a worker or to send over SSH. With Kubeadm it's so hard I literally tear down the cluster to add add a new node - I'm pretty confident with CLIs so I'm sure I'm not the only one.

@cpuguy83
Copy link

cpuguy83 commented Nov 8, 2017

Also the init output is so heavy you can't really get just the join command and stash it somewhere... currently I'm resorting to kubeadm init ... | grep 'kubeadm join --token' > /some_file.
Would be cool to have a quiet mode where the only thing on stdout is the join command.

@zcalusic
Copy link

zcalusic commented Nov 9, 2017

Anyway, what is the way to get that ca-cert-hash right now? Of course, the kubeadm init output is long gone at this point... and I didn't save it expecting it would be easy to extract that info later, on demand.

I managed to get join token with kubeadm token list and joined another node with kubeadm join --token, but it is saying:

[validation] WARNING: using token-based discovery without DiscoveryTokenCACertHashes can be unsafe (see https://kubernetes.io/docs/admin/kubeadm/#kubeadm-join).
[validation] WARNING: Pass --discovery-token-unsafe-skip-ca-verification to disable this warning. This warning will become an error in Kubernetes 1.9.

So, before it becomes error, how do I pass that parameter? Thanks for any help!

@mattmoyer
Copy link

@zcalusic the current way is to calculate the hash with OpenSSL like this (run on the master or wherever you have a copy of /etc/kubernetes/pki/ca.crt):

openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'

@zcalusic
Copy link

zcalusic commented Nov 9, 2017

Thank you @mattmoyer for the hint. Your oneliner worked perfectly.

Of course, I must agree that --print-join-command would be much better user experience.

@wackxu
Copy link
Contributor

wackxu commented Nov 10, 2017

Agree with --print-join-command

@luxas
Copy link
Member

luxas commented Nov 14, 2017

We concluded in the SIG meeting that we're gonna proceed with both kubernetes/kubernetes#55468 and this feature addition.
We'll see in what form exactly in a bit

@luxas luxas added this to the v1.9 milestone Nov 14, 2017
@luxas luxas added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Nov 14, 2017
@luxas luxas assigned mattmoyer and xiangpengzhao and unassigned mattmoyer Nov 14, 2017
@vielmetti
Copy link

This was discussed on the November 21, 2017 zoom call; minutes for that call are at https://docs.google.com/document/d/1deJYPIF4LmhGjDVaqrswErIrV7mtwJgovtLnPCDxP7U/edit#

@xiangpengzhao
Copy link

xiangpengzhao commented Nov 21, 2017

I just had a quick look on this yesterday but haven't worked on it yet :)

Add a --print-join-command flag for kubeadm token create that prints out the whole join command just like kubeadm init does. This would hopefully make it easy to automate around by running something like kubeadm token create --print-join-command >> worker_init.sh during provisioning.

If we prefer this one, I think there is already the same logic in bootstrap token create. We can use that here.

A new command kubeadm token get that gets the full token given the ID, with a --print-join-command flag to optionally print the full join command instead of just the token.

I prefer this one personally. But seems like both the two ideas need more context when implementing, e.g., we need MasterConfiguration to get apiserver advertise address. Currently the token create don't have the config.

UPDATE: maybe we can implement both of the ideas? @luxas @mattmoyer

@mattmoyer
Copy link

I implemented just the first idea in kubernetes/kubernetes#56185. I'm not opposed to implementing the kubeadm get idea also, but we're short on time.

@fabriziopandini
Copy link
Member

fabriziopandini commented Nov 22, 2017

Instead of creating a new kubeadm get, IMO we should print the hash/the kubeadm join statement at the end of the already existing kubeadm token list.

@luxas
Copy link
Member

luxas commented Nov 22, 2017

I think kubeadm token list --print-join-command would be great!

@alexellis
Copy link

alexellis commented Nov 22, 2017

I like that idea @luxas. I think we could make it less verbose, I find I'm typing very long flags kubeadm compared to the docker CLI.

kubeadm token list --verbose

kubeadm token list --tokens

kubeadm token list --join-token

@luxas
Copy link
Member

luxas commented Nov 22, 2017

kubeadm token list --verbose|-v works for me as well

k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this issue Nov 23, 2017
Automatic merge from submit-queue (batch tested with PRs 55545, 55548, 55815, 56136, 56185). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

kubeadm: add `--print-join-command` flag for token create.

**What this PR does / why we need it**: This change adds a new flag `kubeadm token create --print-join-command`. When this flag is passed, kubeadm prints the full `kubeadm join [...]` command, including the CA certificate hash which is otherwise annoying to calculate.

**Which issue(s) this PR fixes** fixes kubernetes/kubeadm#519

**Special notes for your reviewer**:

### Example Output
```
$ kubeadm token create --print-join-command
kubeadm join --token 447067.20b55955bd6abe6c 192.168.99.100:8443 --discovery-token-ca-cert-hash sha256:17023a5c90b996e50c514e63e161e46f78be216fd48c0c3df3be67e008b28889
$ kubeadm token create -h
[...]
      --print-join-command   Instead of printing only the token, print the full 'kubeadm join' flag needed to join the cluster using the token.
[...]
```

I ended up not using the approach suggested by @xiangpengzhao in #56025 (and also by @fabriziopandini) of reusing the `bootstrap-token` phase code, since that code assumes it can load the CA certificates from `/etc/kubernetes`, but that is only true if kubeadm is run on an already-joined node.

Instead, I wrote code to pull the CA certificates and server endpoint from the kubeconfig that `kubeadm token create` is called with, since that also contains the data and is available even if, e.g., kubeadm is being run from outside the cluster.

**Release note**:
```release-note
kubeadm: added `--print-join-command` flag for `kubeadm token create`.
```

/sig cluster-lifecycle

/cc @fabriziopandini @xiangpengzhao @luxas
@tzurE
Copy link

tzurE commented Dec 11, 2017

Hey, is this done?
How can I get the token to join new nodes in my cluster?

@mattmoyer
Copy link

@tzurE it's merged but not released yet, it will be part of Kubernetes 1.9 which is scheduled to be released later this week.

The new functionality allows you to run this command to join nodes:

# on a master node (or any node with admin access to your cluster)
$ kubeadm token create --print-join-command
kubeadm join --token 447067.20b55955bd6abe6c 192.168.99.100:8443 --discovery-token-ca-cert-hash sha256:17023a5c90b996e50c514e63e161e46f78be216fd48c0c3df3be67e008b28889
# on the new node (copy-pasted from the output above)
$ kubeadm join --token 447067.20b55955bd6abe6c 192.168.99.100:8443 --discovery-token-ca-cert-hash sha256:17023a5c90b996e50c514e63e161e46f78be216fd48c0c3df3be67e008b28889

@tzurE
Copy link

tzurE commented Dec 11, 2017

nice, thank you.
is there a solution in the meantime? A way to extract it not using the regular commands?

@mattmoyer
Copy link

@tzurE see this comment: #519 (comment)

@siddharthjoshi745
Copy link

Hi @mattmoyer

The command "kubeadm token create --print-join-command" works great in 1.9. But i am getting NotReady status on my node. I am Using ubuntu 16.04 with k8s 1.9.0. Any suggestions?

@luxas
Copy link
Member

luxas commented Dec 22, 2017

@siddharthjoshi745 Deploy a Pod Network like Weave Net (as can be seen in our docs).
Please don't comment on old issues though, instead open a new one if you've found something wrong, or ask for help on Slack
Have a great day!

@stephaneeybert
Copy link

stephaneeybert commented Dec 7, 2018

How can we output just one value ? Say the token or the discovery token sha, etc..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/UX priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.