Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kubernetes: Pre-pull images into node
apiVersion: apps/v1beta2
kind: DaemonSet
metadata:
name: prepull
annotations:
source: "https://gist.github.com/itaysk/7bc3e56d69c4d72a549286d98fd557dd"
spec:
selector:
matchLabels:
name: prepull
template:
metadata:
labels:
name: prepull
spec:
initContainers:
- name: prepull
image: docker
command: ["docker", "pull", "hello-world"]
volumeMounts:
- name: docker
mountPath: /var/run
volumes:
- name: docker
hostPath:
path: /var/run
containers:
- name: pause
image: gcr.io/google_containers/pause
@itaysk

This comment has been minimized.

Owner

itaysk commented Nov 21, 2017

For Kubernetes versions < 1.8, edit L1 to apiVersion: extensions/v1beta1 .
Don't forget to update the image to pull (L19 - "hello-world").

@quasiben

This comment has been minimized.

quasiben commented Nov 27, 2017

I would also recommend adding:

  updateStrategy:
    type: RollingUpdate
@qye1103

This comment has been minimized.

qye1103 commented Jul 26, 2018

What will you do if you want to change the hello-world all the time? But with the same tag?

@wugx

This comment has been minimized.

wugx commented Jul 30, 2018

I've an error, how to resolve it?

Events:
  Type     Reason                 Age              From                                         Message
  ----     ------                 ----             ----                                         -------
  Normal   SuccessfulMountVolume  27s              kubelet, bjhtyd-hope-16-229.hadoop.jd.local  MountVolume.SetUp succeeded for volume "docker"
  Normal   SuccessfulMountVolume  27s              kubelet, bjhtyd-hope-16-229.hadoop.jd.local  MountVolume.SetUp succeeded for volume "default-token-4hxt6"
  Normal   Pulling                25s              kubelet, bjhtyd-hope-16-229.hadoop.jd.local  pulling image "docker"
  Warning  Failed                 10s              kubelet, bjhtyd-hope-16-229.hadoop.jd.local  Failed to pull image "docker": rpc error: code = Unknown desc = Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
  Warning  Failed                 10s              kubelet, bjhtyd-hope-16-229.hadoop.jd.local  Error: ErrImagePull
  Normal   SandboxChanged         9s               kubelet, bjhtyd-hope-16-229.hadoop.jd.local  Pod sandbox changed, it will be killed and re-created.
  Normal   BackOff                6s (x3 over 8s)  kubelet, bjhtyd-hope-16-229.hadoop.jd.local  Back-off pulling image "docker"
  Warning  Failed                 6s (x3 over 8s)  kubelet, bjhtyd-hope-16-229.hadoop.jd.local  Error: ImagePullBackOff

Kubernetes Version is Server Version: version.Info{Major:"1", Minor:"9"

and I tried docker pull docker

Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
@wat-izz

This comment has been minimized.

wat-izz commented Sep 7, 2018

What should I do if the image being pulled is in a private registry requiring an ImagePullSecret?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment