如何修复“无法拉取图像"在microk8s上 [英] How to fix "Failed to pull image" on microk8s
问题描述
我正在尝试遵循docker入门指南,但是当您必须使用kuberetes时,我会陷入困境.我正在使用microk8s创建集群.
Im trying to follow the get started docker's tutorials, but I get stuck when you have to work with kuberetes. I'm using microk8s to create the clusters.
我的Dockerfile:
My Dockerfile:
FROM node:6.11.5WORKDIR /usr/src/app
COPY package.json .
RUN npm install
COPY . .
CMD [ "npm", "start" ]
我的bb.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: bb-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
bb: web
template:
metadata:
labels:
bb: web
spec:
containers:
- name: bb-site
image: bulletinboard:1.0
---
apiVersion: v1
kind: Service
metadata:
name: bb-entrypoint
namespace: default
spec:
type: NodePort
selector:
bb: web
ports:
- port: 8080
targetPort: 8080
nodePort: 30001
我用
docker image build -t bulletinboard:1.0 .
然后我用以下方法创建pod和服务:
And I create the pod and the service with:
microk8s.kubectl apply -f bb.yaml
已创建吊舱,但是,当我使用
The pod is created, but, when I look for the state of my pods with
microk8s.kubectl get all
它说:
NAME READY STATUS RESTARTS AGE
pod/bb-demo-7ffb568776-6njfg 0/1 ImagePullBackOff 0 11m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/bb-entrypoint NodePort 10.152.183.2 <none> 8080:30001/TCP 11m
service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 4d
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/bb-demo 0/1 1 0 11m
NAME DESIRED CURRENT READY AGE
replicaset.apps/bb-demo-7ffb568776 1 1 0 11m
此外,当我在kubernetes仪表板上查找它时,它会说:
Also, when I look for it at the kubernetes dashboard it says:
无法提取映像"bulletinboard:1.0":rpc错误:代码=未知desc =未能解析映像"docker.io/library/bulletinboard:1.0":无可用的注册表端点:拒绝提取访问,存储库不存在或可能需要授权:服务器消息:不足_作用域:授权失败
Failed to pull image "bulletinboard:1.0": rpc error: code = Unknown desc = failed to resolve image "docker.io/library/bulletinboard:1.0": no available registry endpoint: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
问:为什么会出现此错误?我只是在遵循本教程,没有跳过任何内容.
我已经使用docker登录了.
Im already logged with docker.
推荐答案
您需要将此本地构建的映像推送到Docker Hub注册表.为此,如果您还没有一个Docker Hub帐户,则需要创建一个.
You need to push this locally built image to the Docker Hub registry. For that, you need to create a Docker Hub account if you do not have one already.
完成该操作后,您需要从命令行登录Docker Hub.
Once you do that, you need to login to Docker Hub from your command line.
docker login
标记您的映像,以便将其转到您的Docker Hub存储库.
Tag your image so it goes to your Docker Hub repository.
docker tag bulletinboard:1.0 <your docker hub user>/bulletinboard:1.0
将图像推送到Docker Hub
Push your image to Docker Hub
docker push <your docker hub user>/bulletinboard:1.0
更新yaml文件以反映Docker Hub上的新映像存储库.
Update the yaml file to reflect the new image repo on Docker Hub.
spec:
containers:
- name: bb-site
image: <your docker hub user>/bulletinboard:1.0
spec:
containers:
- name: bb-site
image: <your docker hub user>/bulletinboard:1.0
重新应用yaml文件
microk8s.kubectl apply -f bb.yaml
这篇关于如何修复“无法拉取图像"在microk8s上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!