skip to Main Content

Summary
Besides getting no error while docker’s build and push and kubectl apply events my applications pods status stuck with CrashLoopBackOff error. (Using Apple M2 Chip)

Hello everyone, me and my colleague building a mobile application with Dart/ Flutter. We are using Docker/ Kubernetes to virtualize and run the backend system. However, we are beginner of it.

My colleague can do the containerization and creating resources through Docker and Kubernetes CLI without any problems. However, besides getting no error response, after I do the same steps our pods’ status stuck with CrashLoopBackOff error. He is using a Windows PC while I am using Apple MacBook Air with M2 Chip.

Most probably we are having problem with the Docker phase, because we tried to do Docker phase on his computer then do the kubectl apply -f part on my computer which occurred no problem.

Our Docker File

# Specify the Dart SDK base image version using dart:<version> (ex: dart:2.12)
FROM dart:3.0.7 AS build

# Resolve app dependencies.
WORKDIR /app
COPY . .
# COPY backend/pubspec.* ./
WORKDIR /app/backend
RUN dart pub get

# Copy app source code and AOT compile it.
# Ensure packages are still up-to-date if anything has changed
RUN dart pub get --offline
RUN mkdir -p /bin/server
RUN dart compile exe /app/backend/bin/backend.dart -o bin/server

# Build minimal serving image from AOT-compiled `/server` and required system
# libraries and configuration files stored in `/runtime/` from the build stage.
FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/backend/bin/server /app/bin/

# Start server.
EXPOSE 7001
CMD ["/app/bin/server"]

Our .yaml file for Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: appName-deployment
  labels:
    app: appName
spec:
  replicas: 3
  selector:
    matchLabels:
      app: appName
  template:
    metadata:
      labels:
        app: appName
    spec:
      containers:
        - name: appName
          image: appName/backend:1.0.26
          ports:
            - containerPort: 7001
              name: grpc
            - containerPort: 7002
              name: api
      imagePullSecrets:
        - name: regcred
---
apiVersion: v1
kind: Service
metadata:
  name: appName-service
spec:
  type: NodePort
  selector:
    app: appName
  ports:
    - protocol: TCP
      name: grpc
      port: 7001
      targetPort: 7001
      nodePort: 32000
    - protocol: TCP
      name: api
      port: 7002
      targetPort: 7002
      nodePort: 32002

2

Answers


  1. You have to use the --platform=linux/amd64 option when building the image with the docker build command. Your Mac M2 has an ARM processor while the nodes of your cluster (probably) use AMD processors.

    More information here.

    Login or Signup to reply.
  2. I’ve had success on my MacBook M1 Pro by using the qemu driver with minikube. The general steps to getting minikube setup and building with docker are as follows:

    Assuming brew is installed.

    $ brew install qemu
    $ brew install minikube
    $ brew install docker
    $ brew install docker compose
    $ brew install socket_vmnet
    $ brew tap homebrew/services
    $ HOMEBREW=$(which brew) && sudo ${HOMEBREW} services start socket_vmnet
    
    $ minikube start --driver=qemu --network socket_vmnet
    
    $ eval $(minikube docker-env)
    $ echo "`minikube ip` docker.local" | sudo tee -a /etc/hosts > /dev/null
    

    plz add eval $(minikube docker-env) to your ~/.zshrc (or equivalent terminal config file)

    To get minikube to appropriately route traffic, use a tunnel:

    $ minikube tunnel
    

    Afterwards, you should be able to build and run docker images locally:

    $ docker build -t <IMAGE_NAME> .
    $ docker run -p <SERVER_PORT>:8080 <IMAGE_NAME>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search