azure - 使用 Azure Kubernetes 在端口 80 上运行 Spring Boot

标签 azure docker kubernetes azure-aks

给定一个带有 docker-compose.yaml 的 Spring Boot 应用程序:

version: '3'
services:
  my-ws:
  build: .
  image: my-ws
   container_name: my-ws
   ports:
        - "8080:8080"

和 kubernetes list :

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: my-ws
spec:
  replicas: 3
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 5
  template:
    metadata:
      labels:
        app: my-ws
    spec:
      containers:
      - name: my-ws
        image: myacr.azurecr.io/my-ws:v1
        ports:
        - containerPort: 8080
        resources:
          requests:
            cpu: 250m
          limits:
            cpu: 500m
---
apiVersion: v1
kind: Service
metadata:
  name: my-ws
spec:
  loadBalancerIP: <redacted>
  type: LoadBalancer
  ports:
    - port: 8080
  selector:
    app: my-ws

我们可以在 Azure Kubernetes 服务上成功部署,并且应用程序在端口 8080 上响应。我们希望它在端口 80 上响应。我们已尝试将 docker-compose.yaml 端口更改为:

ports:
     - 80:80

和 list :

- containerPort: 80
...
-port: 80

并重新部署。部署成功,但该应用程序在 8080 或 80 上不可用。

最佳答案

您需要将服务端口 80 映射到容器端口 8080,这是最简单的解决方案(且破坏性最小):

---
apiVersion: v1
kind: Service
metadata:
  name: my-ws
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 8080
  selector:
    app: my-ws

ps。将其他所有内容保留为更改之前的样子

关于azure - 使用 Azure Kubernetes 在端口 80 上运行 Spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53853736/

相关文章:

amazon-web-services - Wildfly 10 服务器启动时出错

networking - Docker 容器在 localhost 上可见,但在具有自定义 bridge0 的其他主机上不可见

Kubernetes RS Controller - 查找服务帐户 k8s-tiller/k8s-tiller : serviceaccount "k8s-tiller" not found 时出错

kubernetes - 如何在 prometheus stable Helm Charts values.yaml 文件中添加 sidecar 容器?

c# - 为什么项目找不到 Microsoft.Azure.WebJobs 3.0.0.0

c# - 即使没有基础架构设置,如何禁用 Azure 功能?

azure - 如何使用 python 从我的 azure ad b2c 更新用户自定义属性

azure - SQL Azure - 更改 Master 上的数据库版本

docker - 使用docker时授权不使用identityserver4

bash - kubectl 或 bash 忽略 KUBECONFIG 环境变量