catch32
catch32

Reputation: 18612

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

Just study the core of K8S on the local machine (Linux Mint 20.2).

Created one node cluster locally with:

k3d cluster create mycluster

Now I want to run the spring boot application in a container.
I build local image:

library:0.1.0

And here is a snippet from Deployment.yml:

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

Despite the fact that the image is already built:

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

Starting the container fails:

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"

How to resolve local images visibility for k3d cluster?


Solution:

Update the Deployment.yml:

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

And import the image to the cluster:

k3d image import xpinjection/library:0.1.0 -c mycluster

UPDATE:

I found an extraordinary error:

FATA[0000] failed to get cluster k3s-default: No nodes found for given cluster

Solved it by specifying cluster name:

k3d image import library:0.1.0 --cluster mycluster

name of a cluster is available:

k3d cluster list

Upvotes: 6

Views: 6083

Answers (1)

Bguess
Bguess

Reputation: 2330

If you don't want to use a docker registry, you have to import the locally built image into the k3d cluster:

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

But don't forget to configure in your deployment:

imagePullPolicy: Never

Upvotes: 12

Related Questions