When to use this approach
Need to start a container right now, but the image isn’t in a registry yet? This approach is for you. We’re going to export your image as a tar file and import it into Kubernetes’ containerd
⚠️ Limitations
Consider this a temporary measure while you arrange a registry because:
- Pods will fail if the image is not loaded on the node!
- Any changes to the image require you to update it on all nodes.
- New nodes in the cluster also need the image to be imported.
Export image
Make sure you have the image available as a tar file. Here’s how to save one from a machine with Docker:
docker save repository/image --output ./image.tar
Transfer and import on each node
Copy the tar file to each node with a command like:
scp image.tar node:/tmp/
Run this command on each node to load the image into containerd:
sudo ctr -n k8s.io images import image.tar
Verify import succeeded with:
sudo ctr -n k8s.io images ls
Deploy with correct pull policy
To use this image in a Kubernetes deployment, make sure it’s set to imagePullPolicy: Never
Here’s an example deployment:
kind: Deployment
apiVersion: apps/v1
metadata:
name: my-app
labels:
app: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: xxxxx/my-app
imagePullPolicy: Never