@@ -290,6 +290,10 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error {
290290 }()
291291
292292 wg .Wait ()
293+ // Tunnel apiserver to guest, if necessary
294+ if cfg .APIServerPort != 0 {
295+ k .tunnelToAPIServer (cfg )
296+ }
293297 return nil
294298}
295299
@@ -399,6 +403,10 @@ func (k *Bootstrapper) StartCluster(cfg config.ClusterConfig) error {
399403 }
400404
401405 if err := bsutil .ExistingConfig (k .c ); err == nil {
406+ // If the guest already exists and was stopped, re-establish the apiserver tunnel so checks pass
407+ if cfg .APIServerPort != 0 {
408+ k .tunnelToAPIServer (cfg )
409+ }
402410 klog .Infof ("found existing configuration files, will attempt cluster restart" )
403411 rerr := k .restartControlPlane (cfg )
404412 if rerr == nil {
@@ -433,6 +441,22 @@ func (k *Bootstrapper) StartCluster(cfg config.ClusterConfig) error {
433441 return err
434442}
435443
444+ func (k * Bootstrapper ) tunnelToAPIServer (cfg config.ClusterConfig ) {
445+ m , err := machine .NewAPIClient ()
446+ if err != nil {
447+ klog .Warningf ("libmachine API failed: %v" , err )
448+ }
449+ cp , err := config .PrimaryControlPlane (& cfg )
450+ if err != nil {
451+ klog .Warningf ("finding control plane failed: %v" , err )
452+ }
453+ args := []string {"-f" , "-NTL" , fmt .Sprintf ("%d:localhost:8443" , cfg .APIServerPort )}
454+ err = machine .CreateSSHShell (m , cfg , cp , args , false )
455+ if err != nil {
456+ klog .Warningf ("apiserver tunnel failed: %v" , err )
457+ }
458+ }
459+
436460// client sets and returns a Kubernetes client to use to speak to a kubeadm launched apiserver
437461func (k * Bootstrapper ) client (ip string , port int ) (* kubernetes.Clientset , error ) {
438462 if k .k8sClient != nil {
@@ -569,6 +593,7 @@ func (k *Bootstrapper) needsReconfigure(conf string, hostname string, port int,
569593 klog .Infof ("needs reconfigure: configs differ:\n %s" , rr .Output ())
570594 return true
571595 }
596+
572597 // cruntime.Enable() may restart kube-apiserver but does not wait for it to return back
573598 apiStatusTimeout := 3000 * time .Millisecond
574599 st , err := kverify .WaitForAPIServerStatus (k .c , apiStatusTimeout , hostname , port )
0 commit comments