Import images to k3s without docker registry

Categories: Kubernetes DevOps

Importing docker images into k3s without internet connection or docker registry is pretty straightforward, but requires access to containerd that runs all k3s pods.

This guide should work on any single-node cluster that uses containerd.

Build and package docker image

Build and package your docker container into tar archive:

docker build -t test-app:v1.0.0 .
docker save --output test-app-v1.0.0.tar test-app:v1.0.0

Copy image to remote host

Then copy it over to the target machine with k3s intalled:

rsync -v test-app-v1.0.0.tar remote:/home/ubuntu/test-app-v1.0.0.tar

Import images into k3s

Then you need to ssh into remote machine and import the image to the cluster:

sudo k3s ctr images import /home/ubuntu/test-app-v1.0.0.tar

If you want to automate this step you need to add user to SUDOERS with NOPASSWD option.

Use image inside k3s

At this point you can use the image in your kubernetes manifests like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-app
  labels:
    name: test-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: test-app
  template:
    metadata:
      labels:
        name: test-app
    spec:
      containers:
        - name: test-app
          image: test-app:v1.0.0
          imagePullPolicy: Never
          ports:
            - name: http
              containerPort: 80
              protocol: TCP

See also

Share this post with your friends

comments powered by Disqus