Kubernetes: how to write cluster token to a file?

5/4/2021

I use the following command to create cluster token :

kubeadm token create --ttl=0

This will show the following output:

W0504 18:31:48.031557 20703 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups kubelet.config.k8s.io kubeproxy.config.k8s.io

Now after using kubeadm token list commnad, I want to copy the token to a file.

How to do so ?

-- McLan
kubeadm
kubernetes
token

1 Answer

5/4/2021

The output of the token list can be formatted with jsonpath:

kubeadm token list -o=jsonpath='{.token}{"\n"}' > tokens.txt

By using this format only the token is printed by the list command.

-- csenga
Source: StackOverflow