k3d 尝试拉 Docker 图像而不是使用本地图像

k3d tries to pull Docker image instead of using the local one

在本地机器(Linux Mint 20.2)研究K8S的核心。

在本地创建了一个节点集群:

k3d cluster create mycluster

现在我想 运行 spring 在容器中启动应用程序。
我构建本地镜像:

library:0.1.0

这是来自 Deployment.yml 的片段:

spec:
  terminationGracePeriodSeconds: 40
  containers:
    - name: 'library'
      image: library:0.1.0
      imagePullPolicy: IfNotPresent

尽管图像已经构建:

docker images
REPOSITORY    TAG       IMAGE ID       CREATED             SIZE
library       0.1.0     254c13416f46   About an hour ago   462MB

启动容器失败:

pod/library-867dfb64db-vndtj    Pulling image "library:0.1.0"
pod/library-867dfb64db-vndtj    Failed to pull image "library:0.1.0": rpc error: code = Unknown desc = failed to pull and unpack image "library:0.1.0": failed to resolve reference "library:0.1.0": failed to do request: Head "https://...com/v2/library/manifests/0.1.0": x509: certificate signed by unknown authority
pod/library-867dfb64db-vndtj    Error: ErrImagePull
pod/library-867dfb64db-vndtj    Error: ImagePullBackOff
pod/library-867dfb64db-vndtj    Back-off pulling image "library:0.1.0"

如何解决 k3d 集群的本地图像可见性问题?


解决方案:

更新 Deployment.yml:

spec:
  terminationGracePeriodSeconds: 40
  containers:
    - name: 'library-xp'
      image: xpinjection/library:0.1.0
      imagePullPolicy: Never

并将图像导入集群:

k3d image import xpinjection/library:0.1.0 -c mycluster

如果你不想使用docker registry,你必须将本地构建的镜像导入k3d集群:

k3d image import [IMAGE | ARCHIVE [IMAGE | ARCHIVE...]] [flags]

但不要忘记在您的部署中进行配置:

imagePullPolicy: Never