imagePullSecrets not working when using k3s

4/1/2019

I'm using k3s to test my k8s configurations. Sadly, imagePullSecrets seems not to work properly.

I've tested the same configuration in minikube and it works fine.

Example:

I create the secret with:

kubectl create secret generic myreg --from-file=.dockerconfigjson=$HOME/.docker/config.json

And this is a daemonset example:

apiVersion: apps/v1                                                                                                                                                                                                                         
kind: DaemonSet
metadata:
  name: foo
  namespace: default
  labels:
    app: foo
spec:
  selector:
    matchLabels:
      name: foo
  template:
    metadata:
      labels:
        name: foo
    spec:
      imagePullSecrets:
      - name: myreg
      containers:
      - name: foo
        image: whatever/foo:latest

The status stays as ErrImagePull and running describe over the pod it says:

  Normal   BackOff    2s    kubelet, localhost  Back-off pulling image "whatever/foo:latest"
  Warning  Failed     2s    kubelet, localhost  Error: ImagePullBackOff

Why Does it not work?

-- MagMax
k3s
kubernetes
minikube
rancher

1 Answer

4/1/2019

Finally I found the answer in the issue Document image preloading.

The imagePullSecrets are not implemented in k3s, but there is an undocumented feature, and you can pull the image manually to get it work.

To do it (as root):

# docker pull whatever/foo:latest
# docker save whatever/foo:latest -o /var/lib/rancher/k3s/agent/images/foo-latest.tgz

And then the image will be "downloaded" and installed into k3s.

Remember to restart k3s after downloading it.

-- MagMax
Source: StackOverflow