Tristan
Tristan

Reputation: 53

Error with only ECR image Back-off restarting failed container

I'm new with k8s and I've deployed a simple nginx deployment using eks and ecr. The problem only present when I'm using ecr image, it's not happens with nginx public image from docker hub. Here is my deployment file.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      imagePullSecrets:
        - name: *-ecr-registry
      containers:
        - name: nginx
          # image: nginx:latest
          image: *.dkr.ecr.*.amazonaws.com/nginx:dev

Here is output of a pod.

Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  12s                default-scheduler  Successfully assigned *
  Normal   Pulled     10s (x2 over 12s)  kubelet            Container image * already present on machine
  Normal   Created    10s (x2 over 12s)  kubelet            Created container nginx
  Normal   Started    10s (x2 over 11s)  kubelet            Started container nginx
  Warning  BackOff    8s (x2 over 9s)    kubelet            Back-off restarting failed container

Here is result log of the pod

exec /docker-entrypoint.sh: exec format error

I also ran the ecr image with docker in my local machine without any error. Can someone give me some hints, how can I overcome this issue, thanks in advance.

Upvotes: 0

Views: 805

Answers (2)

Tristan
Tristan

Reputation: 53

After hours of trying many ways, I realize that I'm using base-image keymetrics/pm2:18-alpine only supports amd64 kernel. Even I tried to rebuild my image in arm64, that doesn't not work in my work nodes with arm64 kernel type. So I see 2 ways to overcome this issue is:

  • recreate my eks cluster using amd64 worker nodes.
  • Or switch to other base-image like node:18.14-alpine that supports both arm64 and amd64 kernel.

Upvotes: 0

Harsh Manvar
Harsh Manvar

Reputation: 30160

The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

it's due to you have built the Docker image on an ARM M1 chip either on Mac and try to run it on AMD or the opposite due to that it's throwing an error.

You can build the docker image again by passing ARG --platform

--platform linux/amd64

Or you can also set the Environment variable export DOCKER_DEFAULT_PLATFORM=linux/amd64

You can pass ARG with FROM in Dockerfile or while running command docker build --platform

Dockerfile

FROM --platform=linux/amd64 node

ARG with build command

docker build -t <image-name> --platform linux/amd64

ref doc: https://docs.docker.com/engine/reference/builder/#from

You can also run the image with docker like

docker run --platform linux/amd64 node

Upvotes: 2

Related Questions