我有一个看似基本的问题,但是在搜索并添加 https_port 作为环境变量、appsettings 顶级属性和其他尝试之后,每当我将应用程序部署到 Rancher 时,它只侦听端口 8080 上的 http。
这是一个简单的Web应用程序,除了通过keycloak测试授权之外没有任何实际功能,因此所有流量的需求都是https。
我希望启动日志包含“正在监听:https://[::]:8081 或 https 流量的其他端口。
相反我得到了
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
2024-09-20T09:50:14.146416699Z Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed. For more information go to https://aka.ms/aspnet/dataprotectionwarning
2024-09-20T09:50:14.540842462Z warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
2024-09-20T09:50:14.540881640Z No XML encryptor configured. Key {b25d69c8-24c9-4281-b5df-71ab43c8182f} may be persisted to storage in unencrypted form.
2024-09-20T09:50:15.340432431Z info: Microsoft.Hosting.Lifetime[14]
2024-09-20T09:50:15.340467342Z Now listening on: http://[::]:8080
2024-09-20T09:50:15.340471006Z info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
2024-09-20T09:50:15.340475874Z info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
2024-09-20T09:50:15.340480847Z info: Microsoft.Hosting.Lifetime[0]
2024-09-20T09:50:15.340483241Z Content root path: /app
我希望我遗漏了一些关于 .NET 8 的明显内容。
我的部署文件如下所示(其中一些值替换为虚拟值):
apiVersion: apps/v1
kind: Deployment
metadata:
name: myPOCsite
namespace: backend
spec:
selector:
matchLabels:
app: myPOCsite
replicas: 1
template:
metadata:
labels:
app: myPOCsite
log: "yes"
spec:
containers:
- name: myPOCsite
image: myimageurl
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8081
resources:
limits:
memory: "100Mi"
cpu: "80m"
requests:
memory: "60Mi"
cpu: "40m"
hostname: myPOCsite
imagePullSecrets:
- name: regsecret
---
apiVersion: v1
kind: Service
metadata:
labels:
app: myPOCsite
name: myPOCsite
namespace: backend
spec:
ports:
- port: 443
protocol: TCP
name: https
targetPort: 8081
selector:
app: myPOCsite
type: ClusterIP
在他们的 Docker 镜像中,Microsoft 将环境变量
ASPNETCORE_HTTP_PORTS
设置为 8080,这会使您的应用程序侦听该端口上的 HTTP。
侦听端口 8080 上的 HTTP 流量是 Docker 化 ASP.NET 应用程序的默认行为。
如果您希望它侦听另一个端口和/或侦听 HTTPS,您需要按照此处所述进行配置。