Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CNI for alternative runtimes #3617

Merged
merged 8 commits into from
Feb 11, 2019
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 17 additions & 3 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -226,7 +241,6 @@ func runStart(cmd *cobra.Command, args []string) {
}
}

selectedContainerRuntime := viper.GetString(containerRuntime)
kubernetesConfig := cfg.KubernetesConfig{
KubernetesVersion: selectedKubernetesVersion,
NodeIP: ip,
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions deploy/addons/gvisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 5 additions & 16 deletions docs/alternative_runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand All @@ -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
afbjorklund marked this conversation as resolved.
Show resolved Hide resolved
```

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 \
Expand All @@ -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 \
Expand Down
2 changes: 0 additions & 2 deletions docs/contributors/minikube_iso.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
5 changes: 5 additions & 0 deletions pkg/minikube/cruntime/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions pkg/minikube/cruntime/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/cruntime/cruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/minikube/cruntime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions test/integration/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down