kuberneets pods 镜像 ErrImageNeverPull

发布于 2025-01-09 10:13:03 字数 1560 浏览 1 评论 0原文

我有一个创建了用户服务的 docker 映像并将其标记为 localhost:5001 我有一个在端口 5001 运行的本地注册表

在此处输入图像描述

用户服务推送到本地注册表

在此处输入图像描述

并使用deploy_new.yaml 文件创建了 pod

apiVersion: v1
kind: Pod
metadata:
  name: user-service
  labels:
    component: web
spec:
  containers:
    - name: web
      image: localhost:5001/user-service
      resources:
        limits:
          memory: 512Mi
          cpu: "1"
        requests:
          memory: 256Mi
          cpu: "0.2"
      imagePullPolicy: Never
      ports:
        - name: http
          containerPort: 4006
          protocol: TCP
      livenessProbe:
        httpGet:
          path: /health/health
          port: 4006
        initialDelaySeconds: 3
        periodSeconds: 3
        failureThreshold: 2
      readinessProbe:
        httpGet:
          path: /health/health
          port: 4006
        initialDelaySeconds: 15
        periodSeconds: 10

但在描述 pod 时 我得到 在此处输入图像描述

问题:

  1. 什么是 ErrImageNeverPull 图像以及如何修复它?
  2. 如何测试活跃度和就绪度探针?

探针 API 输入图片此处描述

I have a docker image created user-service and tagged it to localhost:5001
I have a local registry running at PORT 5001

enter image description here

User-service pushed to local registry

enter image description here

and created pod using deploy_new.yaml file

apiVersion: v1
kind: Pod
metadata:
  name: user-service
  labels:
    component: web
spec:
  containers:
    - name: web
      image: localhost:5001/user-service
      resources:
        limits:
          memory: 512Mi
          cpu: "1"
        requests:
          memory: 256Mi
          cpu: "0.2"
      imagePullPolicy: Never
      ports:
        - name: http
          containerPort: 4006
          protocol: TCP
      livenessProbe:
        httpGet:
          path: /health/health
          port: 4006
        initialDelaySeconds: 3
        periodSeconds: 3
        failureThreshold: 2
      readinessProbe:
        httpGet:
          path: /health/health
          port: 4006
        initialDelaySeconds: 15
        periodSeconds: 10

But on describing pod
I get enter image description here

Questions :

  1. What is ErrImageNeverPull image and how to fix it?
  2. How to test liveliness and readiness probes?

Probe APIs
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骄傲 2025-01-16 10:13:03

1.什么是 ErrImageNeverPull 图像以及如何修复它?

作为 imagePullPolicy 设置为 Never kubelet 不会获取图像,而是查找本地存在的图像。该错误意味着它无法在本地找到图像,并且不会尝试获取它。

如果集群可以访问本地 docker 注册表,只需将 image: user-service 更改为 image: localhost:5000/user-service:latest

如果您使用的是 minikube ,检查README 重用您的 docker 守护进程,以便您无需上传即可使用您的图片。

  1. 在需要使用它的每个会话上执行 eval $(minikube docker-env)
  2. 构建镜像 docker build -t user-service 。
  3. 在 Pod 清单中将镜像添加为 image: user-service
  4. 确保您具有 imagePullPolicy: Never代码> 您的容器(您已经拥有)

2。如何测试活跃度和就绪探针?

我建议您尝试 Kubernetes 文档 他们很好地解释了两者之间的区别以及您可以配置的不同类型的探测器。

在检查活性和就绪探针之前,您需要首先使 Pod 运行。但就您而言,一旦 Pod 启动,它们就会成功。只需描述它并查看事件即可。

1. What is ErrImageNeverPull image and how to fix it?

As the imagePullPolicyis set to Never the kubelet won't fetch images but look for what is present locally. The error means it could not found the image locally and it will not try to fetch it.

If the cluster can reach to your local docker registry, just change the image: user-service to image: localhost:5000/user-service:latest

If you are using minikube, check the README to reuse your docker daemon so you can use your image without uploading it.

  1. Do eval $(minikube docker-env) on each session you need to use it.
  2. Build the image docker build -t user-service .
  3. Add the image in your Pod manifest as image: user-service
  4. make sure you have imagePullPolicy: Never for your container (which you already have)

2. How to test liveliness and readiness probes?

I suggest you try the examples form the Kubernetes documentation they explain really good the difference between the two and the different types of probes you can configure.

You need first to make your pod running before checking liveness and readiness probes. But in your case they will succeed as soon as the Pod starts. Just describe it and see the events.

若沐 2025-01-16 10:13:03

还有一件事需要注意。如果您使用非默认的 minikube 配置文件,eval $(minikube docker-env) 将默默失败,从而导致观察到的行为:

$ eval $(minikube docker-env)
$ minikube docker-env

One more thing to note. eval $(minikube docker-env) will fail silently if you are using a non-default minikube profile, leading to the observed behavior:

$ eval $(minikube docker-env)
$ minikube docker-env
????  Profile "minikube" not found. Run "minikube profile list" to view all profiles.
????  To start a cluster, run: "minikube start"
$

To address this re-run specifying the profile you are using:

$ eval $(minikube -p my-profile docker-env)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文