Issue#
A newly deployed pod goes straight into CrashLoopBackOff. The image pulls fine, but the container exits immediately with code 1 or 255:
kubectl get pods
NAME READY STATUS RESTARTS AGE
api-7d9c6b8f5d-x2k4q 0/1 CrashLoopBackOff 4 (30s ago) 2m
The logs show:
exec /usr/local/bin/app: exec format error
This usually happens when the image was built on an Apple Silicon Mac (arm64) and runs on amd64 nodes, or the other way around on Graviton/Ampere arm64 nodes.
Cause#
The binary inside the image was compiled for a different CPU architecture than the node. The kernel cannot execute it, so the container fails at startup. The image was pushed as a single-architecture image, so the registry served the only variant it had, even though that variant doesn't match the node.
Solution#
- Confirm the mismatch. Check the node architectures:
kubectl get nodes -L kubernetes.io/arch
- Then check which platforms the image provides:
docker buildx imagetools inspect registry.example.com/api:1.4.0
If you see only linux/arm64 (or only linux/amd64) and it doesn't match your nodes, that is the problem. For an image already pulled locally:
docker image inspect --format '{{.Os}}/{{.Architecture}}' registry.example.com/api:1.4.0
- Enable QEMU emulation so one machine can build for other architectures. You only need this when building for a non-native platform:
docker run --privileged --rm tonistiigi/binfmt --install all
- Create a buildx builder that supports multi-platform builds:
docker buildx create --name multiarch --driver docker-container --use
docker buildx inspect --bootstrap
- Rebuild and push a multi-architecture image:
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t registry.example.com/api:1.4.1 \
--push .
If your Dockerfile compiles Go, cross-compile natively instead of emulating, because emulation is much faster this way:
FROM --platform=$BUILDPLATFORM golang:1.23 AS build
ARG TARGETOS TARGETARCH
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/app .
FROM gcr.io/distroless/static
COPY --from=build /out/app /usr/local/bin/app
ENTRYPOINT ["/usr/local/bin/app"]
- Roll out the new tag:
kubectl set image deployment/api api=registry.example.com/api:1.4.1
Workaround: If you can't rebuild right now and the cluster has nodes of both architectures, pin the pod to matching nodes:
spec:
template:
spec:
nodeSelector:
kubernetes.io/arch: arm64
Verify#
The manifest list should now show both platforms:
docker buildx imagetools inspect registry.example.com/api:1.4.1 | grep Platform
The pods should also become Running with no new restarts:
kubectl rollout status deployment/api
kubectl get pods -l app=api