欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

k8s报错

程序员文章站 2024-03-13 22:38:28
...

1. k8s拉取本地镜像
问题:
在机器上使用Dockerfile,打包了自己的镜像,但是没有push到仓库里,想本地直接通过k8s测试一下,但是通过yaml文件创建rc后,一直显示镜像拉取错误。从describe的信息看,k8s一直从远端拉取。

[[email protected] /home/k8s]# kubectl describe pod myweb-2959s
......
  58s		25s		2	{kubelet 127.0.0.1}	spec.containers{myweb}	Normal	      BackOff			Back-off pulling image "myweb8"
  58s		25s		2	{kubelet 127.0.0.1}				Warning	      FailedSync		Error syncing pod, skipping: failed to "StartContainer" for "myweb" with ImagePullBackOff: "Back-off pulling image \"myweb8\""

  1m	10s	3	{kubelet 127.0.0.1}	spec.containers{myweb}	Normal	Pulling		pulling image "myweb8"
  58s	4s	3	{kubelet 127.0.0.1}	spec.containers{myweb}	Warning	Failed		Failed to pull image "myweb8": Error: image library/myweb8 not found
  58s	4s	3	{kubelet 127.0.0.1}				Warning	FailedSync	Error syncing pod, skipping: failed to "StartContainer" for "myweb" with ErrImagePull: "Error: image library/myweb8 not found"

解决方案:
实际上,k8s默认会从远端拉取镜像,其配置参数imagePullPolicy为Always。所以,如果yaml文件中没有定义那就是使用默认的,因此我们可以通过将该参数显示设置为Never或者IfNotPresent,k8s就会从本地拉取镜像了。

  containers:
  - name: myweb
    image: myweb-image
    imagePullPolicy: Never
相关标签: 工具命令 k8s