Windows 10 安装 docker 并开启 Kubernetes 记录

hxy    2020-07-23 10:51

先看看Docker的介绍:

Docker is a platform for developers and sysadmins to build, run, and share applications with containers. The use of containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is.

Containerization is increasingly popular because containers are:

  • Flexible: Even the most complex applications can be containerized.
  • Lightweight: Containers leverage and share the host kernel, making them much more efficient in terms of system resources than virtual machines.
  • Portable: You can build locally, deploy to the cloud, and run anywhere.
  • Loosely coupled: Containers are highly self sufficient and encapsulated, allowing you to replace or upgrade one without disrupting others.
  • Scalable: You can increase and automatically distribute container replicas across a datacenter.
  • Secure: Containers apply aggressive constraints and isolations to processes without any configuration required on the part of the user.
关于WSL (Windows 下的Linux 子系统)的介绍

What is WSL?

Windows Subsystem for Linux (WSL) allows users to run a Linux terminal environment, install packages from the Ubuntu archive, and run Linux applications and workflows on Windows 10.

What is WSL 1?

The original WSL is now known as WSL1. WSL1 is a compatibility layer for running Linux binary executables (ELF) natively on Windows 10. No re-compilation or 'porting' of applications is required. WSL1 provides a Linux-compatible kernel interface developed by Microsoft that allows a user to choose a Linux distribution to install from the Microsoft Store. WSL1 executes unmodified Linux ELF64 binaries by operating a Linux kernel interface on top of the Windows kernel in Windows 10. The WSL1 interface translates Linux system calls from the binaries into Windows system calls and then executes them at native speed. Linux applications run within the Linux distribution which provides the application's dependencies and package management in a container-like environment. WSL provides an interface to mount drives within WSL.

What is WSL 2?

WSL2 was announced at Microsoft Build 2019. WSL2 features a Linux kernel running inside Windows 10 and is built on the core technology of Hyper-V to provide better Linux application support and improved file performance. Transitioning to WSL2 is seamless. WSL2 is still in active development and is only available in Insider builds. These builds are not suitable for production devices and are not recommended for a user's primary machine. Instead, users can try WSL2 using Hyper-V or on a secondary machine.

这个Linux子系统需要专业版或教育版的Windows 10, 并且可能需要将系统版本号升到最新。可以考虑用Windows 10更新助手。升级之后操作如下:

1. 打开"控制面板","卸载程序","启用或关闭Windows功能中", 启用“Hyper-V”


2. 安装:去官网下载。https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe
然后正常安装启动。

基本的docker就完成了。





需要安装Kubernetes优化请继续。
PS:由于我的电脑里安装了Proxifier和Docker底层网络冲突了,所以出现了 System.InvalidOperationException: Failed to set version to docker-desktop: exit code: -1,如下问题。
 

解决办法:以管理员权限打开命令行,输入
netsh winsock reset
然后重启,再次打开docker,成功启动。
使用命令行查看docker版本信息:
C:\Users\admin>docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:23:10 2020
 OS/Arch:           windows/amd64
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:29:16 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
开启K8s
默认镜像在Google,访问出错,Aliyun团队有解决方案。
https://github.com/AliyunContainerService/k8s-for-docker-desktop

安装之后,
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-rc5/aio/deploy/recommended.yaml
这个默认访问不了,可以把网址粘贴到浏览器通过代理下载下来,然后在本地运行:
kubectl create -f recommended.yaml
注意切换到刚才下载recommended.yaml文件的目录再执行kubectl create

检查 kubernetes-dashboard 应用状态

kubectl get pod -n kubernetes-dashboard

开启 API Server 访问代理

kubectl proxy

通过如下 URL 访问 Kubernetes dashboard

http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

配置控制台访问令牌

对于Windows环境

$TOKEN=((kubectl -n kube-system describe secret default | Select-String "token:") -split " +")[1]
kubectl config set-credentials docker-for-desktop --token="${TOKEN}"
echo $TOKEN

选择 令牌

输入上文控制台输出的内容进入控制面板。





-------------------------------
后面的记录有点跑偏了,其实直接关闭Proxifier就可以了。下面的操作记录了如何开启Ubuntu 20.04

搜到有解决方案说:运行如下命令
lxrun /install /y
提示:'lxrun' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
原因:根据官网提供的信息,lxrunt. exe 从 windows 10 1803 及更高版本开始弃用。同时请参考下方链接中的信息。

首先, 到"控制面板","卸载程序","启用或关闭Windows功能中", 启用"适用于Linux的windows子系统"

https://docs.microsoft.com/en-us/windows/wsl/install-manual
我选的Ubuntu20.04, 浏览器直接下载有点慢,用了Motrix,速度能到2 Mb/s
下载之后解压:
双击Ubuntu.exe运行。
配置用户名及密码即可。
 
Last Modified: 2020-07-27 19:22
Views: 3.7K

[[total]] comments

Post your comment
  1. [[item.time]]
    [[item.user.username]] [[item.floor]]Floor
  2. Click to load more...
  3. Post your comment