问题描述

K8S部署服务拉取镜像失败:ImagePullBackOff
K8S拉取镜像提示:Failed to pull image “IP:PORT/zcy-project/nginx:1.16.1”: rpc error: code = Unknown desc = Error response from daemon: unauthorized: unauthorized to access repository: zcy-project/nginx, action: pull: unauthorized to access repository:
使用命令部署服务:

kubectl run nginx-deployment-6 --image=192.168.10.136:8080/zcy-project/nginx:1.16.2 --port=80 --replicas=2
kubectl get pod
kubectl describe pod nginx-deployment-6

查看部署结果:
在这里插入图片描述
这里的状态STATUS:ImagePullBackOff
在这里插入图片描述
可以看到错误提示:

Failed to pull image “IP:PORT/zcy-project/nginx:1.16.1”: rpc error: code = Unknown desc = Error response from daemon: unauthorized: unauthorized to access repository: zcy-project/nginx, action: pull: unauthorized to access repository:

问题排查:

  1. 用docker login测试过账户、密码、Registry、镜像均无误
docker login 192.168.10.136:8080
  1. 每个Node都用docker直接拉取:
docker pull 192.168.10.136:8080/zcy-project/nginx:1.16.1
  1. 使用imagePullSecrets
    创建一个secrete资源对象。以下示例中 registry-harbor 为secret资源对象的名称。除了邮箱可以随便填,其它三个需要使用实际的harbor地址和账号。
kubectl create secret docker-registry registry-harbor \
    --docker-server=192.168.10.136 \
    --docker-username=admin \
    --docker-password='123.com' \
    --docker-email=foo@bar.com
  1. 在pod的yaml定义文件中使用 imagePullSecrets 引用secret
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-6
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
      env: uat
  template:
    metadata:
      labels:
      	app: nginx
        env: uat
    spec:
      containers:
      - name: nginx
        image: 192.168.10.136:8080/zcy-project/nginx:1.16.2
        ports:
        - containerPort: 80
      imagePullSecrets:
      - name: registry-harbor
  1. 创建pod测试能否正常拉取
    kubectl create -f xxx.yaml
GitHub 加速计划 / ha / harbor
23.24 K
4.67 K
下载
Harbor 是一个开源的容器镜像仓库,用于存储和管理 Docker 镜像和其他容器镜像。 * 容器镜像仓库、存储和管理 Docker 镜像和其他容器镜像 * 有什么特点:支持多种镜像格式、易于使用、安全性和访问控制
最近提交(Master分支:1 个月前 )
c97253f6 11 小时前
8d52a633 Signed-off-by: tostt <tostt@users.noreply.github.com> 1 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐