背景说明
Linux 发行版开发商 SUSE 已经发布了容器管理工具 Rancher Desktop 1.0,Rancher Desktop是一款开源应用程序,可供用户在 Mac、Windows 和 Linux 桌面管理 Kubernetes 和容器。Rancher Desktop 可以简化用户在桌面上操作 Kubernetes 的体验,在桌面提供易于使用的本地环境,方便地将应用程序打包成 Kubernetes 应用程序执行。
Rancher Desktop 内建 k3s 发行版,并让用户能够自由选择版本号,因此无论在生产环境和本地 Kubernetes 环境,都能使用相同版本,官方还提到,Rancher Desktop 还能方便地用来测试工作负载,观察其升级 Kubernetes 版本后的行为。在底层,Rancher Desktop 使用 containerd 或 dockerd 作为容器引擎。可供用户自由选择,当 Rancher Desktop 用户使用 nerdctl 或 Docker CLI 时,将允许您构建、推送和拉取容器映像并运行容器。您使用这些工具构建的镜像可以直接在 Kubernetes 中运行,而无需从注册表中推送或拉取它们。当您选择 dockerd 运行时时,您有一个 Docker 套接字可供您的其他工具使用。这使得使用像 k3d 这样的工具直接与 Docker 套接字通信成为可能。
官网地址
文档地址
https://docs.rancherdesktop.io/
https://docs.rancher.cn/docs/rancherdesktop/intro/_index/
项目地址
https://github.com/rancher-sandbox/rancher-desktop/releases
安装方案
前置依赖
软件下载
访问网址https://github.com/rancher-sandbox/rancher-desktop/releases下载安装包
软件安装
双击安装软件包进行安装
选择对应的版本
启动K8s的过程中需要从github拉取镜像,可以开启fastgithub 这个工具加速下载。
软件使用
使用Windows PowerShell窗口进行连接测试,这里推荐使用Windows Terminal
PS C:\Users\86183> kubectl.exe version --short
Client Version: v1.22.5
Server Version: v1.21.10+k3s1
PS C:\Users\86183> kubectl.exe get cluster-info
error: the server doesn't have a resource type "cluster-info"
PS C:\Users\86183> kubectl.exe cluster-info
Kubernetes control plane is running at https://172.31.174.234:6443
CoreDNS is running at https://172.31.174.234:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://172.31.174.234:6443/api/v1/namespaces/kube-system/services/https:metrics-server:https/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
PS C:\Users\86183> kubectl.exe get nodes
NAME STATUS ROLES AGE VERSION
laptop-crffk470 Ready control-plane,master 41m v1.21.10+k3s1
PS C:\Users\86183>
第一次连接时可能出现如下问题
PS C:\Users\86183> kubectl.exe cluster-info
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Unable to connect to the server: dial tcp 127.0.0.1:6443: connectex: No connection could be made because the target machine actively refused it.
查看当前上下文
PS C:\Users\86183> kubectl.exe config current-context
docker-desktop
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* docker-desktop docker-desktop docker-desktop
rancher-desktop rancher-desktop rancher-desktop
也可以查看目录文件C:\Users\86183.kube\config的配置节点current-context
切换上下文
PS C:\Users\86183> kubectl.exe config use-context rancher-desktop
Switched to context "rancher-desktop".
PS C:\Users\86183> kubectl.exe config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
docker-desktop docker-desktop docker-desktop
* rancher-desktop rancher-desktop rancher-desktop
PS C:\Users\86183> kubectl.exe get nodes
NAME STATUS ROLES AGE VERSION
laptop-crffk470 Ready control-plane,master 9m21s v1.21.10+k3s1
PS C:\Users\86183>