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,发现状态已经正常
在这里插入图片描述

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐