kubernetes "unauthorized: authentication required"

5/6/2018

I have one GKE Cluster which uses the AWS ECR repo to pull the docker images. These are the steps that I followed.

Created a secret using this command

# cat > /tmp/image-pull-secret.yaml << EOF
apiVersion: v1
kind: Secret
metadata:
  name: myregistrykey
data:
  .dockerconfigjson: $(aws ecr get-authorization-token --output json | jq -n 'input.authorizationData | {auths: (reduce .[]  as $d ({}; . + {($d.proxyEndpoint|sub("https?://";"")): {auth:$d.authorizationToken}}))}' | (base64 -w0 2>/dev/null || base64) )
type: kubernetes.io/dockerconfigjson
EOF

# kubectl apply -f /tmp/image-pull-secret.yaml

Created a deployment but getting error

# cat abc_deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: abc-deployment
  labels:
    app: abc
    env: development
spec:
  replicas: 3
  selector:
    matchLabels:
      app: abc
      env: development
  template:
    metadata:
      labels:
        app: abc
        env: development
    spec:
      containers:
      - name: abc
        image: 34235354354.dkr.ecr.us-east-1.amazonaws.com/dev-abc:1.1.1
        ports:
        - containerPort: 8080
      imagePullSecrets:
        - name: myregistrykey

Error I am getting ++++++++++++++++++

  Normal   Pulling                1m (x2 over 1m)  kubelet, gke-puppy-default-pool-e701eb52-6gdp  pulling image "34235354354.dkr.ecr.us-east-1.amazonaws.com/dev-abc:1.1.1"
  Warning  Failed                 1m (x2 over 1m)  kubelet, gke-puppy-default-pool-e701eb52-6gdp  Failed to pull image "34235354354.dkr.ecr.us-east-1.amazonaws.com/dev-abc:1.1.1": rpc error: code = Unknown desc = unauthorized: authentication required
  Warning  Failed                 1m (x2 over 1m)  kubelet, gke-puppy-default-pool-e701eb52-6gdp  Error: ErrImagePull
  Normal   BackOff                1m (x6 over 1m)  kubelet, gke-puppy-default-pool-e701eb52-6gdp  Back-off pulling image "34235354354.dkr.ecr.us-east-1.amazonaws.com/dev-abc:1.1.1"
  Warning  Failed                 1m (x6 over 1m)  kubelet, gke-puppy-default-pool-e701eb52-6gdp  Error: ImagePullBackOff

How can we fix this error?

-- user3847894
amazon-web-services
docker
google-cloud-platform
google-kubernetes-engine
kubernetes

0 Answers