1
头图
If you have played K8S, you should know that there is something called Minikube, which can build a single-node K8S environment on this machine. Recently I found a graphical tool, Rancher Desktop, which is easier to use than Minikube. It can basically build a K8S environment with one click. It is very convenient to use on Win10. I recommend it to everyone!

SpringBoot actual e-commerce project mall (50k+star) address: https://github.com/macrozheng/mall

Introduction to Rancher Desktop

Rancher Desktop is an open source K8S management tool, currently available on Github 2.9K+Star . It is a desktop version of K8S and container management tool that supports use on Windows, macOS and Linux. If you want to build a K8S environment on Windows and use Minikube, you must first build a virtual machine, then install Linux, and then install Minikube. If you use Rancher Desktop, you only need to install it, it will automatically install the K8S environment, which is really convenient!

The following is a user interface diagram of Rancher Desktop, which supports one-click switching of K8S versions, which is very good!

WSL

Thanks to WSL (Windows Subsystem for Linux), we can more easily install the Linux Subsystem under Windows without the overhead of a traditional virtual machine or dual-boot setup. The Rancher Desktop Windows version is based on WSL to install the K8S environment. You can learn about the following commonly used WSL commands.

# 使用wsl安装Linux的发行版(默认Ubuntu)
wsl --install
# 列出已经安装的Linux发行版
wsl --list --verbose
# 通过在线商店获得的 Linux 发行版列表
wsl --list --online
# 关闭Linux子系统
wsl --shutdown

PowerShell

PowerShell is a cross-platform task automation solution consisting of a command-line shell, a scripting language, and a configuration management framework. PowerShell runs on Windows, Linux and macOS.

After the K8S environment is installed, we will use PowerShell to operate K8S. The tools used are Tabby , Tabby is indeed an artifact, and PowerShell support is also very good!

Install

Next we will install Rancher Desktop on Win10 and see if it works better than Minikube.

  • After the download is successful, double-click to install, and you will be asked to select the K8S version and container runtime;

  • After that, Rancher Desktop will install the K8S environment and WSL by itself, and there is no need to download it manually. If you cannot download it, you can switch the v1.21.9 version and try it. The version 06226b8abce395 is used here;

  • Next, you can use the kubectl command in PowerShell, for example, to view the cluster information, so far the K8S environment is installed, so simple!

use

Next, we will deploy an Nginx application on K8S to experience whether the K8S environment installed using Rancher Desktop is the same as that of Minikube!
  • First create a Deployment for deploying Nginx applications;
kubectl create deployment kubernetes-nginx --image=nginx:1.10
  • Then check whether the application is ready to be deployed;
kubectl get deployments

  • After the deployment is successful, we create a service to expose the Nginx application for external access;
kubectl expose deployment/kubernetes-nginx --type="NodePort" --port 80
  • Check if the service can get the external access port;
kubectl get services

  • Next, you can access the Nginx service directly through the browser.

Visual management

When using Minikube before, you can use Dashboard to visually manage K8S, and the K8S environment installed with Rancher Desktop can also be managed by it. Let's experience it below.
kubectl apply -f recommended.yaml
  • Since a login token is required to access Dashboard, we have to create a user and generate a token first;

  • Create dashboard-adminuser.yaml configuration file, configure admin-user account and assign the cluster administrator role;
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard
  • Use the following command to create admin-user user;
kubectl apply -f dashboard-adminuser.yaml
  • Then use the following command to generate a login token and copy it for use when logging in to Dashboard;
kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"

  • Next, you can happily use the Dashboard to manage the K8S environment, such as viewing all Deployments;

  • View all running Pods;

  • View all active services.

Summarize

Installing the K8S environment under Windows has always been a very troublesome thing. It was not until I used Rancher Desktop that I found out that it was so simple! I tried it today, and it is no different from Minikube in use. Friends who want to experience K8S on Windows can try it!

If you want to learn more about K8S, you can refer to the K8S series tutorial I wrote earlier.

If you want to practice a whole set of microservice projects under K8S, I recommend this actual e-commerce project marked with 8.2K+ (with a full set of tutorials): https://github.com/macrozheng/mall-swarm

References


macrozheng
1.1k 声望1.3k 粉丝