K3s部署pod设置了镜像拉取策略无效

环境信息:
K3s 版本:

k3s version v1.19.13+k3s1 (99eadcc1)

节点 CPU 架构、操作系统和版本::

Linux ubuntu-server 5.4.0-80-generic #90-Ubuntu SMP Fri Jul 9 22:49:44 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

集群配置:

虚拟机单节点启动k3s

问题描述:

尝试部署一个自己的java应用,写好deployment后,pod运行提示ErrImagePull

复现步骤:

安装 K3s 的命令:

curl -sfL http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_KUBECONFIG_MODE="644" INSTALL_K3S_VERSION=v1.19.13+k3s1 INSTALL_K3S_CHANNEL=stable sh -s -

因为是自己打包的镜像,所以想从本地直接启动,镜像拉取策略设置了IfNotPresent,deployment文件内容如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mybatis-demo
  namespace: default
spec:
  selector:
    matchLabels:
      app: mybatis-demo
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: mybatis-demo
    spec:
      nodeSelector: 
        kubernetes.io/hostname: ubuntu-server
      containers:
      - image: mybatis
        imagePullPolicy: IfNotPresent 
        name: mybatis-demo
        ports:
        - containerPort: 8999
          name: server-port
          protocol: TCP

pod describe显示信息:

Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  40s                default-scheduler  Successfully assigned default/mybatis-demo-cc6cbb894-tczwg to ubuntu-server
  Normal   Pulling    21s (x2 over 40s)  kubelet            Pulling image "mybatis"
  Warning  Failed     16s (x2 over 36s)  kubelet            Failed to pull image "mybatis": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/library/mybatis:latest": failed to resolve reference "docker.io/library/mybatis:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
  Warning  Failed     16s (x2 over 36s)  kubelet            Error: ErrImagePull
  Warning  Failed     4s (x2 over 35s)   kubelet            Error: ImagePullBackOff
  Normal   BackOff    4s (x2 over 35s)   kubelet            Back-off pulling image "mybatis"

本地镜像也存在:

# fan @ ubuntu-server in ~ [7:28:30] 
$ docker images
REPOSITORY    TAG            IMAGE ID       CREATED          SIZE
mybatis       latest         67a2932c11e6   38 minutes ago   129MB
openjdk       11.0-jdk       5505a9a39df1   3 months ago     659MB
hello-world   latest         bf756fb1ae65   2 years ago      13.3kB
openjdk       8-jdk-alpine   a3562aa0b991   2 years ago      105MB

预期结果:

能够直接运行

实际结果:

deployment处于不停重试状态,日志中为什么会先尝试拉取呢?

附加上下文/日志:

日志

Events:
Type Reason Age From Message


Normal Scheduled 40s default-scheduler Successfully assigned default/mybatis-demo-cc6cbb894-tczwg to ubuntu-server
Normal Pulling 21s (x2 over 40s) kubelet Pulling image “mybatis”
Warning Failed 16s (x2 over 36s) kubelet Failed to pull image “mybatis”: rpc error: code = Unknown desc = failed to pull and unpack image “docker.io/library/mybatis:latest”: failed to resolve reference “docker.io/library/mybatis:latest”: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
Warning Failed 16s (x2 over 36s) kubelet Error: ErrImagePull
Warning Failed 4s (x2 over 35s) kubelet Error: ImagePullBackOff
Normal BackOff 4s (x2 over 35s) kubelet Back-off pulling image “mybatis”

上下文

相同的模板替换成nginx就可以,为什么呢。。。。

你的启动命令中,没有表示使用docker作为runtime,而你在查询本地镜像时使用docker cli。
未启用docker时,k3s默认使用containerd。

明白了大佬,谢谢