【问题标题】:How to expose an http/https application on Azure Kubernetes Services如何在 Azure Kubernetes 服务上公开 http/https 应用程序
【发布时间】:2019-05-24 02:26:21
【问题描述】:

我正在将我的 dockerized 应用程序移植到 kubernetes,但在使用 aks 创建负载均衡器时遇到了问题:

The Service "lbalance" is invalid: spec.ports[0].nodePort: Invalid value: 80: provided port is not in the valid range. 
The range of valid ports is 30000-32767

配置非常简单

apiVersion: v1
kind: Service
metadata:
  name: lbalance
spec:
  selector:
    app: lbalance
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 80
    name: http
  - protocol: TCP
    port: 443
    targetPort: 443
    nodePort: 443
    name: https
  type: LoadBalancer

在它后面是一个 haproxy,通过 ssl 终止集群中暴露的其他服务

在我的测试环境中,我有一个属性来控制要打开哪个端口 (--service-node-port-range),但我在门户页面和 Azure 文档中都找不到该属性。

有没有办法在默认端口上提供服务或推荐的方式连接回该端点端口?

【问题讨论】:

    标签: azure kubernetes azure-aks


    【解决方案1】:

    您需要从您的 yaml 中删除 nodePort 声明,它将由 kubernetes 从错误文本中提到的池(您唯一可以使用的池)中分配。

    apiVersion: v1
    kind: Service
    metadata:
      name: lbalance
    spec:
      selector:
        app: lbalance
      ports:
      - protocol: TCP
        port: 80
        targetPort: 80
        name: http
      - protocol: TCP
        port: 443
        targetPort: 443
        name: https
      type: LoadBalancer
    

    这样,您的服务将在 80\443 上可用,并且一切正常

    【讨论】:

    • lbalance LoadBalancer 10.0.141.113 80:30933/TCP,443:32460/TCP 6s 如果删除 nodePort 它们不会暴露在 80/443 上,而是在一些随机的 30k+ 端口上
    • 这可能意味着您的设置错误并且无法在 azure 中创建负载均衡器,可能是您的 SP 配置错误
    • 成功了。我信任 kubectl 输出,但服务器实际上在响应,而不管 enpoint 告诉什么端口
    【解决方案2】:

    30000-32767 是 kubernetes 中默认的 nodeport 范围。您已定义为 nodePort: 443。它不受支持,因此引发了错误。

    按照以下步骤进行

    1. 将 NodePort 替换为 ClusterIP 作为服务类型
    2. 部署入口控制器
    3. 部署默认后端
    4. 从 dns 证书创建密钥(用于 https)
    5. 部署入口规则(包括秘密)将用户请求路由到后端服务。

    【讨论】:

      猜你喜欢
      • 2020-03-09
      • 2020-04-07
      • 1970-01-01
      • 2020-02-09
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 2019-09-18
      • 1970-01-01
      相关资源
      最近更新 更多