'.NET 6 development containers crashing on Kubernetes
I'm currently on a relatively new journey into microservices architecture, and so far have been developing using a docker-compose file in my .NET 6 solution that builds my containers locally. Whilst this has been very useful as the solution grows it is becoming very painful to run locally as having containers running locally on my system is making very slow and cumbersome.
The production version of this solution will eventually target Kubernetes, and so it seems like a good idea to create a development Kubernetes cluster, and use something like the bridge to Kubernetes addin for Visual Studio and abandon docker-compose.
The journey towards this though has brought up a number of problems along the way that I'm hoping I can get some advice on. I have used Compose to convert my docker compose into deployment and service files, my containers are built and live on my local system, when I deploy development containers which have the :dev tag the seem to not run and I get the CrashLoopBackOff issue, see no logs and so no real way to workout why this happens. However if I build the containers under a release profile and use the :latest tag the containers deploy, and run without crashing.
My question is how do I deploy my containers to kuernetes in development profile without them crashing so that I can get up and running with bridge to Kubernetes? I'm wondering whether it is related to the fact that the built containers are local in the container registry provided by docker desktop, or do I need to provide anything specific for containers that are built using a development profile?
DockerFile
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Microservices/PatientService/PatientService/PatientService.csproj", "Microservices/PatientService/PatientService/"]
COPY ["Microservices/PatientService/PatientService.Data/PatientService.Data.csproj", "Microservices/PatientService/PatientService.Data/"]
COPY ["Microservices/PatientService/PatientService.Domain/PatientService.Domain.csproj", "Microservices/PatientService/PatientService.Domain/"]
RUN dotnet restore "Microservices/PatientService/PatientService/PatientService.csproj"
COPY . .
WORKDIR "/src/Microservices/PatientService/PatientService"
RUN dotnet build "PatientService.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PatientService.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PatientService.dll"]
Kubernetes deployment
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
io.kompose.service: patientservice
name: patientservice
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: patientservice
strategy: {}
template:
metadata:
labels:
io.kompose.service: patientservice
spec:
containers:
- image: patientservice:latest
imagePullPolicy: IfNotPresent
name: patientservice
startupProbe:
httpGet:
path: /health/startup
port: 80
failureThreshold: 30
periodSeconds: 10
livenessProbe:
httpGet:
path: /healthz
port: 80
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
readinessProbe:
httpGet:
path: /ready
port: 80
successThreshold: 3
ports:
- containerPort: 80
resources: {}
restartPolicy: Always
status: {}
Kubernetes service manifest
apiVersion: v1
kind: Service
metadata:
labels:
io.kompose.service: patientservice
name: patientservice
spec:
ports:
- name: "5052"
port: 5052
targetPort: 80
selector:
io.kompose.service: patientservice
status:
loadBalancer: {}
When this is deployed, I get CrashLoopBackOut (unless I build as release). I have followed a number of articles that have not helped me, I see a number of suggestion which suggest exec into the container, but I'm not sure what/where I need to look inside the container to help resolve my issue.
Update
It seems that this issue only occurs if I use docker-compose.yaml either on command line, or in Visual Studio, it also happens if I build an individual docker file within Visual Studio. If I build an individual docker file on command line, then add tag to include my docker hub username it works i.e. username/microservicename:latest it runs on Kubernetes without crashing. Does this mean I need to build each container manually on the command line, or is there a tool that I've missed to do this for me?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
