镜像拉取方式选择
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,让它每次都从仓库上面拉镜像。
</article>