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
相关推荐
DianSan_ERP10 小时前
电商架构演进:如何在高并发场景下实现多平台API的标准化履约?
运维·前端·网络·安全·架构·自动化
恒53910 小时前
Linux文件系统I
linux·运维·服务器
阿成学长_Cain10 小时前
Linux ipcs 命令超全详解:查看共享内存 / 消息队列 / 信号量,IPC 运维必备
linux·运维·服务器·网络·数据库
黯然神伤88810 小时前
AlmaLinux设置软件下载源
linux·alma
青瓦梦滋11 小时前
协议定制/序列化-反序列化(Linux视角)
linux·服务器·网络·c++
运维老郭13 小时前
【K8s运维实战】Kubernetes临时存储卷实战:emptyDir核心用法与gitRepo弃用迁移指南
运维·云原生·kubernetes
珠海西格电力13 小时前
云边端协同架构:零碳园区管理系统的技术底座
大数据·运维·人工智能·算法·架构·能源
阿成学长_Cain14 小时前
Linux dirs命令详解|Bash目录堆栈管理快速切换目录实战教程
linux·运维·前端·数据库
小羊Yveesss14 小时前
2026年微信小程序后端怎么搭建?后台、数据、接口和运维怎么选
运维·微信小程序·小程序
ICECREAM15 小时前
Linux 进程间通讯(IPC)——总结
linux