skip to Main Content

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"

The artifact is also stored correctly.
shows the stored artifact image

2

Answers


  1. Chosen as BEST ANSWER

    I fixed my problem based on @Alez answer.

    The following steps helped me:

    1. 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.
    2. 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.
    

  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search