diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index cf77ba95c5..250b5d7dd1 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -554,6 +554,9 @@ func (k *Bootstrapper) restartControlPlane(cfg config.ClusterConfig) error { return nil } + if err := k.stopKubeSystem(cfg); err != nil { + glog.Warningf("Failed to stop kube-system containers: port conflicts may arise: %v", err) + } if err := k.clearStaleConfigs(cfg); err != nil { return errors.Wrap(err, "clearing stale configs") } @@ -905,6 +908,27 @@ func (k *Bootstrapper) elevateKubeSystemPrivileges(cfg config.ClusterConfig) err return nil } +// stopKubeSystem stops all the containers in the kube-system to prevent #8740 when doing hot upgrade +func (k *Bootstrapper) stopKubeSystem(cfg config.ClusterConfig) error { + glog.Info("stopping kube-system containers ...") + cr, err := cruntime.New(cruntime.Config{Type: cfg.KubernetesConfig.ContainerRuntime, Runner: k.c}) + if err != nil { + return errors.Wrap(err, "new cruntime") + } + + ids, err := cr.ListContainers(cruntime.ListOptions{Namespaces: []string{"kube-system"}}) + if err != nil { + return errors.Wrap(err, "list") + } + + if len(ids) > 0 { + if err := cr.StopContainers(ids); err != nil { + return errors.Wrap(err, "stop") + } + } + return nil +} + // adviseNodePressure will advise the user what to do with difference pressure errors based on their environment func adviseNodePressure(err error, name string, drv string) { if diskErr, ok := err.(*kverify.ErrDiskPressure); ok {