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
You have to use the
--platform=linux/amd64
option when building the image with thedocker build
command. Your Mac M2 has an ARM processor while the nodes of your cluster (probably) use AMD processors.More information here.