我正在通过一个实验室来演示如何在IBM上设置Kubernetes和CLI。
我有Kubernetes集群设置和容器注册表。我登录到CLI上的IBM和Container。图像已经被创建并被推送。
我可以使用命令命令使用图像创建一个荚,使用:
kubectl create -f hello-world-create.yaml其中的yaml文件看起来像:
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但是,当我尝试对同一个映像运行声明性命令时
kubectl apply -f hello-world-apply.yaml在其中,yaml文件看起来像
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状态。
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显然,该命令没有读取对图像的访问权限,但我已经成功地使用
ibmcloud cr login并可以使用命令式create命令部署pod。
我已经看过文档,但无法确定我忽略了哪一步。授予声明式apply命令适当访问权限所需的额外步骤是什么?
正在运行
kubectl get secrets -n default | grep "icr-io"给出
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发布于 2020-08-19 05:19:46
这是我所做的和预期的工作,
如您所见,all-icr-io是集群中提供的默认图像提取秘密。不知道你为什么要使用icr
默认情况下,images集群被设置为使用默认名称空间中的秘密
all-icr-io从中的帐户名称空间中只提取图像。
检查这里的文件以将现有的图像提取秘密复制到非默认命名空间。
所以,我的hello-world-create看起来像这样
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是
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文件后,结果如下

发布于 2020-08-18 16:25:19
查看身份验证,了解哪些可能是错误的细节。有些事情需要检查:
kubectl get secrets -n default | grep "icr-io"显示了什么秘密吗?如果没有,请按照上面的文档链接来修复它。https://stackoverflow.com/questions/63472449
复制相似问题