国内快速安装K3s与KubeSphere

1. K3s
文档:https://docs.k3s.io/zh/quick-start

1.1. 执行如下命令快速安装
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn INSTALL_K3S_SKIP_SELINUX_RPM=true sh -s - \
--system-default-registry "registry.cn-hangzhou.aliyuncs.com"

1.1. 查看K3S状态
systemctl status k3s -l
1.2 查看 K3S Pods状态
kubectl get pods -A
1.3. 启动完成
2. KubeSphere
文档:https://www.kubesphere.io/zh/docs/v3.4/quick-start/minimal-kubesphere-on-k8s/

2.1. 执行如下命令安装
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/kubesphere-installer.yaml
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/cluster-configuration.yaml
如果下载不下来,先在本地将配置文件下载下来再传到服务器,在执行 kubectl apply -f xxx.yaml即可2.2 查看安装日志
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f

可以看到拉取镜像失败了,执行如下命令,修改镜像源

kubectl -n kubesphere-system patch cc ks-installer -p '{"spec":{"local_registry":"registry.cn-beijing.aliyuncs.com"}}' --type=merge

kubectl -n kubesphere-system set image deploy ks-installer installer=registry.cn-beijing.aliyuncs.com/kubesphereio/ks-installer:v3.4.1

根据日志可以看到修改成功,耐心等待3分钟在查看日志。

忽略中间日志,看到如下就成功了。

查看k3s pod进程信息

2.3 访问KubeSphere
KubeSphere地址:http://ip:30880/login
默认账户:admin/P@88w0rd

2.4 安装成功
3 K3s使用本地docker镜像库遇到的问题,在拉取本地镜像时,会有如下错误,
 Failed to pull image "IP:5000/image:latest": failed to pull and unpack image "IP:5000/image:latest": failed to resolve reference "IP:5000/image:latest": failed to do request: Head "https://ip:5000/v2/image/manifests/latest": http: server gave HTTP response to HTTPS client

3.1 给K3s添加registries.yaml配置
 vim /etc/rancher/k3s/registries.yaml
 # 将如下内容添加至该文件即可
 mirrors:
  "ip:5000":
    endpoint:
      - "http://ip:5000"

                        

posted @ 2025-03-16 21:27  木子欢儿  阅读(725)  评论(0)    收藏  举报