可在错误端口上访问 AKS 负载平衡器服务

时间:2021-07-13 11:13:22

标签: kubernetes azure-aks

我有一个简单的 ASP.NET 核心 Web API。它在本地工作。我使用以下 yaml 在 Azure AKS 中部署了它:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sa-be
spec:
  selector:
    matchLabels:
      name: sa-be
  template:
    metadata:
      labels:
        name: sa-be
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      containers:
      - name: sa-be
        image: francotiveron/anapi:latest
        resources:
          limits:
            memory: "64Mi"
            cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
  name: sa-be-s
spec:
  type: LoadBalancer
  selector:
    name: sa-be
  ports:
  - port: 8080
    targetPort: 80

结果是:

> kubectl get service sa-be-s
NAME      TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
sa-be-s   LoadBalancer   10.0.157.200   20.53.188.247   8080:32533/TCP   4h55m



> kubectl describe service sa-be-s 
Name:                     sa-be-s
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 name=sa-be
Type:                     LoadBalancer
IP Families:              <none>
IP:                       10.0.157.200
IPs:                      <none>
LoadBalancer Ingress:     20.53.188.247
Port:                     <unset>  8080/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  32533/TCP
Endpoints:                10.244.2.5:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

我希望在 http://20.53.188.247:32533/ 访问 Web API,但它只能在 http://20.53.188.247:8080/ 访问

谁能解释一下

  • 这是他预期的行为吗
  • 如果是,NodePort (32533) 的用途是什么?

1 个答案:

答案 0 :(得分:1)

是的,意料之中。 Explained: Kubernetes Service Ports - 请阅读全文以了解后台发生的情况。

负载均衡器部分:

apiVersion: v1
kind: Service
metadata:
  name: sa-be-s
spec:
  type: LoadBalancer
  selector:
    name: sa-be
  ports:
  - port: 8080
    targetPort: 80
<块引用>

port 是云负载均衡器将侦听的端口(我们的 8080 示例)和 targetPort 是应用程序正在侦听的端口 Pods/容器。 Kubernetes 与您的云 API 一起创建 负载平衡器以及使流量达到负载所需的一切 端口 8080 上的平衡器一直返回到您的 Pods/容器 群集侦听 targetPort 80。

现在主要: 在幕后,许多实现创建了 NodePorts 以将云负载均衡器粘合到集群。交通流量通常是这样的。

enter image description here

相关问题