2

On our K8S Worker node with below command have created "secret" to pull images from our private (Nexus) registry.

kubectl create secret docker-registry regcred --docker-server=https://nexus-server/nexus/ --docker-username=admin --docker-password=password --docker-email=user@company.com

Created my-private-reg-pod.yaml in K8S Worker node, It has below.

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
  - name: private-reg-container
    image: nexus-server:4546/ubuntu-16:version-1
  imagePullSecrets:
  - name: regcred

Created pod with below command

kubectl create -f my-private-reg-pod.yaml

kubectl get pods

NAME       READY   STATUS             RESTARTS   AGE
test-pod   0/1     ImagePullBackOff   0          27m

kubectl describe pod test-pod

Events:
  Type     Reason     Age                   From                   Message
  ----     ------     ----                  ----                   -------
  Normal   Scheduled  <unknown>             default-scheduler      Successfully assigned default/test-pod to k8s-worker01
  Warning  Failed     26m (x6 over 28m)     kubelet, k8s-worker01  Error: ImagePullBackOff
  Normal   Pulling    26m (x4 over 28m)     kubelet, k8s-worker01  Pulling image "sonatype:4546/ubuntu-16:version-1"
  Warning  Failed     26m (x4 over 28m)     kubelet, k8s-worker01  Failed to pull image "nexus-server:4546/ubuntu-16:version-1": rpc error: code = Unknown desc = Error response from daemon: Get https://nexus-server.domain.com/nexus/v2/ubuntu-16/manifests/ver-1: no basic auth credentials
  Warning  Failed     26m (x4 over 28m)     kubelet, k8s-worker01  Error: ErrImagePull
  Normal   BackOff    3m9s (x111 over 28m)  kubelet, k8s-worker01  Back-off pulling image "nexus-server:4546/ubuntu-16:version-1"

On terminal nexus login works

docker login nexus-server:4546

Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

Something i am missing with this section?

David Maze
  • 130,717
  • 29
  • 175
  • 215
user4948798
  • 1,924
  • 4
  • 43
  • 89
  • Is your `nexus-server` is on the same cluster? – Vüsal Jul 30 '20 at 08:27
  • No, `nexus-server` is separate VM server. – user4948798 Jul 30 '20 at 08:30
  • it worked this command `kubectl create secret generic regcred \ --from-file=.dockerconfigjson= \ --type=kubernetes.io/dockerconfigjson` – user4948798 Jul 30 '20 at 08:34
  • pull is success. `kubectl get pods` `test-pod 0/1 CrashLoopBackOff 5 4m13s` shows this error. – user4948798 Jul 30 '20 at 08:37
  • check this out, set image pull policy: https://stackoverflow.com/questions/49639280/kubernetes-cannot-pull-image-from-private-docker-image-repository – amit23comp Jul 30 '20 at 08:38
  • `imagePullPolicy: Always` added in `my-private-reg-pod.yaml` file and created new pod, but still it shows `CrashLoopBackOff` in `kubectl get pods` command output. Also `kubectl describe pod test-pod` command shows `Back-off restarting failed container` – user4948798 Jul 30 '20 at 09:05
  • Does pod has any limitation in accepting docker image size? – user4948798 Jul 30 '20 at 09:07
  • Nope no size limitation – Tarun Khosla Jul 30 '20 at 10:08
  • The problem is with the image pull policy - you have set this to Always (the default setting). This means that the Docker daemon always tries to pull the image from the outer Docker registry - you want to use the local one instead. Try to add --image-pull-policy=Never when creating a pod. Size has no limitation – amit23comp Jul 30 '20 at 10:20
  • i have rebooted my system and it worked. Thanks a lot. – user4948798 Jul 30 '20 at 10:37
  • @Kishore Could you please describe the actions you have taken in order to resolve your issue in a form of an answer? It would be be more clear for the rest of the community. – Wytrzymały Wiktor Jul 31 '20 at 09:43

1 Answers1

3

Since my docker login to nexus succeeded on terminal, So i have deleted my secret and created with kubectl create secret generic regcred \ --from-file=.dockerconfigjson=<path/to/.docker/config.json> \ --type=kubernetes.io/dockerconfigjson it worked.

user4948798
  • 1,924
  • 4
  • 43
  • 89
  • I would like to trey this as well, however, I use Docker for Desktop (on my macOS), and that didn't seem to fix the issue. – FooBar Nov 15 '20 at 12:58
  • @FooBar In my case I have already logged in successfully to connect my registry. So changed to my answer command to create secrets. For details refer the below. 'https://kubernetes.io/docs/concepts/configuration/secret/' – user4948798 Nov 16 '20 at 00:38