Skip to content

Commit 116507c

Browse files
authored
Document auto-import images feature (#430)
* Add information about importing images --------- Signed-off-by: manuelbuil <mbuil@suse.com>
1 parent ef3f88a commit 116507c

File tree

4 files changed

+78
-9
lines changed

4 files changed

+78
-9
lines changed

docs/import-images.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: "Import images"
3+
---
4+
5+
Container images are cached locally on each node by the containerd image store. Images can be pulled from the registry as needed by pods, preloaded via image pull, or imported from an image tarball.
6+
7+
## On-demand image pulling
8+
9+
Kubernetes, by default, automatically pulls images when a Pod requires them if the image is not already present on the node. This behavior can be changed by using the [image pull policy](https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy) field of the Pod. When using the default `IfNotPresent` policy, containerd will pull the image from either upstream (default) or your [private registry](installation/private-registry.md) and store it in its image store. Users do not need to apply any additional configuration for on-demand image pulling to work.
10+
11+
12+
## Pre-import images
13+
:::info Version Gate
14+
The pre-importing of images while K3s is running feature is available as of January 2025 releases: v1.32.0+k3s1, v1.31.5+k3s1, v1.30.9+k3s1, v1.29.13+k3s1. Before that, K3s pre-imported the images only when booting.
15+
:::
16+
17+
Pre-importing images onto the node is essential if you configure Kubernetes' `imagePullPolicy` as `Never`. You might do this for security reasons or to reduce the time it takes for your K3s nodes to spin up.
18+
19+
K3s includes two mechanisms to pre-import images into the containerd image store:
20+
21+
<Tabs groupId = "import images" queryString>
22+
<TabItem value="Online image importing" default>
23+
24+
Users can trigger a pull of images into the containerd image store by placing a text file containing the image names, one per line, in the `/var/lib/rancher/k3s/agent/images` directory. The text file can be placed before K3s is started, or created/modified while K3s is running. K3s will sequentially pull the images via the CRI API, optionally using the [registries.yaml](installation/private-registry.md) configuration.
25+
26+
For example:
27+
28+
```bash
29+
mkdir /var/lib/rancher/k3s/agent/images
30+
cp example.txt /var/lib/rancher/k3s/agent/images
31+
```
32+
33+
Where `example.txt` contains:
34+
35+
```
36+
docker.io/library/redis:latest
37+
docker.io/library/mysql:latest
38+
```
39+
40+
After a few seconds, the `redis` and the `mysql` images will be available in the containerd image store of the node.
41+
42+
Use `sudo k3s ctr images list` to query the containerd image store.
43+
44+
</TabItem>
45+
<TabItem value="Offline image importing">
46+
47+
Users can import images directly into the containerd image store by placing image tarballs in the `/var/lib/rancher/k3s/agent/images` directory. The tarball can be placed before K3s is started, or created/modified while K3s is running. K3s will decompress the image tarball if necessary, extract the images, and load them into the containerd image store.
48+
49+
For example:
50+
51+
```bash
52+
mkdir /var/lib/rancher/k3s/agent/images
53+
curl https://github.com/k3s-io/k3s/releases/download/v1.33.1%2Bk3s1/k3s-airgap-images-amd64.tar.zst -O /var/lib/rancher/k3s/agent/images/k3s-airgap-images-amd64.tar.zst
54+
```
55+
56+
After a few seconds, the images included in the image tarball will be available in the containerd image store of the node.
57+
58+
Use `sudo k3s ctr images list` to query the containerd image store.
59+
60+
This is the method used in Airgap. Please follow the [Airgap install documentation](installation/airgap.md) for detailed information.
61+
62+
</TabItem>
63+
</Tabs>
64+
65+
## Set up an image registry
66+
67+
K3s supports two alternatives for image registries:
68+
69+
* [Private Registry Configuration](installation/private-registry.md) covers use of `registries.yaml` to configure container image registry authentication and mirroring.
70+
71+
* [Embedded Registry Mirror](installation/registry-mirror.md) shows how to enable the embedded distributed image registry mirror, for peer-to-peer sharing of images between nodes.

docs/installation/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ This section contains instructions for installing K3s in various environments. P
66

77
[Configuration Options](configuration.md) provides guidance on the options available to you when installing K3s.
88

9-
[Private Registry Configuration](private-registry.md) covers use of `registries.yaml` to configure container image registry mirrors.
9+
[Private Registry Configuration](private-registry.md) covers use of `registries.yaml` to configure container image registry authentication and mirroring.
1010

11-
[Embedded Mirror](registry-mirror.md) shows how to enable the embedded distributed image registry mirror.
11+
[Embedded Registry Mirror](registry-mirror.md) shows how to enable the embedded distributed image registry mirror, for peer-to-peer sharing of images between nodes.
1212

1313
[Air-Gap Install](airgap.md) details how to set up K3s in environments that do not have direct access to the Internet.
1414

docs/installation/registry-mirror.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ This option enables the embedded mirror for use on all nodes in the cluster.
1616
When enabled at a cluster level, all nodes will host a local OCI registry on port 6443,
1717
and publish a list of available images via a peer to peer network on port 5001.
1818
Any image available in the containerd image store on any node, can be pulled by other cluster members without access to an external registry.
19-
<!-- Note: Not a regular markdown header because it exists inside a Tabs structure, access it via queryString-->
20-
Images imported via [air-gap image tar files](./airgap.md?airgap-load-images=Manually+Deploy+Images) are pinned in containerd to
21-
ensure that they remain available and are not pruned by Kubelet garbage collection.
19+
Images imported via [air-gap image tar files](./airgap.md?airgap-load-images=Manually+Deploy+Images) or [pre-imported](../import-images.md#pre-import-images) are pinned in containerd to ensure that they remain available and are not pruned by Kubelet garbage collection.
2220

2321
The peer to peer port can changed from 5001 by setting the `K3S_P2P_PORT` environment variable for the K3s service. The port must be set to the same value on all nodes.
2422
Changing the port is unsupported and not recommended.
@@ -130,9 +128,8 @@ If image integrity is important, you should use image digests instead of tags, a
130128

131129
## Sharing Air-gap or Manually Loaded Images
132130

133-
Images sharing is controlled based on the source registry.
134-
Images loaded directly into containerd via air-gap tarballs, or loaded directly into containerd's image store using the `ctr` command line tool,
135-
will be shared between nodes if they are tagged as being from a registry that is enabled for mirroring.
131+
Image sharing is controlled based on the source registry.
132+
Images loaded directly into containerd via [air-gap tarballs](./airgap.md?airgap-load-images=Manually+Deploy+Images), [pre-imported](../import-images.md#pre-import-images) or loaded directly into containerd's image store using the `ctr` command line tool, will be shared between nodes if they are tagged as being from a registry that is enabled for mirroring.
136133

137134
Note that the upstream registry that the images appear to come from does not actually have to exist or be reachable.
138135
For example, you could tag images as being from a fictitious upstream registry, and import those images into containerd's image store.
@@ -143,5 +140,5 @@ You would then be able to pull those images from all cluster members, as long as
143140
The embedded registry is read-only, and cannot be pushed to directly using `docker push` or other common tools that interact with OCI registries.
144141

145142
Images can be manually made available via the embedded registry by running `ctr -n k8s.io image pull` to pull an image,
146-
or by loading image archives created by `docker save` via the `ctr -n k8s.io image import` command.
143+
or by loading image archives created by `docker save` via the `ctr -n k8s.io image import` command or the [pre-import feature](../import-images.md#pre-import-images).
147144
Note that the `k8s.io` namespace must be specified when managing images via `ctr` in order for them to be visible to the kubelet.

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module.exports = {
6565
'architecture',
6666
'cluster-access',
6767
'storage',
68+
'import-images',
6869
{
6970
type: 'category',
7071
label: 'Networking',

0 commit comments

Comments
 (0)