Skip to content

Instantly share code, notes, and snippets.

@jkremser
Last active October 31, 2024 18:45
Show Gist options
  • Save jkremser/28cff52b8a6c15cc6e0a34a1674c004e to your computer and use it in GitHub Desktop.
Save jkremser/28cff52b8a6c15cc6e0a34a1674c004e to your computer and use it in GitHub Desktop.
pre-fetch images

pre-fetch images on nodes:

kubelet param: If you would like to enable parallel image pulls, you can set the field serializeImagePulls to false in the kubelet configuration. With serializeImagePulls set to false, image pull requests will be sent to the image service immediately, and multiple images will be pulled at the same time.

By default, the kubelet tries to pull each image from the specified registry. However, if the imagePullPolicy property of the container is set to IfNotPresent or Never, then a local image is used (preferentially or exclusively, respectively).

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: prepuller
spec:
  selector:
    matchLabels:
      name: prepuller
  template:
    metadata:
      labels:
        name: prepuller
    spec:
      # Configure an init container for each image you want to pull
      initContainers:
        - name: prepuller-1
          # Set the image you want to pull
          image: ORG/IMAGE:TAG
          # Use a known command that will exit successfully immediately
          # Any no-op command will do but YMMV with scratch based containers
          command: ["sh", "-c", "'true'"]

        # - name: prepuller-2
        #   image: ...
        #   command: ["sh", "-c", "'true'"]

        # etc...

      # Use the pause container to ensure the Pod goes into a `Running` phase
      # but doesn't take up resource on the cluster
      containers:
        - name: pause
          image: gcr.io/google_containers/pause:3.2
          resources:
            limits:
              cpu: 1m
              memory: 8Mi
            requests:
              cpu: 1m
              memory: 8Mi

Bake container images directly to node images:

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