Windows Subsystem for Linux (WSL) is a new feature in Windows 10 that allows you to run Linux commands directly on Windows. WSL 2 is a new version of WSL that enables the Windows subsystem for Linux to run ELF64 Linux binaries on Windows. Its main goals are to improve file system performance and increase full compatibility of system calls. WSL 2 uses virtualization to run the Linux kernel inside a lightweight utility virtual machine (VM).

Enable and configureWSL 2

Win Version Requirements

WSL 2 is only available on Windows 10 18917 or later. If the version is too low, you can join Windows Insider to upgrade Windows. We can use VER in CMD to check the current version of Windows.

To enable theVirtual Machine PlatformOptional components

Run the following command as an administrator in powerShell

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Copy the code

After the installation is complete, restart the computer to complete the installation.

Set up the WSL distribution

If you want to set the default WSL distribution to WSL 2, use the following command in powerShell

wsl --set-default-version 2
Copy the code

If you want to set a Distro to WSL2, use the following command in powerShell to change

to the Distro you want to set, such as Ubuntu-18.04

wsl --set-version <Distro> 2
Copy the code

Verify the WSL version used

wsl -l -v
Copy the code

Download and installUbuntu-18.04

Search for Ubuntu-18.04 in the Windows App Store and download it. When the download is complete, open Ubuntu-18.04 and you will be asked to set up a new UNIX user name and password. You get into the Linux subsystem. To verify WSL 2, enter WSL-l -v in powerShell. The output is as follows, where VERSION 2 indicates that WSL 2 is enabled

NAME                   STATE           VERSION
* Ubuntu-18.04           Running         2
Copy the code

Ubuntu-18.04Change the domestic source

Start by backing up the default source

cp /etc/apt/sources.list /etc/apt/sourses.list.bak
Copy the code

Change the default source to Ali source and run sudo vim /etc/apt/sources.list to delete the original content and add the following Ali source information

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted  universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverseCopy the code

After changing the source, update it with the following command

sudo apt-get update
sudo apt-get upgade
Copy the code

Install the configurationWindows Terminal

downloadWindows Terminal

Windows Terminal is a new command line tool launched by Win, which can be searched and downloaded in the App Store. The following interface is opened after installation

Here is how to use Windows Terminal to connect to WSL 2 and install ZSH.

The installationzsh

# installation ZSH
sudo apt-get install zsh

Change the default Shell to ZSH
chsh -s /bin/zsh
Copy the code

The installationoh-my-zsh

Oh-my-zsh is used to quickly configure ZSH. You can access the official website or Github to learn about its basic use and rich theme use. You only need to execute the following code to install it

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Copy the code

Install zsh-syntax-higlighting syntax highlighting plugin

# download
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git

Move to the plugins folder
mv -p zsh-syntax-highlighting $ZSH_CUSTOM/plugins

Configure environment variables
cd ~
vim .zshrc

# Add ZSH -syntax-highlighting in the plugins column below
plugins=(
         git
         zsh-syntax-highlighting
         )

# add at the end of the file
source $ZSH_CUSTOM/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# Configuration takes effect
source ~/.zshrc
Copy the code

Install the ZSH-AutoSuggestions syntax history plug-in

# download
git clone https://github.com/zsh-users/zsh-autosuggestions.git

Move to the plugins folder
mv -p zsh-autosuggestions $ZSH_CUSTOM/plugins

Configure environment variables
cd ~
vim .zshrc

Add zsh-autoSuggestions to the plugins column as follows
plugins=(
         git
         zsh-syntax-highlighting
         zsh-autosuggestions
         )

# add at the end of the file
source $ZSH_CUSTOM/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

# Configuration takes effect
source ~/.zshrc
Copy the code

After the configuration is complete, the default theme cursor is as follows. If you want to configure more diversified themes, you can search for them by yourself

Install and configureDockerThe environment

inWSL 2Installed in theDocker

Uninstall the previous version

sudo apt-get remove docker docker-engine docker.io containerd runc
Copy the code

Setting up the repository

Update apt package index
sudo apt-get update

Install the package to allow APT to use the repository via HTTPS
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

Set up a stable repository
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
Copy the code

Install Docker Community Edition (Docker-CE)

Update apt package index
sudo apt-get update

Install the latest version of Docker and Containerd
sudo apt-get install docker-ce docker-ce-cli containerd.io
# (*) Install a specific version; 
      
        indicates a specific VERSION, for example, 18.09.1
      
sudo apt-get install docker-ce=<VERSION> docker-ce-cli=<VERSION> containerd.io
Copy the code

Start Docker and set it to boot

# start docker
systemctl start docker.service
# Set boot to boot
systemctl enable docker.service
Copy the code

If a non-root user wants to use docker, you need to add the user to the Docker user group

sudo usermod -aG docker user-name
Copy the code

(*) unload docker

# Uninstall software
sudo apt-get purge docker-ce
Delete docker containers, images, volumes, etc
sudo rm -rf /var/lib/docker
Copy the code

Download and installDocker Desktop WSL 2 backend

WSL 2 introduces significant architectural changes because it is a full Linux kernel built by Microsoft that allows Linux containers to run natively without emulation, Docker also develops a Desktop management program that can use the Docker daemon in WSL2. Open the Docker Desktop WSL2 Backend page and download the latest program. After installation, open the program and perform the following Settings

  • Enabling experiment-basedWSL 2Engine check box (Enable the experimental WSL 2 based engine)

  • (*) exposure2375Port to be managed by other external programsDocker(openExpose daemon on tcp://localhost:2375 without TLSCheck box in front)
  • inResourcesTo set from whichWSL 2Access in the distributionDocker, is used in the picture belowUbuntu-18.04

Once configured, click Apply & Restart to Apply and Restart the Docker Desktop. After the restart, we can see that the Docker status in the lower left foot of the Desktop is running in green, indicating that the Docker is running.

Docker Engine 19.03.5 Docker Engine 19.03.5 Docker Engine 19.03.5 Docker-compose is available in 1.25.1-rC1 and Kubernetes is supported in v1.15.5.

Install and configureKubernetesThe environment

Modify theDocker daemonconfiguration

The default Cgroup Driver for docker is Cgroup, but versions after Kubernetes1.14 recommend using Systemd as the Cgroup Driver for Docker. Use vim /etc/dock/deamon. json to modify or create a configuration. For details, see Kubernetes official.

In addition, we also need to configure the domestic image source of Docker to accelerate the speed of image download. Generally, the image source of Ali and UNIVERSITY of Science and Technology of China is used. The above two configuration steps are as follows

# Edit the deamon file
vim /etc/docker/deamon.json

# Enter the following information
{
  "registry-mirrors": ["https://6e0d9uoa.mirror.aliyuncs.com"."https://docker.mirrors.ustc.edu.cn"]."exec-opts": ["native.cgroupdriver=systemd"]."log-driver": "json-file"."log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}

# restart Docker
sudo service docker restart
Copy the code

downloadKubernetesRequired mirror image

Due to network problems, if you cannot access the Internet, you will not be able to start Kubernetes directly from Decker Desktop. Kubernetes: Kubernetes: Kubernetes: Kubernetes: Kubernetes: Kubernetes: Kubernetes: Kubernetes: Kubernetes:

# Download the project locally
git clone https://github.com/AliyunContainerService/k8s-for-docker-desktop
Enter the project directory
cd k8s-for-docker-desktop

Kubernetes v1.15.5 is supported by the latest master, so you can download the script directly
./load_images.sh
Copy the code

After all images are downloaded, we can see the downloaded container using Docker Images

REPOSITORY TAG IMAGE ID CREATED SIZE K8s.gcr. IO/kube-Apiserver v1.15.5e534b1952A0d 2 months ago 207MB REPOSITORY TAG IMAGE ID CREATED SIZE K8s.gcr. IO/kube-Apiserver V1.15.5e534b1952A0D 2 months ago 207MB K8s.gcr. IO /kube-proxy v1.15.5cbd7f21fec99 2 months ago 82.4MB k8s.gcr. IO /kube-controller-manager v1.15.51399a72fa1a9 2 months ago 82.4MB k8s.gcr. IO /kube-controller-manager v1.15.51399a72fa1a9 2 months ago IO/Kube - Scheduler v1.15.5 Fab2dded59dd 2 Months ago 81.1MB Quay. IO/kubernetes-ingress-Controller/nginx-ingress-Controller 0.26.1 29024c9c6e70 2 months ago 483MB Docker/kube-composing -controller v0.4.23a8c3d87a58e7 6 months ago 35.3MB Docker/kube-composing - apI-server v0.4.23 F3591b2cb223 6 months ago 40.3MB k8s.gcr. IO/coreDNS 1.3.1 EB516548c180 11 months ago 40.3MB K8s.gcr. IO/kubernetes-dashboards - AMd64 v1.10.1f9aed6605b81 12 months ago 122MB k8s.gcr. IO/etCD 3.3.102c4adeb21b4f 12 months ago 122MB k8s.gcr. IO/etCD 3.3.102c4adeb21b4f 12 months ago 122MB k8s.gcr. IO/etCD 3.3.102c4adeb21b4f 12 months ago Months ago 258MB k8s.gcr. IO /pause 3.1 da86e6ba6CA1 24 months ago 258KBCopy the code

To enable theKubernetes

We chose to enable Kubernetes in our Docker Desktop Settings and hit Apply & Restart to Restart.

With any luck, when you restart your Desktop you will find that both Docker and Kubernetes are in a green runnning state, but there is a good chance that Kubernetes will always be in a yellow starting state. In this case, don’t worry, we can check the log information under C: ProgramData DockerDesktop service. TXT, generally, the startup is not successful, the most frequent log information is the following repeated content

[08:57:24. 359] [ApiProxy] [Info] time ="2019-12-20T08:57:24+08:00" msg="cannot list nodes: Get https://kubernetes.docker.internal:6443/api/v1/nodes: EOF"[08:57:24. 359] [GoBackendProcess] [Info] time ="2019-12-20T08:57:24+08:00" msg="External: POST /events 200 \" go-http-client /1.1\" \"\""
Copy the code

In this case, you can refer to Issue 3769(comment) and Issue 1962(comment), which can be summarized as the following operations:

  • Modify thehostThe file will be127.0.0.1 kubernetes. Docker. InternalMapping information is added tohostIn the file
  • Modifying the network connectionDNSAddress is8.8.8.8winHow to modify the network connectionDNSYou can search by yourself
  • deleteC:\ProgramData\DockerDesktopIn the directorypkiDirectory file
  • deleteC: \ Users \ < yourname > directory.kubeDirectory file
  • Shut downwinNetwork firewall, or willvpnkit.exeAdd to firewall inbound and outbound rules.
  • inDesktopClick entertroubleshoot, click ResetkubernetesCluster (Reset Kubernetes cluster)

If the preceding operations still fail, repeat the operations for several times. If other problems arise, the solution can usually be found under the issue of the Docker \for-win project. If the startup is successful, execute the following command on the command line to verify

$ kubectl cluster-info
Kubernetes master is running at https://kubernetes.docker.internal:6443
KubeDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. $kubectl get Nodes NAME STATUS ROLES AGE VERSION Docker-desktop Ready master 6h v1.15.5Copy the code

The deployment ofKubernetes dashboard

The Kubernetes Dashboard is a common Web-based UI for the Kubernetes cluster. It allows users to manage and troubleshoot applications running in a cluster, as well as manage the cluster itself. Run the following command to deploy

# Create a Dashboard resource
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

# (*) If the command above says there is a problem with the network connection, download the yamL file to your local computer and execute it
kubectl apply -f kubernetes-dashboard.yaml

# enable API Server access proxy
kubectl proxy
Copy the code

Once deployed, we can access the Kubernetes Dashboard via the following URL

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#! /login

To access the Dashboard, you need to obtain a token by running the following command and pasting the generated token to the token login input box.

kubectl -n kube-system describe secret default| awk '$1=="token:"{print $2}'
Copy the code

Download and installHelm

Helm is a package manager for Kubernetes developed by Deis. Each package is called Chart. Helm client installation is very simple. We can download the latest executable program from Github and decompress it to use it.

# Download v2.16.1Wget HTTP: / / https://get.helm.sh/helm-v2.16.1-linux-amd64.tar.gz# decompressionTar - ZXVF helm - v2.16.1 - Linux - amd64. Tar. Gzcd linux-amd64/
Move to /usr/local/bin
cp helm /usr/local/bin/
Copy the code

The server tiller is not so easy to install because it downloads images from the Internet. Fortunately, there are images packaged and uploaded by others on Docker Hub, so we just need to pull them down and tag them. The specific steps are as follows:

Download the image locallyDocker pull doublemine/kubernetes - helm. Tiller: v2.16.1Add the tag #Docker tag doublemine/kubernetes - helm. Tiller: v2.16.1 GCR. IO/kubernetes - helm/tiller: v2.16.1Copy the code

After the server image is downloaded locally, we can install tiller on the cluster and run the following command to create the service account and initialize the client

kubectl create serviceaccount tiller -n kube-system kubectl create clusterrolebinding tiller --clusterrole cluster-admin  --serviceaccount kube-system:tiller helm init --wait --service-account tillerCopy the code

After the installation and initialization is complete, we want to verify that the Tiller service is running by using the following command

$ kubectl get pod --namespace kube-system
NAME                                     READY   STATUS    RESTARTS   AGE
coredns-5c98db65d4-7rn5b                 1/1     Running   0          12h
coredns-5c98db65d4-bx9x2                 1/1     Running   0          12h
etcd-docker-desktop                      1/1     Running   0          12h
kube-apiserver-docker-desktop            1/1     Running   0          12h
kube-controller-manager-docker-desktop   1/1     Running   0          12h
kube-proxy-rdtfm                         1/1     Running   0          12h
kube-scheduler-docker-desktop            1/1     Running   0          12h
kubernetes-dashboard-7d75c474bb-qcbxx    1/1     Running   0          4h46m
tiller-deploy-54f7455d59-fgsnb           1/1     Running   0          12h
Copy the code

We can see the last column showing that the Tiller service is running.

The Helm configures the domestic mirror source

When we use helm to install the application, we will find the download speed is very slow and may encounter network problems. In this case, we need to configure its default download image source to be domestic. The configuration procedure is as follows:

Delete the default mirror source
helm repo remove stable
# Add new domestic mirror source
helm repo add stable http://mirror.azure.cn/kubernetes/charts/
helm repo add incubator http://mirror.azure.cn/kubernetes/charts-incubator/
# Update warehouse
sudo helm repo update

# Test speed
helm search mysql
Copy the code