k8s使用本地镜像

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010039418/article/details/86578420

背景

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

[root@CentOS-7-2 /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

猜你喜欢

转载自blog.csdn.net/u010039418/article/details/86578420