date
related_level
slug
type
relate_date
summary
status
tags
category
last_updated
Nov 10, 2025 10:03 PM
是否已更新
orginal_page
是否推荐
参考资料
k3s 架构
节点角色
- server 节点指的是运行
k3s server命令的主机,管理 control plane 和数据存储组件
- agent 节点指的是运行
k3s agent命令的主机,不具有任何数据存储或 control plane 组件
- server 和 agent 节点都运行 kubelet、容器运行时和 CNI

带有嵌入式数据库的单服务器 k3s 集群
- 每个 Agent 节点都注册到同一个 Server 节点
- k3s 用户可以通过调用 Server 节点上的 k3s API 来操作 Kubernetes 资源

高可用(HA) k3s 集群
一个高可用 K3s 集群包括以下
- 以嵌入式 etcd 为高可用存储
- 三个或多个 Server 节点为 Kubernetes API 提供服务并运行其他 control plane 服务
- 嵌入式 etcd 数据存储(与单节点设置中使用的嵌入式 SQLite 数据存储相反)
- 以外部数据库为高可用存储
- 两个或多个 Server 节点为 Kubernetes API 提供服务并运行其他 control plane 服务
- 外部数据存储(例如 MySQL、PostgreSQL 或 etcd)
在 HA 服务器配置中,每个节点都能使用固定的注册地址向 Kubernetes API 注册
Agent 节点通过 k3s agent 进程发起的 WebSocket 连接进行注册,连接由作为 agent 进程一部分运行的客户端负载均衡器维护
- 最初,Agent 通过本地负载均衡器端口 6443 连接到 supervisor(和 kube-apiserver)
- 负载均衡器维护了一个要连接的可用端点列表
- 默认(也是最初唯一的)端点来源于
--server地址中的主机名
- 连接到集群后,Agent 会从默认命名空间中的 Kubernetes Service 端点列表中检索 kube-apiserver 地址列表。这些端点添加到负载均衡器,然后负载均衡器将保持与集群中所有 Server 稳定连接,提供与 kube-apiserver 的连接,从而容忍单个 Server 的中断
Agent 将使用节点集群 Secret 以及随机生成的节点密码注册到 Server,密码存储在 /etc/rancher/node/password 中
- Server 会将各个节点的密码存储为 Kubernetes Secret,后续的任何尝试都必须使用相同的密码
- 节点密码 Secret 存储在
kube-system命名空间中,名称使用<host>.node-password.k3s模板
- 如果 Agent 的
/etc/rancher/node目录被删除,或者你希望使用现有名称重新加入节点,那么你需要从集群中删除该节点 - 这将清除旧节点条目和节点密码 Secret,并允许节点(重新)加入集群
k3s 网络端口
- 通常,允许所有出站流量
- K3s 服务器需要端口 6443 才能被所有节点访问
- 如果 K3s 使用 Flannel 的 VXLAN 后端(默认配置),节点之间需要通过 UDP 端口 8472 进行通信
- 如果 K3s 使用 Flannel 的 WireGuard 后端,节点之间需要通过 UDP 端口 51820 和 UDP 端口 51821(启用了 IPv6 支持)进行通信
- K3s 代理节点通过 向主节点发起出站连接 来建立反向隧道,以便节点与服务器建立连接,并且所有 kubelet 流量都通过该隧道运行
- 如果不使用 Flannel 并提供自己的自定义 CNI,则 K3s 不需要以上所需的端口
- 如果您计划使用嵌入式 etcd 实现高可用性,则服务器节点必须可以通过端口 2379 和 2380 相互访问
Protocol | Port | Source | Destination | Description |
TCP | 2379-2380 | Servers | Servers | Required only for HA with embedded etcd |
TCP | 6443 | Agents | Servers | K3s supervisor and Kubernetes API Server |
UDP | 8472 | All nodes | All nodes | Required only for Flannel VXLAN |
TCP | 10250 | All nodes | All nodes | Kubelet metrics |
UDP | 51820 | All nodes | All nodes | Required only for Flannel Wireguard with IPv4 |
UDP | 51821 | All nodes | All nodes | Required only for Flannel Wireguard with IPv6 |
TCP | 5001 | All nodes | All nodes | Required only for embedded distributed registry (Spegel) |
TCP | 6443 | All nodes | All nodes | Required only for embedded distributed registry (Spegel) |
Ubuntu/debian 安装 k3s
安装需求
适用于以下指令集架构
- x86_64
- armhf
- arm64/aarch64
- s390x
硬件配置最低需求
- K3s的性能取决于数据库的性能。为了确保最佳速度,我们建议尽可能使用 SSD
- 如果在 Raspberry Pi 或其他 ARM 设备上部署 K3s,建议您使用外部 SSD
- etcd 是写密集型的; SD卡和eMMC无法处理IO负载
Node | CPU | RAM |
Server | 2 cores | 2 GB |
Agent | 1 core | 512 MB |
服务器性能与代理数量指南
- 建议以 50 个或更少的批次加入代理节点,以允许 CPU 释放空间,因为节点加入时会出现峰值。如果需要超过 255 个节点,请记住修改默认的
cluster-cidr
Server CPU | Server RAM | Number of Agents |
2 | 4 GB | 0-350 |
4 | 8 GB | 351-900 |
8 | 16 GB | 901-1800 |
16+ | 32 GB | 1800+ |
服务器性能与节点数量指南
Deployment Size | Nodes | vCPUs | RAM |
Small | Up to 10 | 1 | 2 GB |
Medium | Up to 100 | 2 | 8 GB |
Large | Up to 250 | 4 | 16 GB |
X-Large | Up to 500 | 8 | 32 GB |
XX-Large | 500+ | 16 | 64 GB |
Ubuntu 安装额外需求
k3s 不兼容 ufw,建议关闭 ufw
ufw disable
或者添加以下 allow
ufw allow 6443/tcp- apiserver
ufw allow from 10.42.0.0/16 to any- pods
ufw allow from 10.43.0.0/16 to any- services
脚本安装(作为单节点集群服务器)
- 国内可以把下载链接换成
https://rancher-mirror.rancher.cn/k3s/k3s-install.sh
curl -sfL https://get.k3s.io | sh -s - server
server可以省略,作为集群服务器启动
- 选项
--docker使用 cri-docker 而不是 containerd 作为容器运行时 - 会多一层 docker-shim 抽象,建议直接使用 containerd
- 需要兼容 docker 前端语法可以安装
nerdctl操作 containerd 容器
k3s 安装的执行结果
- k3s 服务将配置为在节点重新启动后或者进程崩溃或被终止时自动重新启动
- 后续可以在 systemd unit 文件或配置文件中修改启动选项
/etc/systemd/system/k3s.service
同时将安装其他实用程序
- ubuntu 24 下 k3s 安装可能会缺失
/usr/bin/containerd二进制文件 - 原因不明
kubectl
crictl- 面向 Kubernetes 的容器运行时 CLI
ctr- containerd 原生命令行工具
k3s-killall.sh
k3s-uninstall.sh
- kubeconfig文件将被写入
/etc/rancher/k3s/k3s.yaml,k3s 安装的 kubectl 将自动使用它 k3s kubectl …
可选:二进制文件安装
下载 k3s 二进制文件并上传到 /usr/local/bin 目录
chmod +x ./k3s
cp ./k3s /usr/local/bin/k3s
测试
k3s -v
k3s check-config- 报错
脚本安装其他节点作为代理节点并将其添加到集群
K3S_TOKEN用于验证加入的节点和集群,分为安全格式或者短格式- https://docs.k3s.io/zh/cli/token
- 如果第一个 Server 节点是在没有
--tokenCLI 标志或K3S_TOKEN变量的情况下启动的,那么可以从任何已经加入集群的 Server 节点中检索到 Token sudo cat /var/lib/rancher/k3s/server/tokenprefix:固定的K10前缀,用来标识 token 格式cluster CA hash:集群的 Server CA 证书的哈希,用于为加入的节点验证 Server- 对于自签名 CA 证书,这是存储在磁盘上的 PEM 格式证书的 SHA256 总和
- 对于自定义 CA 证书,这是根证书的 DER 编码的 SHA256 总和,也称为证书指纹
credentials:用户名和密码,或持有者 Token,用于验证加入集群的节点- 短 Token 格式仅包括用于验证加入集群的节点的密码或持有者 Token
安全格式:<prefix><cluster CA hash>::<credentials>
支持三种类型的 token:Server, Agent, Bootstrap
类型 | CLI 选项 | 环境变量 |
Server | --token | K3S_TOKEN |
Agent | --agent-token | K3S_AGENT_TOKEN |
Bootstrap | n/a | n/a |
- 使用
K3S_URL和K3S_TOKEN环境变量 - URL 指向服务器节点
K3S_TOKEN可以通过cat /var/lib/rancher/k3s/server/token获取
curl -sfL https://get.k3s.io | K3S_TOKEN=mynodetoken sh - agent --server https://<ip or hostname of server1>:6443
curl -sfL https://get.k3s.io | K3S_TOKEN=mynodetoken sh - server --server https://<ip or hostname of server1>:6443- 作为服务器节点加入集群,需要在服务器节点启动时传递
--cluster-init使用嵌入式 etcd 取代 sqlite
确认 k3s 集群运行情况
- 确认 k3s 服务情况
sudo systemctl status k3ssudo journalctl -u k3s
sudo k3s kubectl get pods --all-namespaces
sudo k3s kubectl get nodes -o wide
sudo docker ps- 确认 docker 容器运行情况
配置外部访问 k3s 集群
- 以下样例为同一机器上运行,如果是不同客户端需要通过 sftp 等手段传递配置文件
- 方法1:设置 KUBECONFIG 环境变量
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml- 也可以配置到 ~/.bashrc, ~/.zshrc 等终端配置文件
sudo k3s kubectl get nodes -o wide
- 方法2:复制
/etc/rancher/k3s/k3s.yaml到对应客户端~/.kube/config sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/configsudo chown $USER:$(id -g -n) ~/.kube/config
- 确认运行情况
helm ls --all-namespaceskubectl get nodes -o widekubectl get pods -o wide --all-namespaces
安装 etcdctl 管理 etcd
- k3s 默认使用嵌入式 SQLite 存储数据,需要传递
--cluster-init使用嵌入式 etcd 初始化新集群
下载系统和架构对应版本并解压安装 etcdctl
- 以 linux-amd64(x86-64) 安装v3.5.17 版本为例
- 测试是否成功安装
etcd --version
将 etcdctl 配置为使用 K3s 管理的证书和密钥来进行身份验证
sudo etcdctl version \ --cacert=/var/lib/rancher/k3s/server/tls/etcd/server-ca.crt \ --cert=/var/lib/rancher/k3s/server/tls/etcd/client.crt \ --key=/var/lib/rancher/k3s/server/tls/etcd/client.key
设置别名 ectl 以免每次都输入对应证书和密钥
vim ~/.bashrc- 根据 shell 自行更改
alias ectl='etcdctl --cacert=<ca-file> --cert=<cert-file> --key=<key-file>'
source ~/.bashrc
etcdctl 常用指令
设置环境变量 ETCDCTL_API, ETCDCTL_ENDPOINTS
vim /etc/profile.d/etcdctl.sh
export ETCDCTL_API=3- API版本
export ETCDCTL_ENDPOINTS=http://localhost:2379- etcd 集群的访问地址,自行修改
chmod +x /etc/profile.d/etcdctl.sh
--endpoints 手动指定 k3s 集群
HOST_1=10.240.0.17 HOST_2=10.240.0.18 HOST_3=10.240.0.19 ENDPOINTS=$HOST_1:2379,$HOST_2:2379,$HOST_3:2379
etcdctl --endpoints=$ENDPOINTS member list
- 也可以加入到别名
- 增删改查
etcdctl put foo /"Hello World!/"etcdctl put web1 value1etcdctl put web2 value2etcdctl --write-out="json" get foo
检查 kubernete 集群网络配置和调试 DNS
检查 kubernete 集群网络配置
kubectl get nodes -o wide- 查看节点 Pod CIDR 范围
kubectl get svc -n kube-system- 列出命名空间
kube-system下的所有服务
kubectl -n kube-system get configmap coredns -oyaml- dns 配置
kubectl get networkpolicy --all-namespaces- 网络策略,如有
kubectl -n kube-system describe pod $(kubectl get pods --all-namespaces | grep -E ' traefik' | awk '{print $2}')- 查看
traefik启动参数
检查 kubernete DNS 配置并调试 DNS
创建一个简单的 Pod 作为测试环境
vim dnsutils.yaml
- 或者直接使用官方配置
kubectl apply -f https://k8s.io/examples/admin/dns/dnsutils.yaml
- 命名空间 default 根据自身配置修改
- 验证安装情况
kubectl get pods dnsutils
- 处于 running 状态后可以执行
nslookup kubectl exec -i -t dnsutils -- nslookup kubernetes.defaultkubectl exec -i -t dnsutils -- ping -c 4 kubernetes.default
检查 DNS 配置
查看 resolv.conf 文件的内容
kubectl exec -ti dnsutils -- cat /etc/resolv.conf
官方样例,search 域可能根据云供应商变化
Coredns 服务开启 DNS 查询记录日志
kubectl -n kube-system edit configmap coredns
- 添加
log项
kubectl logs --namespace=kube-system -l k8s-app=kube-dns- 查看服务运行日志
检查 DNS 服务和 CoreDNS Pod 运行情况
kubectl get svc --namespace=kube-system- 查看
kube-dns是否运行
kubectl get pods --namespace=kube-system -l k8s-app=kube-dns- 查看对应 DNS pods 是否运行
kubectl logs --namespace=kube-system -l k8s-app=kube-dns- 查看服务运行日志
检查 DNS 端点公开情况
kubectl get endpoints kube-dns --namespace=kube-system- 位于 cluster-cidr 范围内
检查 CoreDNS 权限
- CoreDNS 必须能够列出 service 和 endpoint 相关的资源来正确解析服务名称
kubectl describe clusterrole system:coredns -n kube-system
预期输出结果
- 缺失权限时编辑 ClusterRole 来添加
kubectl edit clusterrole system:coredns -n kube-system
部分 DNS 已知问题
部分 Linux 发行版如 Ubuntu 本地 DNS 解析器 systemd-resolved 覆盖 /etc/resolv.conf 内容,可能导致在上游服务器中解析域名产生转发环
- 可以手动指定 kubelet 的
--resolv-conf标志为正确的resolv.conf systemd-resolved对应路径为/run/systemd/resolve/resolv.conf
- 也可以禁用本地 DNS 解析器 stub
resolvectl status | grep resolv.confresolv.conf mode: stub代表当前配置了127.0.0.53为域名服务器vim /etc/systemd/resolved.conf#DNSStubListener=yes取消注释并改为DNSStubListener=no即可禁用systemctl restart systemd-resolved
如何禁用 nameserver 127.0.0.53
Linux 的 libc 默认将 DNS nameserver 记录限制为 3, 而 Kubernetes 需要使用 1 条 nameserver 记录
- 如果本地的安装已经使用了 3 个
nameserver,那么其中有些条目将会丢失
- 可以手动指定 kubelet 的
--resolv-conf标志为正确的resolv.conf systemd-resolved对应路径为/run/systemd/resolve/resolv.conf
- 也可以运行
dnsmasq,以提供更多nameserver条目
使用 Alpine 3.17 或更早版本作为你的基础镜像,DNS 可能会由于 Alpine 的设计问题而无法工作
- 将镜像升级到 Alpine 3.18 或更高版本
卸载 k3s
如果计划在卸载并重新安装后将节点重新加入现有集群,请务必从集群中删除该节点,以确保删除节点密钥 Secret
kubectl get nodes -o wide
- 停止调度并清理,最后删除节点
kubectl cordon <node-name>kubectl drain <node-name> --delete-emptydir-data --ignore-daemonsetskubectl delete node <node-name>
- 还没清理干净的话可以删掉包含节点密钥在内的整个 node 文件夹
rm -rf /etc/rancher/node
全部删除
k3s kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | while read node; do echo "Deleting node: $node" k3s kubectl delete node $node done
/usr/local/bin/k3s-uninstall.sh- 服务器
/usr/local/bin/k3s-agent-uninstall.sh- 代理节点
rm ~/.kube/config- 本地访问集群配置文件
docker ps --filter "name=k8s_" -q | xargs -r -n 1 -P 10 docker stop && docker container prune -f- 如果容器运行时为 docker,需要清理 k8s 剩余容器
- 清理已停止容器
配置 k3s 安装
k3s 安装配置选项
参考资料
部分配置可选项
--cluster-init可选,使用嵌入式 etcd 初始化新集群,默认使用嵌入式 SQLite
--datastore-endpoint 使用外部 etcd 集群
--datastore-endpoint="https://etcd-node1.example.com:2379,https://etcd-node2.example.com:2379,https://etcd-node3.example.com:2379"
- 如果设置了 ssl,则需要添加证书及密钥文件
-
--datastore-cafile="~/.step/certs/root_ca.crt" \\ --datastore-certfile="/usr/local/share/stepca-certificates/client.crt" \\ --datastore-keyfile="/usr/local/share/stepca-certificates/client.key"
定制服务器角色 --disable-etcd, --disable-apiserver, --disable-scheduler, --disable-controller-manager
- 默认为全功能服务器
- 仅 etcd 角色
--cluster-init --disable-apiserver --disable-controller-manager --disable-scheduler
- 仅 control-plane 角色
--disable-etcd- 不能是集群第一个服务器,集群内必须已有 etcd 角色
--cluster-domain=example.internal- 指定集群 domain
- 可选,不运行任何用户工作负载的专用控制平面
--node-taint CriticalAddonsOnly=true:NoExecute
--tls-san=<FIXED_IP>可选,如果需要使用固定的注册地址
--node-taint "key=value:NoSchedule"可选,配置该节点为非工作负载节点
有些配置标志在所有 Server 节点中必须是相同的
- 网络相关标志:
--cluster-dns、--cluster-domain、--cluster-cidr、--service- cidr
- 控制某些组件部署的标志:
--disable-helm-controller、--disable-kube-proxy、--disable-network-policy和任何传递给--disable的组件
- 功能相关标志:
--secrets-encryption
配置镜像加速及私人镜像
vim /etc/rancher/k3s/registries.yaml
进阶:lxc 安装 k3s 传递选项
创建 rc.local 脚本
vim /etc/rc.local
- 由于 LXC 的特殊性,某些设备文件和挂载选项可能与传统的虚拟机或物理服务器不同。通过运行这个脚本,可以确保 Kubernetes 的组件能够正确地访问所需的设备文件,并且挂载点能够正确地传播
检查脚本是否执行成功
findmnt / -o TARGET,OPT-FIELDS,PROPAGATION
ls -al /dev/kmsg
添加 kubelet 选项确保在用户态下正确启动 k3s
curl -sfL https://get.k3s.io | sh -s - server --docker\ --kubelet-arg=feature-gates=KubeletInUserNamespace=true \ --kube-controller-manager-arg=feature-gates=KubeletInUserNamespace=true \ --kube-apiserver-arg=feature-gates=KubeletInUserNamespace=true \ ...- 其余选项根据自身情况添加
进阶:k3s DNS 配置
- 参考资料
- https://kubernetes.io/zh-cn/docs/tasks/administer-cluster/dns-debugging-resolution/
GitHubHow to use a private DNS with k3s · k3s-io k3s · Discussion #7822How to use a private DNS with k3s · k3s-io k3s · Discussion #7822
Trying to configure k3s to use my private dns server 10.10.0.243 as the forward/upstream default to resolve. I fail to do so, my pods cannot resolve the private domains, only public ones. Using ubu...
- https://www.cnblogs.com/gongzb/p/18350950
指定集群 DNS 服务器和集群 domain
--cluster-dns=192.168.1.123- 需要设置负载均衡
--cluster-domain=k3s-cluster.example.local- 默认为 cluster.local
使用当前主机的 resolv.conf 文件
--kubelet-arg=resolv-conf=/etc/resolv.conf
检查是否已使用主机 resolv.conf 文件
kubectl debug -it $(kubectl get pod -n kube-system | grep coredns | awk '{print $1}') -n kube-system --image=busybox:1.28 --target=coredns -- cat /etc/resolv.conf- 在
corednsPod 中启动一个临时busybox容器并执行cat /etc/resolv.conf
- 检查上游 dns
kubectl run -ti --rm alpine-musl --image=giantswarm/tiny-tools:3.12 --restart=Never --timeout=5s -- nslookup kuberneteskubectl run -ti --rm busybox-libc --image=busybox:1.35.0-glibc --restart=Never --timeout=5s -- nslookup kubernetes
进阶:配置 contianerd 运行时
- 参考资料
vim /var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.tmpl
- 如果 containerd 版本在 1.7 及之前, 文件名应为
config.toml.tmpl
- 在模板的基础上修改
进阶:启用嵌入式 etcd、IPv4/IPv6 双栈并设置 wiregurad-native 作为 Flannel 后端
- 当定义以 IPv6 作为主要系列的 cluster-cidr 和 service-cidr 时,应显式设置所有集群成员的 node-ip,将节点所需的 IPv6 地址作为第一个地址。默认情况下,kubelet 始终使用 IPv4 作为主要地址族
如果 ipv6 默认路由是通过路由器通告 (RA) 设置,需要 net.ipv6.conf.all.accept_ra=2
- 请注意,接受 RA 可能会增加中间人攻击的风险
vim /etc/sysctl.conf- 添加
net.ipv6.conf.all.accept_ra = 2
sysctl --system- 重新加载后生效
sysctl net.ipv6.conf.all.accept_ra
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | sh -s - server --cluster-init --flannel-backend=wireguard-native --cluster-cidr=2001:cafe:42::/56,10.42.0.0/16 --service-cidr=2001:cafe:43::/112,10.43.0.0/16 --node-ip=<host-ipv6>,<host-ipv4>- 自行修改 ipv6 前缀和
--node-ip为对应宿主机 ip - 均需要为静态地址,否则变更 ip 地址后会找不到 node,需要重新加载集群
- 使用未公开路由的 ipv6 地址时,可以使用
--flannel-ipv6-masq选项来启用 IPv6 NAT
其他系统/方式安装 k3s
win11 安装 k3s
实际上是 wsl 使用 alpine 安装 k3s(终端使用 Windows Terminal)
windows 11 系统安装 wsl 并导入 alpine 镜像
wsl --install
([System.Net.WebClient]::new()).DownloadFile("https://github.com/antoinemartin/PowerShell-Wsl-Manager/releases/latest/download/miniwsl.alpine.rootfs.tar.gz", "$PWD/Downloads/alpine.tgz")- 下载
alpine.tgz到下载文件夹
wsl --import myk3s . ./Downloads/alpine.tgz- wsl 安装 alpine
- 启动 myk3s 并安装 k3s
wsl -d myk3s
macos 安装 k3s
参考资料
不直接支持 kubenetes,需要通过 multipass 运行虚拟机
brew install --cask multipass
(可选) 配置 cloud-init 配置文件
- 参考资料
- multipass 默认用户必须为 ubuntu, 不要修改
vim ~/.config/k3sserver-config.yaml
vim ~/.config/k3sagent-config.yaml
创建 k3s 虚拟机,桥接接口并分配内存及磁盘空间
- 查看可用网络
multipass networks --format yaml
- 假设 en0 为可用接口, 设置首选网络
multipass set local.bridged-network=en0
- 根据实际配置调整参数
multipass launch --name k3sserver --bridged --cpus 4 --memory 4G --disk 60G --cloud-init ~/.config/k3sserver-config.yamlmultipass launch --name k3sagent --bridged --cpus 2 --memory 2G --disk 40G --cloud-init ~/.config/k3sagent-config.yaml
创建完毕后查看虚拟机信息
multipass list
multipass info k3sserver
multipass get local.k3sserver.bridged
进入 k3s 内部
multipass shell k3sserver
设置 ubuntu 用户和 ssh-server
sudo passwd ubuntu
echo "<pubkey>" > ~/.ssh/authorized_keys
sudo apt install -y openssh-server
systemctl enable --now ssh
- 随后与 Ubunut 安装 k3s 一致 (默认为 ubuntu)
后续如果需要调整配置
multipass stop k3sserver
multipass set local.k3sserver.memory=6G
multipass start k3sserver
multipass stop --all
修改 multipass 虚拟机静态 IP
multipass shell k3sserver
sudo vim /etc/netplan/50-cloud-init.yaml
- 根据情况自行修改 iface
sudo netplan apply
虚拟机重启后显示 unknown 状态
- stop 对应主机之后重启, 还没法恢复需要进入排障流程
虚拟机重启后无法连接到对应主机显示 no route to host
参考资料
macOS 中的网络扩展控制协议层 (Network Extension Control Protocol layer) 阻止了网络连接
- 前往“设置”>“隐私和安全”>“本地网络”,并确保用于运行 Multipass CLI 的应用程序已启用,例如 Terminal、Hyper、Ghostty、Iterm2 等
- 如果是 vscode-remote 远程连接, 则需要放行 Visual Studio code
- https://github.com/microsoft/vscode-remote-release/issues/10441
- 在 VSCode 上打开终端, ping 一个本地网络地址即可触发提示
- 注意, 不是在 vscode-remote 上执行, 在本地环境直接执行
- 如果没有触发提示, 尝试删掉已有 VSCode 重新下载安装并执行上述步骤
确保 dhcp 服务已启动
sudo launchctl start com.apple.bootpd
sudo launchctl load -w /System/Library/LaunchDaemons/bootps.plist- 上面失败时
防火墙放行
/usr/libexec/ApplicationFirewall/socketfilterfw --add /usr/libexec/bootpd
/usr/libexec/ApplicationFirewall/socketfilterfw --unblock /usr/libexec/bootpd
multipass 移除虚拟机
multipass delete k3sserver
multipass purge
- 还有一种方法是安装 Rancher Desktop,缺点是比较耗资源
通过 rancher 套件安装 k3s 集群
- 有可视化 webui,缺点是资源消耗较大
- 变量
KUBECONFIG默认位置 - Windows
KUBECONFIG=%USERPROFILE%\.kube\config
通过 k3d (docker-k3s)安装 k3s
- linux, mac, windows 均可用
- mac
brew install k3d- windows
scoop install k3d
- Author:白鸟3
- URL:https://blog.kun2peng.top/operation/k8s_k3s
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
