报错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