当前位置: 首页 > news >正文

rancher 解决拉取dashboard-shell镜像失败的问题

问题背景

在 Kubernetes 集群中部署 Rancher 后,点击右上角的 "Shell" 按钮时,Rancher 会动态创建一个 dashboard-shell-xxxxx Pod,用于提供 Web 终端功能。然而,由于默认镜像 rancher/shell:v0.1.21 托管在 Docker Hub(docker.io),国内用户可能会遇到拉取失败的问题,报错如下:

Failed to pull image "rancher/shell:v0.1.21": rpc error: 
code = Unknown desc = failed to pull and unpack image "docker.io/rancher/shell:v0.1.21": 
failed to resolve reference "docker.io/rancher/shell:v0.1.21": 
failed to do request: Head "https://registry-1.docker.io/v2/rancher/shell/manifests/v0.1.21": dial tcp 199.59.149.235:443: i/o timeout

或者,如果你已经替换为私有仓库但仍然遇到 401 Unauthorized 错误:

Failed to pull image "uhub.service.ucloud.cn/sre-paas/rancher/shell:v0.1.21": failed to authorize: 401 Unauthorized

解决方案

1. 修改 Rancher 默认 Shell 镜像

Rancher 通过 MutatingWebhookConfiguration 动态注入 Shell Pod 的配置,我们可以修改其默认镜像地址。

步骤 1:查找 Rancher 的 shell-image 设置
kubectl get settings.management.cattle.io shell-image -n cattle-system -o yaml

如果不存在,可以手动创建:

kubectl apply -f - <<EOF
apiVersion: management.cattle.io/v3
kind: Setting
metadata:
  name: shell-image
  namespace: cattle-system
value: "your-mirror-registry.com/rancher/shell:v0.1.21"
EOF
步骤 2:更新镜像地址
kubectl edit settings.management.cattle.io shell-image -n cattle-system

修改 value 为你的镜像地址:

value: "uhub.service.ucloud.cn/sre-paas/rancher/shell:v0.1.21"
步骤 3:重启 Rancher 使配置生效
kubectl rollout restart deployment rancher -n cattle-system

2. 配置 imagePullSecrets 拉取私有镜像

如果镜像仓库需要认证(如 UCloud、Harbor),需创建 docker-registry Secret 并绑定到 ServiceAccount

步骤 1:创建 docker-registry Secret
kubectl create secret docker-registry ucloud-regcred \
  --docker-server=uhub.service.ucloud.cn \
  --docker-username=<your-username> \
  --docker-password=<your-password> \
  -n cattle-system
步骤 2:绑定到 default ServiceAccount
kubectl patch serviceaccount default \
  -p '{"imagePullSecrets": [{"name": "ucloud-regcred"}]}' \
  -n cattle-system
验证是否生效
kubectl get pod <shell-pod-name> -n cattle-system -o yaml | grep imagePullSecrets

3. 检查 Pod 是否正常启动

如果仍然失败,检查 Pod 事件:

kubectl describe pod <shell-pod-name> -n cattle-system

常见问题:

  • 镜像路径错误(确认 uhub.service.ucloud.cn/sre-paas/rancher/shell:v0.1.21 是否存在)

  • Secret 未正确绑定(检查 kubectl get sa default -n cattle-system -o yaml

  • 网络策略限制(检查 Calico/NetworkPolicy 是否阻止访问镜像仓库)

总结

问题解决方案
镜像拉取超时修改 shell-image 设置,使用国内镜像源
401 Unauthorized创建 imagePullSecrets 并绑定到 default ServiceAccount
Pod 未继承 imagePullSecrets检查 MutatingWebhookConfiguration 是否覆盖配置

通过以上方法,你应该能成功解决 Rancher Dashboard Shell 镜像拉取失败的问题。如果仍有疑问,欢迎在评论区交流! 🚀

相关文章:

  • Wincc管对象的使用
  • 【ESP32-microros(vscode-Platformio)】
  • Go 语言中的 package main、 func main() 和main.go的使用规范
  • 浮点数比较在Eigen数学库中的处理方法
  • AI前沿周报:2025年3月技术深度解析
  • Express中间件(Middleware)详解:从零开始掌握(1)
  • 在Java项目中,引入【全局异常处理器】
  • HarmonyOS-ArkUI V2装饰器-@Once
  • 第一节:React 基础篇-React虚拟DOM原理及Diff算法优化策略
  • 【Web功能测试】注册与登录功能测试用例设计深度解析
  • (十四)安卓开发中的RecyclerView详解
  • Python 和 JavaScript两种语言的相似部分-由DeepSeek产生
  • 计算机操作系统-【死锁】
  • 信奥赛之c++基础(循环结构之for循环)
  • Java常用工具算法-6--秘钥托管云服务3--微软zure Key Vault
  • 第5章,将 Toy IR 程序部分地下降到更低层的 dialect 以便优化
  • 【Grok 大模型深度解析】第二期:架构探秘与训练哲学
  • 在AMGX中使用MPI加载自定义分布式矩阵和向量
  • 自定义函数:为接口开发增添灵活性 - Apipost 的独特优势
  • [特殊字符] 各领域 Dummy 开关实现方式大集合
  • 零陵做网站/外贸网站营销推广
  • 免费个人名片生成器/seo哪里可以学
  • 云南省文山州网站建设/推广计划怎么做推广是什么
  • 通辽市 做网站/企业高管培训课程有哪些
  • 贵阳网站备案/爱站工具包的模块
  • 中国免费素材网站/搜索引擎有哪些网站