From 03176dd3751eb257f02e06bb8a27052611a5e405 Mon Sep 17 00:00:00 2001 From: Ling Samuel Date: Thu, 24 Dec 2020 10:48:27 +0800 Subject: [PATCH] Add --control-planes to `start` Signed-off-by: Ling Samuel --- cmd/minikube/cmd/node_add.go | 3 +-- cmd/minikube/cmd/start.go | 12 ++++++++++++ cmd/minikube/cmd/start_flags.go | 2 ++ site/content/en/docs/commands/start.md | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/node_add.go b/cmd/minikube/cmd/node_add.go index 768c001dcd88..b90a41ddcf58 100644 --- a/cmd/minikube/cmd/node_add.go +++ b/cmd/minikube/cmd/node_add.go @@ -21,7 +21,6 @@ import ( "github.com/spf13/viper" "k8s.io/minikube/pkg/minikube/cni" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/mustload" @@ -68,7 +67,7 @@ var nodeAddCmd = &cobra.Command{ } if n.ControlPlane { - n.Port = constants.APIServerPort + n.Port = cc.KubernetesConfig.NodePort } // Make sure to decrease the default amount of memory we use per VM if this is the first worker node diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 28b4ba18f7e5..1de81882f31c 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -131,6 +131,13 @@ func platform() string { func runStart(cmd *cobra.Command, args []string) { register.SetEventLogPath(localpath.EventLog(ClusterFlagValue())) + controlPlanesNum := viper.GetInt(controlPlanes) + nodesNum := viper.GetInt(nodes) + if controlPlanesNum > nodesNum { + out.WarningT(fmt.Sprintf("control planes number %v larger than nodes number %v, enlarge nodes to %v.", controlPlanesNum, nodesNum, controlPlanesNum)) + viper.Set(nodes, controlPlanesNum) + } + out.SetJSON(outputFormat == "json") if err := pkgtrace.Initialize(viper.GetString(trace)); err != nil { exit.Message(reason.Usage, "error initializing tracing: {{.Error}}", out.V{"Error": err.Error()}) @@ -359,6 +366,7 @@ func startWithDriver(cmd *cobra.Command, starter node.Starter, existing *config. } } + numControlPlanes := viper.GetInt(controlPlanes) numNodes := viper.GetInt(nodes) if existing != nil { if numNodes > 1 { @@ -381,6 +389,10 @@ func startWithDriver(cmd *cobra.Command, starter node.Starter, existing *config. PrimaryControlPlane: false, KubernetesVersion: starter.Cfg.KubernetesConfig.KubernetesVersion, } + if i < numControlPlanes { + n.ControlPlane = true + n.Port = starter.Cfg.KubernetesConfig.NodePort + } out.Ln("") // extra newline for clarity on the command line err := node.Add(starter.Cfg, n, viper.GetBool(deleteOnFailure)) if err != nil { diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 311d75dc031c..0403e7f558b1 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -102,6 +102,7 @@ const ( hostOnlyNicType = "host-only-nic-type" natNicType = "nat-nic-type" nodes = "nodes" + controlPlanes = "control-planes" preload = "preload" deleteOnFailure = "delete-on-failure" forceSystemd = "force-systemd" @@ -150,6 +151,7 @@ func initMinikubeFlags() { startCmd.Flags().Bool(autoUpdate, true, "If set, automatically updates drivers to the latest version. Defaults to true.") startCmd.Flags().Bool(installAddons, true, "If set, install addons. Defaults to true.") startCmd.Flags().IntP(nodes, "n", 1, "The number of nodes to spin up. Defaults to 1.") + startCmd.Flags().Int(controlPlanes, 1, "The number of control planes to spin up. Defaults to 1.") startCmd.Flags().Bool(preload, true, "If set, download tarball of preloaded images if available to improve start time. Defaults to true.") startCmd.Flags().Bool(deleteOnFailure, false, "If set, delete the current cluster if start fails and try again. Defaults to false.") startCmd.Flags().Bool(forceSystemd, false, "If set, force the container runtime to use sytemd as cgroup manager. Currently available for docker and crio. Defaults to false.") diff --git a/site/content/en/docs/commands/start.md b/site/content/en/docs/commands/start.md index 7de128c60330..c635d140927b 100644 --- a/site/content/en/docs/commands/start.md +++ b/site/content/en/docs/commands/start.md @@ -30,6 +30,7 @@ minikube start [flags] --cache-images If true, cache docker images for the current bootstrapper and load them into the machine. Always false with --driver=none. (default true) --cni string CNI plug-in to use. Valid options: auto, bridge, calico, cilium, flannel, kindnet, or path to a CNI manifest (default: auto) --container-runtime string The container runtime to be used (docker, cri-o, containerd). (default "docker") + --control-planes int The number of control planes to spin up. Defaults to 1. (default 1) --cpus int Number of CPUs allocated to Kubernetes. (default 2) --cri-socket string The cri socket path to be used. --delete-on-failure If set, delete the current cluster if start fails and try again. Defaults to false.