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

Improve kubeadm init message #42970

Merged
merged 1 commit into from Mar 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 23 additions & 9 deletions cmd/kubeadm/app/cmd/init.go
Expand Up @@ -21,6 +21,8 @@ import (
"io"
"io/ioutil"
"path"
"strconv"
"text/template"

"github.com/renstrom/dedent"
"github.com/spf13/cobra"
Expand All @@ -42,20 +44,25 @@ import (
)

var (
initDoneMsgf = dedent.Dedent(`
initDoneTempl = template.Must(template.New("init").Parse(dedent.Dedent(`
Your Kubernetes master has initialized successfully!

To start using your cluster, you need to run:
export KUBECONFIG=%s
To start using your cluster, you need to run (as a regular user):

sudo cp {{.KubeConfigPath}} $HOME/
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is much clearer and a step in the correct direction of making docs for kubeadm better. My only comment is about making kubeadm as OS-agnostic as much as possible (kubernetes/kubeadm#108). Obviously, kubeadm is not supported for windows or macOS yet. Maybe writing in plain English what you are doing (in these commands) and saying something like:
"For example, run these commands on your linux machine."

Just an idea.

sudo chmod $(id -u):$(id -g) $HOME/{{.KubeConfigName}}
export KUBECONFIG=$HOME/{{.KubeConfigName}}

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
http://kubernetes.io/docs/admin/addons/
http://kubernetes.io/docs/admin/addons/

You can now join any number of machines by running the following on each node
as root:

You can now join any number of machines by running the following on each node:
kubeadm join --token {{.Token}} {{.MasterIP}}:{{.MasterPort}}

kubeadm join --token %s %s:%d
`)
`)))
)

// NewCmdInit returns "kubeadm init" command.
Expand Down Expand Up @@ -256,6 +263,13 @@ func (i *Init) Run(out io.Writer) error {
return err
}

fmt.Fprintf(out, initDoneMsgf, path.Join(kubeadmapi.GlobalEnvParams.KubernetesDir, kubeadmconstants.AdminKubeConfigFileName), i.cfg.Token, i.cfg.API.AdvertiseAddress, i.cfg.API.BindPort)
return nil
ctx := map[string]string{
Copy link
Member

Choose a reason for hiding this comment

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

Cool, I didn't know you could pass map[string]string to Golang templates, thought one could only use structs to get that neat behavior.

"KubeConfigPath": path.Join(kubeadmapi.GlobalEnvParams.KubernetesDir, kubeadmconstants.AdminKubeConfigFileName),
"KubeConfigName": kubeadmconstants.AdminKubeConfigFileName,
"Token": i.cfg.Token,
"MasterIP": i.cfg.API.AdvertiseAddress,
"MasterPort": strconv.Itoa(int(i.cfg.API.BindPort)),
}

return initDoneTempl.Execute(out, ctx)
}