diff --git a/cmd/minikube/cmd/config/validations.go b/cmd/minikube/cmd/config/validations.go index 4dc42824bde8..7d60a1bee6b4 100644 --- a/cmd/minikube/cmd/config/validations.go +++ b/cmd/minikube/cmd/config/validations.go @@ -149,7 +149,7 @@ minikube stop and then start minikube again with the following flags: -minikube start --container-runtime=containerd --docker-opt containerd=/var/run/containerd/containerd.sock --network-plugin=cni`) +minikube start --container-runtime=containerd --docker-opt containerd=/var/run/containerd/containerd.sock`) } return nil diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index c51fdca7a8ff..a08e50631d22 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -204,6 +204,21 @@ func runStart(cmd *cobra.Command, args []string) { cmdutil.MaybeReportErrorAndExit(err) } + selectedContainerRuntime := viper.GetString(containerRuntime) + selectedNetworkPlugin := viper.GetString(networkPlugin) + selectedEnableDefaultCNI := viper.GetBool(enableDefaultCNI) + + // default network plugin (cni) + r, err := cruntime.New(cruntime.Config{Type: selectedContainerRuntime}) + if err == nil && r.DefaultCNI() { + if !cmd.Flags().Changed(networkPlugin) { + selectedNetworkPlugin = "cni" + if !cmd.Flags().Changed(enableDefaultCNI) { + selectedEnableDefaultCNI = true + } + } + } + selectedKubernetesVersion := viper.GetString(kubernetesVersion) if strings.Compare(selectedKubernetesVersion, "") == 0 { selectedKubernetesVersion = constants.DefaultKubernetesVersion @@ -226,7 +241,6 @@ func runStart(cmd *cobra.Command, args []string) { } } - selectedContainerRuntime := viper.GetString(containerRuntime) kubernetesConfig := cfg.KubernetesConfig{ KubernetesVersion: selectedKubernetesVersion, NodeIP: ip, @@ -239,11 +253,11 @@ func runStart(cmd *cobra.Command, args []string) { FeatureGates: viper.GetString(featureGates), ContainerRuntime: selectedContainerRuntime, CRISocket: viper.GetString(criSocket), - NetworkPlugin: viper.GetString(networkPlugin), + NetworkPlugin: selectedNetworkPlugin, ServiceCIDR: viper.GetString(serviceCIDR), ExtraOptions: extraOptions, ShouldLoadCachedImages: shouldCacheImages, - EnableDefaultCNI: viper.GetBool(enableDefaultCNI), + EnableDefaultCNI: selectedEnableDefaultCNI, } // Write profile cluster configuration to file diff --git a/deploy/addons/gvisor/README.md b/deploy/addons/gvisor/README.md index 1a2a2a735b75..6433189f615a 100644 --- a/deploy/addons/gvisor/README.md +++ b/deploy/addons/gvisor/README.md @@ -7,8 +7,7 @@ When starting minikube, specify the following flags, along with any additional d ```shell $ minikube start --container-runtime=containerd \ - --docker-opt containerd=/var/run/containerd/containerd.sock \ - --network-plugin=cni --enable-default-cni + --docker-opt containerd=/var/run/containerd/containerd.sock ``` ### Enabling gVisor diff --git a/docs/alternative_runtimes.md b/docs/alternative_runtimes.md index d7ecbbd6d183..ce811706fc9e 100644 --- a/docs/alternative_runtimes.md +++ b/docs/alternative_runtimes.md @@ -3,10 +3,7 @@ To use [rkt](https://github.com/coreos/rkt) as the container runtime run: ```shell -$ minikube start \ - --network-plugin=cni \ - --enable-default-cni \ - --container-runtime=rkt +$ minikube start --container-runtime=rkt ``` @@ -15,19 +12,15 @@ $ minikube start \ To use [CRI-O](https://github.com/kubernetes-incubator/cri-o) as the container runtime, run: ```shell -$ minikube start \ - --network-plugin=cni \ - --enable-default-cni \ - --container-runtime=cri-o +$ minikube start --container-runtime=cri-o ``` Or you can use the extended version: ```shell -$ minikube start \ +$ minikube start --container-runtime=cri-o \ --network-plugin=cni \ --enable-default-cni \ - --container-runtime=cri-o \ --cri-socket=/var/run/crio/crio.sock \ --extra-config=kubelet.container-runtime=remote \ --extra-config=kubelet.container-runtime-endpoint=unix:///var/run/crio/crio.sock \ @@ -39,19 +32,15 @@ $ minikube start \ To use [containerd](https://github.com/containerd/containerd) as the container runtime, run: ```shell -$ minikube start \ - --network-plugin=cni \ - --enable-default-cni \ - --container-runtime=containerd +$ minikube start --container-runtime=containerd ``` Or you can use the extended version: ```shell -$ minikube start \ +$ minikube start --container-runtime=containerd \ --network-plugin=cni \ --enable-default-cni \ - --container-runtime=containerd \ --cri-socket=/run/containerd/containerd.sock \ --extra-config=kubelet.container-runtime=remote \ --extra-config=kubelet.container-runtime-endpoint=unix:///run/containerd/containerd.sock \ diff --git a/docs/contributors/minikube_iso.md b/docs/contributors/minikube_iso.md index 6d63491b6850..a4d2fc678240 100644 --- a/docs/contributors/minikube_iso.md +++ b/docs/contributors/minikube_iso.md @@ -39,8 +39,6 @@ The bootable ISO image will be available in `out/minikube.iso`. ```shell $ ./out/minikube start \ --container-runtime=rkt \ - --network-plugin=cni \ - --enable-default-cni \ --iso-url=file://$GOPATH/src/k8s.io/minikube/out/minikube.iso ``` diff --git a/pkg/minikube/cruntime/containerd.go b/pkg/minikube/cruntime/containerd.go index 46c23060a307..8b4e5aadb730 100644 --- a/pkg/minikube/cruntime/containerd.go +++ b/pkg/minikube/cruntime/containerd.go @@ -41,6 +41,11 @@ func (r *Containerd) SocketPath() string { return "/run/containerd/containerd.sock" } +// DefaultCNI returns whether to use CNI networking by default +func (r *Containerd) DefaultCNI() bool { + return true +} + // Active returns if containerd is active on the host func (r *Containerd) Active() bool { err := r.Runner.Run("systemctl is-active --quiet service containerd") diff --git a/pkg/minikube/cruntime/crio.go b/pkg/minikube/cruntime/crio.go index 4d81d6068989..6a2fbcf7d2d9 100644 --- a/pkg/minikube/cruntime/crio.go +++ b/pkg/minikube/cruntime/crio.go @@ -41,6 +41,11 @@ func (r *CRIO) SocketPath() string { return "/var/run/crio/crio.sock" } +// DefaultCNI returns whether to use CNI networking by default +func (r *CRIO) DefaultCNI() bool { + return true +} + // Available returns an error if it is not possible to use this runtime on a host func (r *CRIO) Available() error { return r.Runner.Run("command -v crio") diff --git a/pkg/minikube/cruntime/cruntime.go b/pkg/minikube/cruntime/cruntime.go index 6db7b7a504c6..9f478086164d 100644 --- a/pkg/minikube/cruntime/cruntime.go +++ b/pkg/minikube/cruntime/cruntime.go @@ -49,6 +49,8 @@ type Manager interface { KubeletOptions() map[string]string // SocketPath returns the path to the socket file for a given runtime SocketPath() string + // DefaultCNI returns whether to use CNI networking by default + DefaultCNI() bool // Load an image idempotently into the runtime on a host LoadImage(string) error diff --git a/pkg/minikube/cruntime/docker.go b/pkg/minikube/cruntime/docker.go index fb4f7bf6424a..92f4c0bb5485 100644 --- a/pkg/minikube/cruntime/docker.go +++ b/pkg/minikube/cruntime/docker.go @@ -40,6 +40,11 @@ func (r *Docker) SocketPath() string { return r.Socket } +// DefaultCNI returns whether to use CNI networking by default +func (r *Docker) DefaultCNI() bool { + return false +} + // Available returns an error if it is not possible to use this runtime on a host func (r *Docker) Available() error { _, err := exec.LookPath("docker") diff --git a/test/integration/util/util.go b/test/integration/util/util.go index 66a24be154ad..27456bd8b759 100644 --- a/test/integration/util/util.go +++ b/test/integration/util/util.go @@ -207,9 +207,9 @@ func (m *MinikubeRunner) Start() { // TODO(tstromberg): Deprecate this in favor of making it possible for tests to define explicit flags. switch r := m.Runtime; r { case "containerd": - opts = "--container-runtime=containerd --network-plugin=cni --enable-default-cni --docker-opt containerd=/var/run/containerd/containerd.sock" + opts = "--container-runtime=containerd --docker-opt containerd=/var/run/containerd/containerd.sock" case "crio": - opts = "--container-runtime=crio --network-plugin=cni --enable-default-cni" + opts = "--container-runtime=crio" } m.RunCommand(fmt.Sprintf("start %s %s %s --alsologtostderr --v=5", m.StartArgs, m.Args, opts), true)