From ee9004f93b78083f07f1ea35b88cfaaabf1794fa Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Sat, 2 May 2020 17:02:19 -0700 Subject: [PATCH 1/9] add os type to DaemonInfo --- pkg/drivers/kic/oci/info.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/drivers/kic/oci/info.go b/pkg/drivers/kic/oci/info.go index 4fe381ede52b..cc3fbfd2f5f9 100644 --- a/pkg/drivers/kic/oci/info.go +++ b/pkg/drivers/kic/oci/info.go @@ -27,8 +27,9 @@ import ( // SysInfo Info represents common system Information between docker and podman that minikube cares type SysInfo struct { - CPUs int // CPUs is Number of CPUs - TotalMemory int64 // TotalMemory Total available ram + CPUs int // CPUs is Number of CPUs + TotalMemory int64 // TotalMemory Total available ram + OSType string // container's OsType (windows or linux) } // DaemonInfo returns common docker/podman daemon system info that minikube cares about @@ -38,11 +39,13 @@ func DaemonInfo(ociBin string) (SysInfo, error) { p, err := podmanSystemInfo() info.CPUs = p.Host.Cpus info.TotalMemory = p.Host.MemTotal + info.OSType = p.Host.Os return info, err } d, err := dockerSystemInfo() info.CPUs = d.NCPU info.TotalMemory = d.MemTotal + info.OSType = d.OSType return info, err } From 4572d0634f1f36c47a5cf5110a1425ed0da06314 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Sat, 2 May 2020 18:29:33 -0700 Subject: [PATCH 2/9] exit with usage if container type is windows --- cmd/minikube/cmd/start.go | 9 +++++++++ pkg/drivers/kic/oci/errors.go | 21 +++++++++++++++++++++ pkg/drivers/kic/oci/oci.go | 11 +++++++++++ pkg/minikube/node/start.go | 9 ++++++++- 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 pkg/drivers/kic/oci/errors.go diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 3ac60648c46e..9cbc356b46c5 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -156,6 +156,15 @@ func runStart(cmd *cobra.Command, args []string) { ds, alts, specified := selectDriver(existing) starter, err := provisionWithDriver(cmd, ds, existing) if err != nil { + if errors.Is(err, oci.ErrWindowsContainers) { + out.ErrLn("") + out.ErrT(out.Conflict, "Your Docker Desktop container os type is Windows but Linux is required.") + out.T(out.Warning, "Please change Docker settings to use Linux containers instead of Windows containers.") + out.T(out.Documentation, "https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers") + exit.UsageT(`You can verify your Docker container type by running: + {{.command}} + `, out.V{"command": "docker info --format '{{.OSType}}'"}) + } if specified { // If the user specified a driver, don't fallback to anything else exit.WithError("error provisioning host", err) diff --git a/pkg/drivers/kic/oci/errors.go b/pkg/drivers/kic/oci/errors.go new file mode 100644 index 000000000000..4e3cc7a5a495 --- /dev/null +++ b/pkg/drivers/kic/oci/errors.go @@ -0,0 +1,21 @@ +/* +Copyright 2020 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package oci + +import "errors" + +var ErrWindowsContainers = errors.New("Docker daemon's container type is windows") \ No newline at end of file diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index 9e633b9a8eff..059fea949176 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -104,6 +104,17 @@ func PrepareContainerNode(p CreateParams) error { // CreateContainerNode creates a new container node func CreateContainerNode(p CreateParams) error { + // on windows os, if docker desktop is using Windows Containers. Exit early with error + if p.OCIBinary == Docker && runtime.GOOS == "windows" { + info, err := DaemonInfo(p.OCIBinary) + if info.OSType == "windows" { + return ErrWindowsContainers + } + if err != nil { + return err + } + } + runArgs := []string{ "-d", // run the container detached "-t", // allocate a tty for entrypoint logs diff --git a/pkg/minikube/node/start.go b/pkg/minikube/node/start.go index d4c8a1e7f77e..6d5cea56aed5 100644 --- a/pkg/minikube/node/start.go +++ b/pkg/minikube/node/start.go @@ -36,6 +36,7 @@ import ( "golang.org/x/sync/errgroup" cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config" "k8s.io/minikube/pkg/addons" + "k8s.io/minikube/pkg/drivers/kic/oci" "k8s.io/minikube/pkg/minikube/bootstrapper" "k8s.io/minikube/pkg/minikube/bootstrapper/images" "k8s.io/minikube/pkg/minikube/cluster" @@ -356,7 +357,6 @@ func startHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*hos if err == nil { return host, exists, nil } - out.ErrT(out.Embarrassed, "StartHost failed, but will try again: {{.error}}", out.V{"error": err}) // NOTE: People get very cranky if you delete their prexisting VM. Only delete new ones. if !exists { @@ -366,6 +366,13 @@ func startHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*hos } } + // don't try to re-create if container type is windows. + if errors.Is(err, oci.ErrWindowsContainers) { + glog.Infof("will skip retrying to create machine because error is not retriable: %v", err) + return host, exists, err + } + + out.ErrT(out.Embarrassed, "StartHost failed, but will try again: {{.error}}", out.V{"error": err}) // Try again, but just once to avoid making the logs overly confusing time.Sleep(5 * time.Second) From 2102a206052405eb834fe14860ab2f10e747fe27 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Sat, 2 May 2020 18:38:23 -0700 Subject: [PATCH 3/9] wrap errors --- pkg/drivers/kic/oci/errors.go | 2 +- pkg/drivers/kic/oci/oci.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/drivers/kic/oci/errors.go b/pkg/drivers/kic/oci/errors.go index 4e3cc7a5a495..8b5185abe0e3 100644 --- a/pkg/drivers/kic/oci/errors.go +++ b/pkg/drivers/kic/oci/errors.go @@ -18,4 +18,4 @@ package oci import "errors" -var ErrWindowsContainers = errors.New("Docker daemon's container type is windows") \ No newline at end of file +var ErrWindowsContainers = errors.New("Docker daemon's container type is windows") diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index 059fea949176..48ed892b33e0 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -111,7 +111,8 @@ func CreateContainerNode(p CreateParams) error { return ErrWindowsContainers } if err != nil { - return err + glog.Warningf("error getting dameon info: %v", err) + return errors.Wrap(err, "daemon info") } } From bcecda8e20841f2c881f8624b556d267d8bed101 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Sat, 2 May 2020 18:48:52 -0700 Subject: [PATCH 4/9] add comment for error type --- pkg/drivers/kic/oci/errors.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/drivers/kic/oci/errors.go b/pkg/drivers/kic/oci/errors.go index 8b5185abe0e3..a056f11e68da 100644 --- a/pkg/drivers/kic/oci/errors.go +++ b/pkg/drivers/kic/oci/errors.go @@ -18,4 +18,5 @@ package oci import "errors" -var ErrWindowsContainers = errors.New("Docker daemon's container type is windows") +// ErrWindowsContainers is thrown when docker been configured to run windows containers instead of Linux +var ErrWindowsContainers = errors.New("docker container type is windows") From 7cf9da3d726a9b6298a325986148660dfe65db0c Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Sat, 2 May 2020 19:57:19 -0700 Subject: [PATCH 5/9] add docs about container type --- site/content/en/docs/drivers/docker.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/site/content/en/docs/drivers/docker.md b/site/content/en/docs/drivers/docker.md index ad5949d0ceaf..f6105aa5904d 100644 --- a/site/content/en/docs/drivers/docker.md +++ b/site/content/en/docs/drivers/docker.md @@ -34,7 +34,14 @@ The Docker driver allows you to install Kubernetes into an existing Docker insta - Run `--alsologtostderr -v=1` for extra debugging information +- On Windows, make sure you Docker's container type is Linux and not windows. see docker docs on [switching container type](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers). +You can verify your Docker container type by running: +```shell + docker info --format '{{.OSType}}' +``` + - On Linux, if you want to run MySQL pod, you need to disable AppArmor for mysql profile If your docker has [AppArmor](https://wiki.ubuntu.com/AppArmor) enabled, running mysql in privileged mode with docker driver will have the issue [#7401](https://github.com/kubernetes/minikube/issues/7401). There is a workaround - see [moby/moby#7512](https://github.com/moby/moby/issues/7512#issuecomment-61787845). + From e5c8592fddd0ad80d09b485d92f4676b83cc3337 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Sat, 2 May 2020 19:58:19 -0700 Subject: [PATCH 6/9] spell docs --- site/content/en/docs/drivers/docker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/en/docs/drivers/docker.md b/site/content/en/docs/drivers/docker.md index f6105aa5904d..c3a809288a03 100644 --- a/site/content/en/docs/drivers/docker.md +++ b/site/content/en/docs/drivers/docker.md @@ -34,7 +34,7 @@ The Docker driver allows you to install Kubernetes into an existing Docker insta - Run `--alsologtostderr -v=1` for extra debugging information -- On Windows, make sure you Docker's container type is Linux and not windows. see docker docs on [switching container type](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers). +- On Windows, make sure Docker Desktop's container type setting is Linux and not windows. see docker docs on [switching container type](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers). You can verify your Docker container type by running: ```shell docker info --format '{{.OSType}}' From d88725915362c4cc3a5bae528b2d06df27cdb75c Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Sat, 2 May 2020 20:19:17 -0700 Subject: [PATCH 7/9] add to registry --- cmd/minikube/cmd/start.go | 2 +- pkg/minikube/registry/drvs/docker/docker.go | 6 +++++- site/content/en/docs/drivers/docker.md | 16 +++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 9cbc356b46c5..428784de23f3 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -160,7 +160,7 @@ func runStart(cmd *cobra.Command, args []string) { out.ErrLn("") out.ErrT(out.Conflict, "Your Docker Desktop container os type is Windows but Linux is required.") out.T(out.Warning, "Please change Docker settings to use Linux containers instead of Windows containers.") - out.T(out.Documentation, "https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers") + out.T(out.Documentation, "https://minikube.sigs.k8s.io/docs/drivers/docker/#verify-docker-container-type-is-linux") exit.UsageT(`You can verify your Docker container type by running: {{.command}} `, out.V{"command": "docker info --format '{{.OSType}}'"}) diff --git a/pkg/minikube/registry/drvs/docker/docker.go b/pkg/minikube/registry/drvs/docker/docker.go index 6f47a34a1dfb..bad19f3fba3e 100644 --- a/pkg/minikube/registry/drvs/docker/docker.go +++ b/pkg/minikube/registry/drvs/docker/docker.go @@ -81,9 +81,13 @@ func status() registry.State { defer cancel() // Quickly returns an error code if server is not running - cmd := exec.CommandContext(ctx, oci.Docker, "version", "--format", "{{.Server.Version}}") + cmd := exec.CommandContext(ctx, oci.Docker, "version", "--format", "{{.Server.Os}}-{{.Server.Version}}") o, err := cmd.Output() output := string(o) + if !strings.Contains(output,"windows-") { + return registry.State{Error: oci.ErrWindowsContainers, Installed: true, Healthy: false, Fix: "Change container type to \"linux\" in Docker Desktop settings", Doc: docURL+"#verify-docker-container-type-is-linux"} + + } if err == nil { glog.Infof("docker version: %s", output) return registry.State{Installed: true, Healthy: true} diff --git a/site/content/en/docs/drivers/docker.md b/site/content/en/docs/drivers/docker.md index c3a809288a03..72e187a88716 100644 --- a/site/content/en/docs/drivers/docker.md +++ b/site/content/en/docs/drivers/docker.md @@ -30,16 +30,18 @@ The Docker driver allows you to install Kubernetes into an existing Docker insta ## Troubleshooting -- On macOS or Windows, you may need to restart Docker for Desktop if a command gets hung - -- Run `--alsologtostderr -v=1` for extra debugging information - +[comment]: <> (this title is used in the docs links, don't change) +### Verify Docker container type is Linux - On Windows, make sure Docker Desktop's container type setting is Linux and not windows. see docker docs on [switching container type](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers). You can verify your Docker container type by running: -```shell - docker info --format '{{.OSType}}' -``` + ```shell + docker info --format '{{.OSType}}' + ``` + +### Run with logs +- Run `--alsologtostderr -v=1` for extra debugging information +### Deploying MySql on a linux with AppArmor - On Linux, if you want to run MySQL pod, you need to disable AppArmor for mysql profile If your docker has [AppArmor](https://wiki.ubuntu.com/AppArmor) enabled, running mysql in privileged mode with docker driver will have the issue [#7401](https://github.com/kubernetes/minikube/issues/7401). From f68f45a30ab3bc00c56060cc2785b6234ea389b4 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Sat, 2 May 2020 20:20:58 -0700 Subject: [PATCH 8/9] flip debug if --- pkg/minikube/registry/drvs/docker/docker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/registry/drvs/docker/docker.go b/pkg/minikube/registry/drvs/docker/docker.go index bad19f3fba3e..8b9b3690c407 100644 --- a/pkg/minikube/registry/drvs/docker/docker.go +++ b/pkg/minikube/registry/drvs/docker/docker.go @@ -84,7 +84,7 @@ func status() registry.State { cmd := exec.CommandContext(ctx, oci.Docker, "version", "--format", "{{.Server.Os}}-{{.Server.Version}}") o, err := cmd.Output() output := string(o) - if !strings.Contains(output,"windows-") { + if strings.Contains(output,"windows-") { return registry.State{Error: oci.ErrWindowsContainers, Installed: true, Healthy: false, Fix: "Change container type to \"linux\" in Docker Desktop settings", Doc: docURL+"#verify-docker-container-type-is-linux"} } From 85aa9709da2bf96df136972007d4853060db9a5a Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Sat, 2 May 2020 20:30:50 -0700 Subject: [PATCH 9/9] lint --- pkg/minikube/registry/drvs/docker/docker.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/minikube/registry/drvs/docker/docker.go b/pkg/minikube/registry/drvs/docker/docker.go index 8b9b3690c407..b05d174037fc 100644 --- a/pkg/minikube/registry/drvs/docker/docker.go +++ b/pkg/minikube/registry/drvs/docker/docker.go @@ -84,8 +84,8 @@ func status() registry.State { cmd := exec.CommandContext(ctx, oci.Docker, "version", "--format", "{{.Server.Os}}-{{.Server.Version}}") o, err := cmd.Output() output := string(o) - if strings.Contains(output,"windows-") { - return registry.State{Error: oci.ErrWindowsContainers, Installed: true, Healthy: false, Fix: "Change container type to \"linux\" in Docker Desktop settings", Doc: docURL+"#verify-docker-container-type-is-linux"} + if strings.Contains(output, "windows-") { + return registry.State{Error: oci.ErrWindowsContainers, Installed: true, Healthy: false, Fix: "Change container type to \"linux\" in Docker Desktop settings", Doc: docURL + "#verify-docker-container-type-is-linux"} } if err == nil {