azure - AKS 公共(public) IP 无法访问

标签 azure nginx kubernetes

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

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 购买了此公共(public) IP。如果我们从服务 yaml 中删除此 loadBalancerIP 并部署,然后使用 kubectl get services -n nginx-ingress 列出的 ip,那么当我们访问服务端点时它可以正常工作。但对于这个公共(public) IP 似乎没有任何作用。

请找到以下服务描述(kubectl 描述服务 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

请帮忙!!

最佳答案

众所周知,AKS创建完成后,Azure会创建两个资源组。

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

您可以使用 Azure CLI 命令创建公共(public) 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

结果如下:

enter image description here

注意:

1.创建不带 DNS 名称的 Azure 公共(public) IP 地址。
2.在此资源组MC_myResourceGRoup_myAKSCluster_eastus中创建Azure公共(public)IP地址。
3.您可以使用kubectl描述服务来检查状态,如下所示:

[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

关于azure - AKS 公共(public) IP 无法访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48859877/

相关文章:

ssl - Nginx 无限重定向

Docker-Compose、NGINX 和热重载配置

kubernetes - 在 Kubernetes 中创建作业和 cronjob 的命令式命令

c# - Azure函数从HttpTriggerFunction访问CloudBlobContainer

c# - 如何以线程安全、高性能的方式迭代索引数组?

azure - 如何执行 Windows Azure 备份?

amazon-web-services - 如何使用 Elastic beanstalk 和 Dockerrun.aws.json 正确部署到 AWS?

amazon-web-services - 使用 Anthos 的混合云和多云数据平台的多云解决方案

kubernetes - 我可以获得 storageclasses.storage.k8s.io 支持的访问模式吗?

namespaces - kubernetes - 动态更改 RC 的命名空间