gpt4 book ai didi

docker - kubectl get pods 显示 ErrImagePull

转载 作者:行者123 更新时间:2023-12-02 06:43:05 24 4
gpt4 key购买 nike

我尝试使用本地 docker 镜像创建一个 pod,如下所示。

1.首先我在终端中运行此命令

eval $(minikube docker-env)

2.我创建了一个docker镜像,如下

sudo docker image build -t my-first-image:3.0.0 .

3.我创建了如下所示的 pod.yml 并运行此命令

kubectl -f create pod.yml.

4.然后我尝试运行这个命令

kubectl get pods

但它显示以下错误


NAME READY STATUS RESTARTS AGE
multiplication-b47499db9-phpb7 0/1 ImagePullBackOff 0 23h
my-first-pod 0/1 ErrImagePull 0 7s

5.i 获取 pod 日志

kubectl describe pod my-first-pod 

Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 99s default-scheduler Successfully assigned default/my-first-pod to minikube
Warning Failed 41s (x3 over 94s) kubelet, minikube Failed to pull image "my-first-image:3.0.0": rpc error: code = Unknown desc = Error response from daemon: pull access denied for my-first-image, repository does not exist or may require 'docker login'
Warning Failed 41s (x3 over 94s) kubelet, minikube Error: ErrImagePull
Normal BackOff 12s (x4 over 93s) kubelet, minikube Back-off pulling image "my-first-image:3.0.0"
Warning Failed 12s (x4 over 93s) kubelet, minikube Error: ImagePullBackOff
Normal Pulling 0s (x4 over 98s) kubelet, minikube pulling image "my-first-image:3.0.0"

Dockerfile

FROM node:carbon
WORKDIR /app
COPY . .
CMD [ "node", "index.js" ]

pods.yml

kind: Pod
apiVersion: v1
metadata:
name: my-first-pod
spec:
containers:
- name: my-first-container
image: my-first-image:3.0.0

index.js

var http = require('http');
var server = http.createServer(function(request, response) {
response.statusCode = 200;
response.setHeader('Content-Type', 'text/plain');
response.end('Welcome to the Golden Guide to Kubernetes
Application Development!');
});
server.listen(3000, function() {
console.log('Server running on port 3000');
});

最佳答案

原因

这是因为它无法下载 pod 定义文件中定义的 docker 镜像。默认情况下,它从DockerHub下载所需的图像。 .

方式 1

因此,在创建 my-first-image:3.0.0 镜像后,您必须将其发布到 DockerHub。为此,在 DockerHub 创建一个帐户并使用 login 从终端登录。命令

sudo docker login

成功登录后,使用标签中的 DockerHub 用户名重建 Docker 镜像并将其推送到 DockerHub ( more details )

sudo docker image build -t YOUR_DOCKERHUB_USERNAME/my-first-image:3.0.0 .
sudo docker push YOUR_DOCKERHUB_USERNAME/my-first-image:3.0.0

pod.yml 中的镜像更新为 YOUR_DOCKERHUB_USERNAME/my-first-image:3.0.0 并像以前一样创建 Pod。

方式 2

您可以指示从本地计算机查找所需的 docker 镜像,而不是从 DockerHub 下载。为此,您必须在特定容器描述下的 pod.yml 文件中添加 imagePullPolicy: Never。以下是 pod.yml 文件的示例,用于显示在何处定义图像拉取策略

kind: Pod
apiVersion: v1
metadata:
name: my-first-pod
spec:
containers:
- name: my-first-container
image: YOUR_DOCKERHUB_USERNAME/my-first-image:3.0.0
imagePullPolicy: Never

关于docker - kubectl get pods 显示 ErrImagePull,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55392014/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com