How to deploy a .NET core console app to Azure Kubernetes Service?

5/19/2021

I have a .NET core console application to crawl a database periodically at certain intervals. I have dockerized it and have been able to run the docker image successfully from my local system. My ultimate objective is to deploy it from AKS. So I have pushed the aforementioned image to Azure Container Registry also. Please help me figure out the next steps on how to deploy the image from ACR into AKS.

The Dockerfile used to create the docker image :

FROM mcr.microsoft.com/dotnet/runtime:5.0
COPY bin/Release/net5.0/publish/ App/
WORKDIR /App
ENTRYPOINT ["dotnet", "<app_name>.dll"]

The YAML file used to deploy to AKS :

apiVersion: apps/v1
items:
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      Process: <app_name>
    creationTimestamp: null
    labels:
      app: <app_name>
    name: <app_name>
  spec:
    selector:
      app: <app_name>
  status:    
- apiVersion: apps/v1
  kind: Deployment
  metadata:
    annotations:
      Process: <app_name>
    creationTimestamp: null
    labels:
      app: <app_name>
    name: <app_name>
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: <app_name>
    strategy: {}
    template:
      metadata:
        creationTimestamp: null
        labels:
          app: <app_name>
      spec:
        containers:
        - env:
          image: "<acr_name>.azurecr.io/<image_name>:<version_tag>"
          name: <app_name>          
          resources: {}
        restartPolicy: Always
  status: {}
kind: List
metadata: {}

I am relatively new to Docker technologies, and I am unsure whether this is the proper way to deploy .NET console apps to AKS or if this is the proper YAML configuration for a console app o deploy it to AKS. Please help me in figuring this out. Any help is appreciated, thanks in advance!

-- indiyaaah
azure
console-application
docker
kubernetes

2 Answers

5/19/2021

I would start with a reference doc from Microsoft's documentation and then ask a more specific question.

Ref: https://docs.microsoft.com/en-us/dotnet/architecture/containerized-lifecycle/design-develop-containerized-apps/build-aspnet-core-applications-linux-containers-aks-kubernetes#push-the-image-into-the-azure-acr

Console App would be simpler than a web app. You will need to take out the port and service configs.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: console-app
  labels:
    app: console-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: console-app
  template:
    metadata:
      labels:
        app: console-app
    spec:
      containers:
        - name: console-app
          image: exploredocker.azurecr.io/console-app:v1
          imagePullPolicy: IfNotPresent
-- Faheem
Source: StackOverflow

5/19/2021

I guess you need to modify the docker file with the correct project path

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /app

# copy csproj and restore as distinct layers
# COPY *.sln .
COPY dotnet-app/*.csproj ./dotnet-app/
RUN dotnet restore dotnet-app

# copy everything else and build app
COPY dotnet-app/. ./dotnet-app/
WORKDIR /app/dotnet-app
RUN dotnet publish -c Release -o out


FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
WORKDIR /app
COPY --from=build /app/dotnet-app/out ./
ENTRYPOINT ["dotnet", "dotnet-app.dll"]

Here is a step by step instruction from the sample repository i built

-- Sajeetharan
Source: StackOverflow