rancher安装--针对报错API Aggregation not ready

报错API Aggregation not ready

准备一个Dockerfile
c 复制代码
FROM rancher/rancher:stable

# 重命名原始入口脚本
RUN mv /usr/bin/entrypoint.sh /usr/bin/entrypoint-original.sh

# 创建包装入口脚本:在 k3s 启动前写入镜像源配置
RUN echo '#!/bin/sh'                                                         >  /usr/bin/entrypoint.sh && \
    echo 'mkdir -p /var/lib/rancher/k3s/agent/etc'                           >> /usr/bin/entrypoint.sh && \
    echo 'mkdir -p /etc/rancher/k3s'                                         >> /usr/bin/entrypoint.sh && \
    echo 'cat > /var/lib/rancher/k3s/agent/etc/registries.yaml << REGEOF'    >> /usr/bin/entrypoint.sh && \
    echo 'mirrors:'                                                          >> /usr/bin/entrypoint.sh && \
    echo '  "docker.io":'                                                    >> /usr/bin/entrypoint.sh && \
    echo '    endpoint:'                                                     >> /usr/bin/entrypoint.sh && \
    echo '      - "https://docker.m.daocloud.io"'                           >> /usr/bin/entrypoint.sh && \
    echo '      - "https://dockerproxy.com"'                                >> /usr/bin/entrypoint.sh && \
    echo '      - "https://mirror.aliyuncs.com"'                            >> /usr/bin/entrypoint.sh && \
    echo '  "rancher":'                                                      >> /usr/bin/entrypoint.sh && \
    echo '    endpoint:'                                                     >> /usr/bin/entrypoint.sh && \
    echo '      - "https://docker.m.daocloud.io"'                           >> /usr/bin/entrypoint.sh && \
    echo '      - "https://dockerproxy.com"'                                >> /usr/bin/entrypoint.sh && \
    echo '  "ghcr.io":'                                                     >> /usr/bin/entrypoint.sh && \
    echo '    endpoint:'                                                     >> /usr/bin/entrypoint.sh && \
    echo '      - "https://docker.m.daocloud.io"'                           >> /usr/bin/entrypoint.sh && \
    echo '  "registry.k8s.io":'                                             >> /usr/bin/entrypoint.sh && \
    echo '    endpoint:'                                                     >> /usr/bin/entrypoint.sh && \
    echo '      - "https://docker.m.daocloud.io"'                           >> /usr/bin/entrypoint.sh && \
    echo '  "quay.io":'                                                     >> /usr/bin/entrypoint.sh && \
    echo '    endpoint:'                                                     >> /usr/bin/entrypoint.sh && \
    echo '      - "https://docker.m.daocloud.io"'                           >> /usr/bin/entrypoint.sh && \
    echo 'REGEOF'                                                            >> /usr/bin/entrypoint.sh && \
    echo 'cp /var/lib/rancher/k3s/agent/etc/registries.yaml /etc/rancher/k3s/registries.yaml' >> /usr/bin/entrypoint.sh && \
    echo 'exec /usr/bin/entrypoint-original.sh "$@"'                         >> /usr/bin/entrypoint.sh && \
    chmod +x /usr/bin/entrypoint.sh

镜像构建运行

c 复制代码
# 1. 构建新镜像
docker build -t rancher-cn:latest .

# 2. 停掉旧容器、清理数据
docker stop rancher 2>/dev/null
docker rm rancher 2>/dev/null
rm -rf /opt/rancher/*

# 3. 运行
docker run -d --restart=unless-stopped \
  -p 80:80 -p 443:443 \
  --privileged \
  -v /opt/rancher:/var/lib/rancher \
  --name rancher \
  rancher-cn:latest

# 4. 等几秒后验证配置是否生效
sleep 5
docker exec rancher cat /var/lib/rancher/k3s/agent/etc/registries.yaml
docker exec rancher cat /etc/rancher/k3s/registries.yaml

# 5. 观察日志
docker logs -f rancher

检查确认

c 复制代码
# 等待 3-5 分钟后检查
docker exec rancher kubectl get pods -A
# coredns 应该变成 Running
docker exec rancher kubectl get pods -n kube-system
相关推荐
A小辣椒16 小时前
TShark:Wireshark CLI 功能
linux
A小辣椒20 小时前
TShark:基础知识
linux
AlfredZhao1 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao2 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334662 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪2 天前
linux 拷贝文件或目录到指定的位置
linux
大树883 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠3 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质3 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
bush43 天前
嵌入式linux学习记录十四、术语
linux·嵌入式