TECHIES WORLD

For Techs.... Techniques.... Technologies....

BashLinux

Kubernates Error: Failed to pull image : rpc error: code = Unknown desc = Error response from daemon: pull access denied for , repository does not exist or may require 'docker login': denied: requested access to the resource is denied

Failed to pull image : rpc error: code = Unknown desc = Error response from daemon: pull access denied for , repository does not exist or may require 'docker login': denied: requested access to the resource is denied

This error usually happens on trying to pull the private images from Docker Hub. Kubernates requires some additional configuration to solve this problem and this article explains the details.

Step1: create a secret name regcred with the Docker Hub credentials

#kubectl create secret docker-registry regcred --docker-server=https://index.docker.io/v1/ --docker-username=username --docker-password=password --docker-email=email

Where username, password and email are need to be replaced with the appropriate values.

Step2: Add the regcred to the pod deployment configuration. The sample yaml snippet is sharing below.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-name
  labels:
    app: app-name
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app-name
  template:
    metadata:
      labels:
        app: app-name
    spec:
      containers:
      - name: app-name
        image: image-url
        ports:
        - containerPort: port
    imagePullSecrets:
    - name: regcred

Where app-name, image-url and port need to be replaced with the corresponding values.

Step3: Apply the deployment.

#kubectl apply -f deployment-file

Where deployment-file need to be replaced with the name of the deployment configuation file.

That's all…