英文:
Error with only ECR image Back-off restarting failed container
问题
我是中文翻译,以下是您提供的内容的翻译部分:
我是新手使用 Kubernetes,使用 EKS 和 ECR 部署了一个简单的 Nginx 部署。问题只出现在我使用 ECR 镜像时,使用 Docker Hub 上的 Nginx 公共镜像时没有问题。
这是我的部署文件。
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
这是一个 Pod 的输出。
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  12s                default-scheduler  已成功分配给 *
  Normal   Pulled     10s (x2 over 12s)  kubelet            容器镜像 * 已经存在于机器上
  Normal   Created    10s (x2 over 12s)  kubelet            已创建容器 nginx
  Normal   Started    10s (x2 over 11s)  kubelet            已启动容器 nginx
  Warning  BackOff    8s (x2 over 9s)    kubelet            退避重新启动失败的容器
这是 Pod 的结果日志。
exec /docker-entrypoint.sh: exec format error
我还在本地机器上使用 Docker 运行了 ECR 镜像,没有出现任何错误。
有人能否给我一些提示,如何解决这个问题,提前感谢。
英文:
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.
答案1
得分: 2
> 请求的镜像平台 (linux/amd64) 与检测到的主机平台 (linux/arm64/v8) 不匹配,并且未请求特定的平台
这是因为您在 ARM M1 芯片上的 Mac 上构建了 Docker 镜像,然后尝试在 AMD 上运行,或者反过来,因此出现了错误。
您可以通过传递参数 --platform 再次构建 Docker 镜像
--platform linux/amd64
或者您还可以设置环境变量 export DOCKER_DEFAULT_PLATFORM=linux/amd64
您可以在 Dockerfile 中的 FROM 中传递参数
FROM --platform=linux/amd64 node
使用构建命令时的 ARG
docker build -t <image-name> --platform linux/amd64
参考文档: https://docs.docker.com/engine/reference/builder/#from
您还可以像这样使用 Docker 运行镜像
docker run --platform linux/amd64 node
英文:
> 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
答案2
得分: 0
经过多次尝试,我意识到我正在使用的基础镜像keymetrics/pm2:18-alpine 只支持 amd64 内核。即使我尝试在 arm64 中重新构建我的镜像,也无法在具有 arm64 内核类型的工作节点上正常工作。所以我看到解决这个问题的两种方法是:
- 重新创建我的 eks 集群,使用 amd64 工作节点。
 - 或者切换到其他支持 arm64 和 amd64 内核的基础镜像,如
node:18.14-alpine。 
英文:
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-alpinethat supports both arm64 and amd64 kernel. 
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论