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
相关推荐
能喵烧香1 小时前
鸿潮万相:全品类OpenHarmony定制发行版全景详解
linux·系统架构·开源
风曦Kisaki1 小时前
#Linux Shell 编程入门 Day04:正则表达式(egrep模糊匹配)与 sed流式编辑器
linux·正则表达式·编辑器
海盗船长没有船y3 小时前
避坑指南:Ubuntu 启动报错 “Unable to mount root fs“ 的深层诱因与修复
linux·ubuntu·故障排除·dkms
东风微鸣3 小时前
Ubuntu 26.04 游戏配置指南:魔兽争霸3 Dota1
linux·ubuntu·游戏
郝亚军3 小时前
在Ubuntu 2.04上如何按照x86_64架构编译libmodbus库
linux·运维·ubuntu
小黑蛋学java3 小时前
Ubuntu Docker 安装手册
linux·ubuntu·docker
Tim风声(网络工程师)9 小时前
排查内网互联网访问流程
运维·服务器·网络
坚持就完事了10 小时前
Linux中如何添加环境变量
linux·运维·服务器
AC赳赳老秦11 小时前
政企内网落地:OpenClaw 离线环境深度适配方案,无外网场景下本地化模型对接与全功能使用
java·大数据·运维·python·自动化·deepseek·openclaw