k8s镜像拉取策略 - imagePullPolicy

镜像拉取方式选择
k8s-imagePullPolicy

  containers:
    - name: uses-private-image
      image: $PRIVATE_IMAGE_NAME
      imagePullPolicy: Always
      command: [ "echo", "SUCCESS" ]

k8s的配置文件中经常看到有imagePullPolicy属性,这个属性是描述镜像的拉取策略

  • Always 总是拉取镜像
  • IfNotPresent 本地有则使用本地镜像,不拉取
  • Never 只使用本地镜像,从不拉取,即使本地没有
  • 如果省略imagePullPolicy,  策略为always 

官方文档:https://kubernetes.io/docs/concepts/containers/images

The default pull policy is IfNotPresent which causes the kubelet to skip pulling an image if it already exists. If you would like to always force a pull, you can do one of the following:

set the imagePullPolicy of the container to Always.
omit the imagePullPolicy and use :latest as the tag for the image to use.
omit the imagePullPolicy and the tag for the image to use.
enable the AlwaysPullImages admission controller.
When imagePullPolicy is defined without a specific value, it is also set to Always.

 

k8s镜像拉取总结

1. docker images 本地的镜像确实有,但是kubectl apply 时一直提示pull fail:

   我这边情况是,刚开始没有使用镜像仓库(也不懂),在masters上docker images时,master节点上确实有这个镜像,但是部署时是部署到node节点的,node节点上并没有这个镜像,所以会报错

    解决这个问题有两个方法:

        1. 在node节点上也做一份镜像,问题是节点多了麻烦

        2. 使用镜像仓库(建议)

2. 当我使用镜像仓库时,更新了某个镜像之后,重新apply镜像还是没变,这个问题跟第一个问题一样,都是node节点上的镜像跟预期的不一样,解决这个问题就一个思路,让它从仓库拉镜像:

       1. 删除node节点镜像

       2. 容器的imagePullPolicy值设置为Always,让它每次都从仓库上面拉镜像。

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

网络飞鸥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值