<p>I have a console application that acts as a listener from some message broker. I've containerized it and successfully run as a local docker. Now I would like to deploy it to Kubernetes (specifically EKS on AWS).</p>
<p>So I created a yaml file that needed for deployment, however, I was confused about the port needed in the yaml file. From the experience of deploying API, I know the port should be the same as the Docker Image exposed port, however, the Console Application does not expose any port, and no need port to run either.</p>
<p>So I simply put out some ports and try to deploy. And naturally it is not working. I have pulled the image from ECR and runs to confirm it was working. Only the deployment to EKS is not.</p>
<p>May I know is there a correct way to deploy a .NET Core console application to Kubernetes?</p>
<p>Below is my Dockerfile:</p>
<pre><code>FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY [&quot;Listener/Listener.csproj&quot;, &quot;Listener/&quot;]
COPY [&quot;Infra/Infra.csproj&quot;, &quot;Infra/&quot;]
RUN dotnet restore &quot;Listener/Listener.csproj&quot;
COPY . .
WORKDIR &quot;/src/Listener&quot;
RUN dotnet build &quot;Listener.csproj&quot; -c Release -o /app/build

FROM build AS publish
RUN dotnet publish &quot;Listener.csproj&quot; -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT [&quot;dotnet&quot;, &quot;Listener.dll&quot;]
</code></pre>
<p>Below is my yaml file for this console application:</p>
<pre><code>apiVersion: apps/v1
items:
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      Process: listener
    creationTimestamp: null
    labels:
      app: listener
    name: listener
  spec:
    type: LoadBalancer
    ports:
    - name: &quot;5999&quot;
      port: 5999
      targetPort: 5999
    selector:
      app: listener
  status:
    loadBalancer: {}
- apiVersion: apps/v1
  kind: Deployment
  metadata:
    annotations:
      Process: listener
    creationTimestamp: null
    labels:
      app: listener
    name: listener
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: listener
    strategy: {}
    template:
      metadata:
        creationTimestamp: null
        labels:
          app: listener
      spec:
        containers:
        - env:
          image: *****.dkr.ecr.&lt;region&gt;.amazonaws.com/listener:latest
          name: listener
          ports:
          - containerPort: 5999
          resources: {}
        restartPolicy: Always
  status: {}
kind: List
metadata: {}
</code></pre>
<p>Really appreciates it if anyone could help! Thanks!</p>

Sivvie Lim
<p>Well, if your project doesn't actually listen on any ports, then you don't need to expose any. You can do away with these lines from your deployment</p>
<pre><code>ports:
- containerPort: 5999
</code></pre>
<p>And, since <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="noreferrer">services</a> are defined as &quot;an abstract way to expose an application running on a set of Pods as a network service,&quot; you don't actually need the service definition either, meaning that all you need is your deployment.</p>
