【问题标题】:AKS public ip not accessibleAKS 公共 ip 无法访问
【发布时间】:2018-07-29 07:36:21
【问题描述】:

我的入口服务中有以下配置:

apiVersion: v1
kind: Service
metadata:
  name: nginx-ingress
  namespace: nginx-ingress
spec:
  externalTrafficPolicy: Local
  type: LoadBalancer
  loadBalancerIP: **.***.**.***
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
    name: http
  - port: 443
    targetPort: 443
    protocol: TCP
    name: https
  selector:
    app: nginx-ingress

我们从 azure 购买了这个公共 IP。如果我们从服务 yaml 中删除这个 loadBalancerIP 并部署,然后使用kubectl get services -n nginx-ingress 列出的 ip,当我们访问服务端点时它工作正常。但是使用这个公共 ip 似乎没有任何效果。

请查看以下服务说明 (kubectl describe service nginx-ingress -n nginx-ingress-os):

[openapianil@LHGOPENAPIDEV001 github]$ kubectl describe service nginx-ingress -n nginx-ingress-os
Name:                     nginx-ingress
Namespace:                nginx-ingress-os
Labels:                   <none>
Annotations:              kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"nginx-ingress","namespace":"nginx-ingress-os"},"spec":{"externalTrafficPolicy"...
Selector:                 app=nginx-ingress
Type:                     LoadBalancer
IP:                       10.0.0.44
IP:                       **.**.**.***
LoadBalancer Ingress:     **.**.**.***
Port:                     http  80/TCP
TargetPort:               80/TCP
NodePort:                 http  31247/TCP
Endpoints:                **.**.**.***:80
Port:                     https  443/TCP
TargetPort:               443/TCP
NodePort:                 https  32241/TCP
Endpoints:                **.**.**.***:443
Session Affinity:         None
External Traffic Policy:  Local
HealthCheck NodePort:     30880
Events:
  Type    Reason                Age   From                Message
  ----    ------                ----  ----                -------
  Normal  EnsuringLoadBalancer  1m    service-controller  Ensuring load balancer
  Normal  EnsuredLoadBalancer   43s   service-controller  Ensured load balancer

请帮忙!!

【问题讨论】:

  • 指定公网IP后,该服务是否部署成功?您能否运行此命令 kubectl describe service nginx-ingress 并将该输出发布到您的问题中?
  • @JasonYe-MSFT 更新了我的问题陈述。请帮忙。

标签: azure nginx kubernetes


【解决方案1】:

我们知道,AKS 创建完成后,Azure 会创建两个资源组。

如果要使用 IP 地址创建服务,则应在另一个资源组中创建静态 IP 地址,名称如 MC_myResourceGRoup_myAKSCluster_eastus。

您可以使用 Azure CLI 命令创建公共 IP 地址:

az network public-ip create --resource-group MC_myResourceGRoup_myAKSCluster_eastus --name myAKSPublicIP --allocation-method static

您也可以使用 Azure 门户创建它,但您不能向它添加 DNS。

然后你可以像这样使用静态IP地址:

apiVersion: v1
kind: Service
metadata:
  name: azure-vote-front1
spec:
  type: LoadBalancer
  loadBalancerIP: 52.224.235.119
  ports:
  - port: 80
  selector:
    app: azure-vote-front1

结果如下:

注意:

1.创建 Azure 公共 IP 地址没有 DNS 名称。
2.在此资源组MC_myResourceGRoup_myAKSCluster_eastus创建Azure公共IP地址。
3.可以使用kubectl describe service查看状态,如下:

[root@jasoncli@jasonye jason]# kubectl describe service azure-vote-front1
Name:                     azure-vote-front1
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=azure-vote-front1
Type:                     LoadBalancer
IP:                       10.0.76.241
IP:                       52.224.235.119
LoadBalancer Ingress:     52.224.235.119
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30416/TCP
Endpoints:                10.244.0.11:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age   From                Message
  ----    ------                ----  ----                -------
  Normal  CreatingLoadBalancer  45m   service-controller  Creating load balancer
  Normal  CreatedLoadBalancer   44m   service-controller  Created load balancer

更新:

这是我的 yaml 文件:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: azure-vote-back
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: azure-vote-back
    spec:
      containers:
      - name: azure-vote-back
        image: redis
        ports:
        - containerPort: 6379
          name: redis
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-back
spec:
  ports:
  - port: 6379
  selector:
    app: azure-vote-back
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: azure-vote-front
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: azure-vote-front
    spec:
      containers:
      - name: azure-vote-front
image: microsoft/azure-vote-front:v1
        ports:
        - containerPort: 80
        env:
        - name: REDIS
          value: "azure-vote-back"
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-front
spec:
  loadBalancerIP: 40.71.3.119
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: azure-vote-front

【讨论】:

  • 如果我们看上面的例子,一旦它处于上述状态,我们应该对telenet 52.224.235.119 80 喝啤酒吧?它应该得到连接的消息。但就我而言,即使在成功部署之后,它仍然会继续尝试连接。有什么想法吗?
  • 对同一问题再进行一次查询。我们可以在同一个负载均衡器 ip 上提供其他服务吗(希望它是不同端口的可能)。
  • @AnilKumarP 抱歉耽搁了,Azure 不支持一个 IP 地址用于多个服务。我在我的实验室测试它,得到这个错误消息:Original Error: autorest/azure: Service returned an error. Status=400 Code="PublicIPReferencedByMultipleIPConfigs" 和 Message="Public ip address /subscriptions/b834c23f/resourceGroups/MC_jasonakss_jasonakss_eastus/providers/Microsoft.Network/publicIPAddresses/jasonip1 is referenced by multiple ipconfigs in resource /subscriptions/b74c23f/resourceGroups/MC_jasonakss_jasonakss_eastus/providers/Microsoft.Network/loadBalancers/kubernetes."
  • @AnilKumarP 顺便问一下,静态 IP 地址对您有用吗?我已经更新了我的 yaml 来回答,请检查一下,如果您需要更多帮助,请告诉我。抱歉耽搁了:)
  • 非常感谢您的回复。我已经将一个 api 配置为公共 ip,它工作正常。我现在要做的是将此公共 ip 配置为我的 NGINX 服务器的 loadBalancerIP,该服务器分别在 2 个端口 80 和 443 http/https 上运行。这根本行不通。顺便问一下,您是如何识别此错误的?它在哪里抛出 PublicIPReferencedByMultipleIPConfigs?
【解决方案2】:

我在处理QuickStart 时遇到了这个问题,如果我在创建 AKS 时没有启用 RBAC,则 EXTERNAL-IP 被列为 localhost。为我启用 RBAC 时按预期工作。

【讨论】:

    猜你喜欢
    • 2020-09-06
    • 2018-08-23
    • 2020-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多