AutoK3s 是一个新工具,可以轻松在许多平台上安装和管理 Kubernetes 集群。
在本教程中,我们将使用以下方法在 Windows WSL 中安装 Kubernetes:-
Ubuntu 22.04 WSL 发行版
这个发行版的惊人之处在于它们内置了 systemctl。如果您选择了其他发行版,您应该使用其他方法来启动 docker 和其他服务。
Docker for Linux(不带 docker 桌面)
您可能知道,docker desktop 不再免费,我发现它使用了更多来自 pc 的资源。
1.戳
K3s 是一个高度可用、经过认证的 Kubernetes 发行版,专为生产工作负载而设计。最重要的是“轻量级 Kubernetes”
1.坐下
K3d 是在 docker 中运行 k3s 的轻量级包装器。
AutoKxs
AutoK3s 是一个用于简化 K3s 集群管理的轻量级工具。
本教程推荐使用Ubuntu 22.04。你可以从微软商店下载它。
建议升级。
sudo apt update && sudo apt upgrade
进入全屏模式 退出全屏模式
在您的 WSL 编辑中/etc/wsl.conf
sudo nano /etc/wsl.conf
进入全屏模式 退出全屏模式
添加以下行:
\[boot\]
command="/usr/libexec/wsl-systemd"
进入全屏模式 退出全屏模式
然后关闭终端并在 PowerShell 中使用以下命令重新启动 WSL
wsl
进入全屏模式 退出全屏模式
然后您可以启动新的 WSL shell 并检查 systemctl 是否正常工作
ps aux
进入全屏模式 退出全屏模式
[
](https://res.cloudinary.com/practicaldev/image/fetch/s--0Gix2B3S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads .s3.amazonaws.com/uploads/articles/hz72s3trxuhbp311xioj.jpg)
请注意,第一行(PID 1)是 systemctl
然后检查 systemctl 状态:
systemctl status
进入全屏模式 退出全屏模式
对我来说,我得到了 3 个失败的服务:
ssh.service
systemd-remount-fs.service
systemd-sysusers.service
解决 ssh 服务:
apt-get install openssh-server openssh-client
dpkg-reconfigure openssh-server
进入全屏模式 退出全屏模式
对于其余的:
注释掉/etc/fstab中的行:
#LABEL=cloudimg-rootfs / ext4 discard,errors=remount-ro 0 1
进入全屏模式 退出全屏模式
打开/usr/lib/systemd/system/systemd-sysusers.service并删除所有行,然后添加:
\[Unit\]
Description=Create System Users Documentation=man:sysusers.d(5) man:systemd-sysusers.service(8)
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-remount-fs.service
Before=sysinit.target shutdown.target systemd-update-done.service
ConditionNeedsUpdate=/etc
\[Service\]
Type=oneshot
RemainAfterExit=yes
ExecStart=systemd-sysusers
TimeoutSec=90
\[Service\]
LoadCredential=
进入全屏模式 退出全屏模式
最后,重新启动并再次检查服务。
从这个教程中详细安装 Docker 的说明,我们可以跳过Sharing dockerd并添加脚本(因为我们使用 systemctl)简而言之,这可以通过以下方式完成:
安装依赖
sudo apt install --no-install-recommends apt-transport-https ca-certificates curl gnupg2
进入全屏模式 退出全屏模式
切换到旧版 iptables
update-alternatives
进入全屏模式 退出全屏模式
选择 iptables-legacy
包存储库配置
首先,临时设置一些特定于操作系统的变量:
. /etc/os-release
进入全屏模式 退出全屏模式
然后,确保 apt 信任 repo:
curl -fsSL https://download.docker.com/linux/${ID}/gpg | sudo tee /etc/apt/trusted.gpg.d/docker.asc
进入全屏模式 退出全屏模式
然后添加并更新 repo 信息,以便 apt 将来使用它:
echo "deb \[arch=amd64\] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update
进入全屏模式 退出全屏模式
安装 Docker
sudo apt install docker-ce docker-ce-cli containerd.io
进入全屏模式 退出全屏模式
将用户添加到 Docker 组
sudo usermod -aG docker $USER
进入全屏模式 退出全屏模式
最后,关闭该 WSL 窗口,然后再次启动 WSL。并检查 docker 是否正常工作:
docker run
进入全屏模式 退出全屏模式
安装 K3D
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
进入全屏模式 退出全屏模式
安装 AutoK3s 从发布页面下载二进制文件。
curl https://github.com/cnrancher/autok3s/releases/download/v0.5.1/autok3s\_linux\_amd64 --create-dirs -o ~/bin/autok3s
进入全屏模式 退出全屏模式
使其可执行
chmod 755 ~/bin/autok3s
进入全屏模式 退出全屏模式
然后添加到路径
echo 'export PATH="$HOME/bin:$PATH"' >\> ~/.bashrc
进入全屏模式 退出全屏模式
安装 kube-explorer(可选)
curl https://github.com/cnrancher/kube-explorer/releases/download/v0.2.9/kube-explorer-linux-amd64 --create-dirs -o ~/bin/kube-explorer
chmod 755 $HOME/bin/kube-explorer
进入全屏模式 退出全屏模式
autok3s serve
进入全屏模式 退出全屏模式
在浏览器上打开127.0.0.1:8080开始创建、删除修改 Kubernetes 集群。