Kubernetes: how to write cluster token to a file?

209 Views Asked by At

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 ?

1

There are 1 best solutions below

2
On BEST ANSWER

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.