首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用声明性命令创建Kubernetes Pod时获得ErrImagePull : 401未经授权

在使用声明性命令创建Kubernetes Pod时获得ErrImagePull : 401未经授权
EN

Stack Overflow用户
提问于 2020-08-18 16:03:29
回答 2查看 17.8K关注 0票数 3

我正在通过一个实验室来演示如何在IBM上设置Kubernetes和CLI。

我有Kubernetes集群设置和容器注册表。我登录到CLI上的IBM和Container。图像已经被创建并被推送。

我可以使用命令命令使用图像创建一个荚,使用:

代码语言:javascript
复制
kubectl create -f hello-world-create.yaml

其中的yaml文件看起来像:

代码语言:javascript
复制
apiVersion: v1
kind: Pod
metadata:
  name: hello-world
spec:
  containers:
  - name: hello-world
    image: us.icr.io/earlyprogramimages/hello-world:1
    ports:
    - containerPort: 80
  imagePullSecrets:
  - name: icr

但是,当我尝试对同一个映像运行声明性命令时

代码语言:javascript
复制
kubectl apply -f hello-world-apply.yaml

在其中,yaml文件看起来像

代码语言:javascript
复制
apiVersion: apps/v1
kind: Deployment
metadata:
  generation: 1
  labels:
    run: hello-world
  name: hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      run: hello-world
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        run: hello-world
    spec:
      containers:
      - image: us.icr.io/earlyprogramimages/hello-world:1
        imagePullPolicy: Always
        name: hello-world
        ports:
        - containerPort: 80
          protocol: TCP
      imagePullSecrets:
      - name: icr
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      securityContext: {}
      terminationGracePeriodSeconds: 30

我得到事件堆栈所在的每个豆荚的ErrImagePull状态。

代码语言:javascript
复制
Successfully assigned default/hello-world-6fd8bd67dc-79gbz to xx.xx.xx.xx
Pulling image "us.icr.io/earlyprogramimages/hello-world:1

Failed to pull image "us.icr.io/earlyprogramimages/hello-world:1": rpc error: code = Unknown desc = failed to pull and unpack image "us.icr.io/earlyprogramimages/hello-world:1": failed to resolve reference "us.icr.io/earlyprogramimages/hello-world:1": failed to authorize: failed to fetch anonymous token: unexpected status: 401 Unauthorized

Error: ErrImagePull

显然,该命令没有读取对图像的访问权限,但我已经成功地使用

代码语言:javascript
复制
ibmcloud cr login

并可以使用命令式create命令部署pod。

我已经看过文档,但无法确定我忽略了哪一步。授予声明式apply命令适当访问权限所需的额外步骤是什么?

正在运行

代码语言:javascript
复制
kubectl get secrets -n default | grep "icr-io"

给出

代码语言:javascript
复制
kubectl get secrets -n default | grep "icr-io"
all-icr-io            kubernetes.io/dockerconfigjson        1      167m
default-au-icr-io     kubernetes.io/dockerconfigjson        1      167m
default-de-icr-io     kubernetes.io/dockerconfigjson        1      167m
default-icr-io        kubernetes.io/dockerconfigjson        1      167m
default-jp-icr-io     kubernetes.io/dockerconfigjson        1      167m
default-uk-icr-io     kubernetes.io/dockerconfigjson        1      167m
default-us-icr-io     kubernetes.io/dockerconfigjson        1      167m
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-19 05:19:46

这是我所做的和预期的工作,

如您所见,all-icr-io是集群中提供的默认图像提取秘密。不知道你为什么要使用icr

默认情况下,images集群被设置为使用默认名称空间中的秘密all-icr-io从中的帐户名称空间中只提取图像。

检查这里的文件以将现有的图像提取秘密复制到非默认命名空间。

所以,我的hello-world-create看起来像这样

代码语言:javascript
复制
apiVersion: v1
kind: Pod
metadata:
  name: hello-world
spec:
  containers:
  - name: hello-world
    image: us.icr.io/mods15/hello-world:1
    ports:
    - containerPort: 80
  imagePullSecrets:
  - name: all-icr-io

我的hello-world-apply.yaml

代码语言:javascript
复制
apiVersion: apps/v1
kind: Deployment
metadata:
  generation: 1
  labels:
    run: hello-world
  name: hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      run: hello-world
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        run: hello-world
    spec:
      containers:
      - image: us.icr.io/mods15/hello-world:1
        imagePullPolicy: Always
        name: hello-world
        ports:
        - containerPort: 80
          protocol: TCP
      imagePullSecrets:
      - name: all-icr-io
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      securityContext: {}
      terminationGracePeriodSeconds: 30

成功配置yaml文件后,结果如下

票数 6
EN

Stack Overflow用户

发布于 2020-08-18 16:25:19

查看身份验证,了解哪些可能是错误的细节。有些事情需要检查:

  1. 您是否有允许您访问容器注册中心的IAM策略?
  2. kubectl get secrets -n default | grep "icr-io"显示了什么秘密吗?如果没有,请按照上面的文档链接来修复它。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63472449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档