英文:
CrashLoopBackOff when pulling image form Artifact-Registry inside GKE Deployment
问题
你好,感谢你的帮助!
我在我的GKE集群(1.26.5-gke.1400)中遇到了一些异常行为,当我尝试从制品注册表中拉取镜像时出现问题。这两个服务都位于同一个GCP项目中。我的GKE集群正在使用默认的计算服务帐号,并且已被授予Artifact Registry Reader权限。
我的目标是部署一个简单的nginx应用程序,从Docker镜像中加载一个index.html文件。然而,在描述的配置下,我在日志中遇到了以下错误:
CrashLoopBackOff - exec /docker-entrypoint.sh: exec format error
以下是我的deployment.yml文件内容:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hochzeitsautoschwerin
namespace: hochzeitsautoschwerin
spec:
selector:
matchLabels:
app: hochzeitsautoschwerin
strategy:
type: Recreate
template:
metadata:
labels:
app: hochzeitsautoschwerin
spec:
containers:
- image: europe-west4-docker.pkg.dev/jenkins-389117/test-images/test:1.0.0
name: testdeployment
ports:
- containerPort: 8080
name: web
resources:
limits:
cpu: "0.2"
memory: "256Mi"
requests:
cpu: "0.1"
memory: "100Mi"
我的Dockerfile如下所示:
FROM --platform=linux/amd64 nginx:latest
COPY src/index.html /usr/share/nginx/html/index.html
COPY docker/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
RUN echo "[i] Starting docker-entrypoint.sh"
CMD ["/docker-entrypoint.sh"]
docker-entrypoint.sh的内容如下:
#!/bin/sh
# Start NGINX
exec nginx -g 'daemon off;'
echo "[i] nginx started"
制品也被正确存储。
英文:
Hello and thank you for your assistance!
I am experiencing some unusual behavior within my GKE cluster (1.26.5-gke.1400) when attempting to pull images from the artifact registry. Both services are located within the same GCP project. My GKE cluster is utilizing the default compute service account, which has been granted the Artifact Registry Reader permission.
My objective is to deploy a simple nginx application that loads an index.html file from a Docker Image. However, with the configuration described, I am encountering the following error in the logs:
> CrashLoopBackOff - exec /docker-entrypoint.sh: exec format error
# deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: hochzeitsautoschwerin
namespace: hochzeitsautoschwerin
spec:
selector:
matchLabels:
app: hochzeitsautoschwerin
strategy:
type: Recreate
template:
metadata:
labels:
app: hochzeitsautoschwerin
spec:
containers:
- image: europe-west4-docker.pkg.dev/jenkins-389117/test-images/test:1.0.0
name: testdeployment
ports:
- containerPort: 8080
name: web
resources:
limits:
cpu: "0.2"
memory: "256Mi"
requests:
cpu: "0.1"
memory: "100Mi"
My dockerfile looks like this:
FROM --platform=linux/amd64 nginx:latest
COPY src/index.html /usr/share/nginx/html/index.html
COPY docker/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
RUN echo "[i] Starting docker-entrypoint.sh"
CMD ["/docker-entrypoint.sh"]
The docker-entrypoint.sh is defined like this:
#!/bin/sh
# Start NGINX
exec nginx -g 'daemon off;'
echo "[i] nginx started"
答案1
得分: 1
错误CrashLoopBackOff
意味着发生了一个错误,导致Pod无法正确启动。因此,镜像被正确找到和存储,但无法正确运行。
导致无法运行的错误是:
> CrashLoopBackOff - exec /docker-entrypoint.sh: exec format error
通常,这是因为您运行它的平台架构与构建Docker镜像的平台架构不同。
为了解决这个问题,您应该在Dockerfile中添加平台信息,例如:
FROM --platform=linux/amd64 nginx:latest
英文:
The error CrashLoopBackOff
means that there's an error happening that prevents a Pod from starting properly. So the image is found and stored properly but it doesn't run correctly.
The error that prevents it to run is:
> CrashLoopBackOff - exec /docker-entrypoint.sh: exec format error
This usually happens because the architecture of the platform where you run it is different to the architecture where you built the Docker image.
To do that you should add to your Dockerfile the platform, such as:
FROM --platform=linux/amd64 nginx:latest
答案2
得分: 0
我根据@Alez的答案解决了我的问题。
以下步骤对我有帮助:
- 我检查了我的本地 M1 Mac 使用的平台,然后使用命令 uname -m 检查了运行我的 GKE 集群的 GCP VM。我发现我的本地 Mac 正在运行 arm64,而具有集群的 VM 正在运行 x86_64。这解释了我的错误,因为 VM 无法解析构建 Docker 镜像的 arm64 架构。
- 为了为两种架构构建 Docker 镜像,我使用了
docker buildx
命令。
2.1 要初始化 buildx,请使用命令:docker buildx create --use
2.2 然后,构建镜像并将其推送到 Artifact Registry:
docker buildx build --push --platform linux/arm64,linux/amd64 -t europe-west4-docker.pkg.dev/project_id/registry_name/test:1.0.0 -f docker/Dockerfile .
标签:
--push #构建后直接推送镜像。
--platform linux/arm64,linux/amd64 #指定应为哪种类型的平台构建镜像。
英文:
I fixed my problem based on @Alez answer.
The following steps helped me:
- I checked which platform my local M1 Mac is using, and then I checked the GCP VM on which my GKE cluster was running with the command uname -m. I found out that my local Mac is running on arm64, and the VM with the cluster on x86_64. This explains my error, as the VM can't resolve the arm64 architecture on which the Docker image was built.
- To build the Docker image for both architectures, I used the
docker buildx
command.
2.1 To initialize buildx, use the command: docker buildx create --use
2.2 Then, build the image and push it to the Artifact Registry:
docker buildx build --push --platform linux/arm64,linux/amd64 -t europe-west4-docker.pkg.dev/project_id/registry_name/test:1.0.0 -f docker/Dockerfile .
tags:
--push #directly push the image after building.
--platform linux/arm64,linux/amd64 #specify on for which type of platform the image should get build.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论