How to make sure my .NET Core service running in EKS can find the https port?

9/3/2021

I have created a .NET Core microservice using Microsoft sign-in as explained here. When running it locally or in a local Docker container, everything is working as expected. However, when running in EKS, I get an annoying warning message in the logs:

Failed to determine the https port for redirect.

This warning is shown in this picture shown below which also shows that I also checked which port numbers are used (only 80 for http). I would be nice if netstat -tulp would show a port number for https because then I can just set it in the application settings (as explained by the Microsoft docs) ad resolve it directly.

The Microsoft docs clearly exlain what to do when

The middleware logs the warning "Failed to determine the https port for redirect."

but these do not make clear what to do if everything works fine in all environments except when running the application in EKS. Probably, I should do something in my EKS/Kubernetes configuration but I have no clue what to do.

Here is the service file:

enter image description here

Here is the warning message shown in the logs.

enter image description here

How do I resolve the warning message?

-- Daan
amazon-eks
asp.net-core
https
kubernetes

2 Answers

9/9/2021

Make sure your app is actually listening for HTTPS connections on the port in your config: targetPort: 9377, nodePort: 30098

This other similar question might help resolve some issues with your setup: Access .NET Core app on Kubernetes on both http and https. If those are not issues with your setup, the answer by yip102011 is good.

-- yoda_droid
Source: StackOverflow

9/6/2021

I can see you are using app.UseHsts(); in Startup.cs file which will force client to use https. See document here.

But basic on your log Now listening on: http://[::]:80, your service only listening on http but not https.

Maybe You can try this 1. Simply delete the code app.UseHsts(); and use only http. 2. Enable https by config spec.template.spec.containers.env in k8s deployment.yaml. You will need a server tls cert in your container.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: webapi
  labels:
    app: weather-forecast
spec:
  replicas: 1
  selector:
    matchLabels:
      service: webapi
  template:
    metadata:
      labels:
        app: weather-forecast
        service: webapi
    spec:
      containers:
        - name: webapi
          image: exploredocker.azurecr.io/webapi:v1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
              protocol: TCP
            - containerPort: 443
              protocol: TCP
          env:
            - name: ASPNETCORE_URLS
              value: https://+:443;http://+:80
            - name: ASPNETCORE_Kestrel__Certificates__Default__Path
              value: /https/server_cert.pfx
            - name: ASPNETCORE_Kestrel__Certificates__Default__Password
              value: password
-- yip102011
Source: StackOverflow