From 19ae2de19cb285e6fefab5c275dab86cd1ef0587 Mon Sep 17 00:00:00 2001 From: Etienne Champetier Date: Fri, 12 May 2023 14:42:35 -0400 Subject: [PATCH] kubeadm: speedup init by 0s or 20s Before this commit, kubeadm starts kubelet before it creates /etc/kubernetes/manifests. On boot, kubelet tries to load the static pod manifests from this dir by calling `listConfig()` https://github.com/kubernetes/kubernetes/blob/7ad8303b9602252b18932d34377cd2793595d537/pkg/kubelet/config/file.go#L97 and it'll then try to start a file watcher every second for 20s https://github.com/kubernetes/kubernetes/blob/7ad8303b9602252b18932d34377cd2793595d537/pkg/kubelet/config/file.go#L114 https://github.com/kubernetes/kubernetes/blob/7ad8303b9602252b18932d34377cd2793595d537/pkg/kubelet/config/file_linux.go#L51-L67 If kubelet starts and calls `listConfig()` before kubeadm creates `/etc/kubernetes/manifests` (while writing the static pods manifests), the file watcher will be created less than a second after, but there will be no changes to report, so the manifests will only be detected on the next tick of `listTicker`, a bit less than 20s later https://github.com/kubernetes/kubernetes/blob/7ad8303b9602252b18932d34377cd2793595d537/pkg/kubelet/config/file.go#L102-L103 Even if we fixed the watch code to `listConfig()` just after starting the inotify watch, watching source file is only supported on linux, so moving the manifests generation before kubelet start fixes all cases and make more sense IMO. Signed-off-by: Etienne Champetier --- cmd/kubeadm/app/cmd/init.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/kubeadm/app/cmd/init.go b/cmd/kubeadm/app/cmd/init.go index 2fc2b3cfcbc..06f64a91565 100644 --- a/cmd/kubeadm/app/cmd/init.go +++ b/cmd/kubeadm/app/cmd/init.go @@ -134,9 +134,9 @@ func newCmdInit(out io.Writer, initOptions *initOptions) *cobra.Command { initRunner.AppendPhase(phases.NewPreflightPhase()) initRunner.AppendPhase(phases.NewCertsPhase()) initRunner.AppendPhase(phases.NewKubeConfigPhase()) - initRunner.AppendPhase(phases.NewKubeletStartPhase()) - initRunner.AppendPhase(phases.NewControlPlanePhase()) initRunner.AppendPhase(phases.NewEtcdPhase()) + initRunner.AppendPhase(phases.NewControlPlanePhase()) + initRunner.AppendPhase(phases.NewKubeletStartPhase()) initRunner.AppendPhase(phases.NewWaitControlPlanePhase()) initRunner.AppendPhase(phases.NewUploadConfigPhase()) initRunner.AppendPhase(phases.NewUploadCertsPhase())