0 背景
执行如下yaml文件创建Pod时发生报错
---
apiVersion: v1
kind: Pod
metadata:
name: volume-pod
spec:
containers:
- name: tomcat
image: tomcat:latest
ports:
- containerPort: 8080
volumeMounts:
- name: app-logs
mountPath: /usr/local/tomcat/logs
- name: busybox
image: busybox:latest
command: ["sh","-c","tail -f /logs/catalina*.log"]
volumeMounts:
- name: app-logs
mountPath: /logs
volumes:
- name: app-logs
emptyDir: {}
1 报错
Error from server (BadRequest): container “tomcat” in pod “volume-pod” is waiting to start: trying and failing to pull image

Error from server (BadRequest): container “tomcat” in pod “volume-pod” is waiting to start: trying and failing to pull image

但是在本地存在镜像

需要在Pod的yaml文件中设置参数( imagePullPolicy: IfNotPresent),避免k8s去拉取最新的镜像
---
apiVersion: v1
kind: Pod
metadata:
name: volume-pod
spec:
containers:
- name: tomcat
image: tomcat:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
volumeMounts:
- name: app-logs
mountPath: /usr/local/tomcat/logs
- name: busybox
image: busybox:latest
imagePullPolicy: IfNotPresent
command: ["sh","-c","tail -f /logs/catalina*.log"]
volumeMounts:
- name: app-logs
mountPath: /logs
volumes:
- name: app-logs
emptyDir: {}
重新生成pod,发现状态已经正常

Kubernetes Pod创建问题与解决方案:本地镜像使用与配置
在尝试通过yaml文件创建Kubernetes Pod时遇到错误,报错提示为尝试并失败拉取最新镜像。实际上,本地已经存在所需镜像。为避免这种情况,需要在yaml文件中为每个容器设置`imagePullPolicy`为`IfNotPresent`,确保使用已存在的本地镜像。更新yaml文件后,Pod状态恢复正常。
2万+

被折叠的 条评论
为什么被折叠?



