如何提供我的 AKS(外部 IP <Pending>)?

How can I provide my AKS (External IP <Pending>)?

我想在 Azure 上将我的微服务基础结构部署为 AKS。我创建了一个节点,上面有 3 个微服务 运行。我的 API 网关应该可以用 public IP 寻址,数据应该转发到我的其他两个微服务。

PS /home/jan-marius> kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
apigateway-77875f89cb-qcmnf   1/1     Running   0          18h
contacts-5ccc69f74-x287p      1/1     Running   0          18h
templates-579fc4984b-srv7h    1/1     Running   0          18h

到目前为止 good.After 我从 Microsoft Docs 创建了一个 public IP 并如下更改了我的 Yaml 文件。

az network public-ip create \
    --resource-group myResourceGroup \
    --name myAKSPublicIP \
    --sku Standard \
    --allocation-method static
apiVersion: apps/v1
kind: Deployment
metadata:
  name: apigateway
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apigateway
  template:
    metadata:
      labels:
        app: apigateway
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
        - name: apigateway
          image: xxx.azurecr.io/apigateway:11
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 250m
              memory: 512Mi
          ports:
          - containerPort: 8800
            name: apigateway

---
apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-dns-label-name: tegos-sendmessage
  name: apigateway
spec:
  loadBalancerIP: 20.50.10.36
  type: LoadBalancer
  ports:
  - port: 8800
  selector:
    app: apigateway


---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: contacts
spec:
  replicas: 1
  selector:
    matchLabels:
      app: contacts
  template:
    metadata:
      labels:
        app: contacts
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: contacts
        image: xxx.azurecr.io/contacts:12
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 250m
            memory: 512Mi
        ports:
        - containerPort: 8100
          name: contacts

---
apiVersion: v1
kind: Service
metadata:
  name: contacts
spec:
  ports:
  - port: 8100
  selector:
    app: contacts
---


apiVersion: apps/v1
kind: Deployment
metadata:
  name: templates
spec:
  replicas: 1
  selector:
    matchLabels:
      app: templates
  template:
    metadata:
      labels:
        app: templates
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: templates
        image: xxx.azurecr.io/templates:13
        resources:
         requests:
            cpu: 100m
            memory: 128Mi
         limits:
            cpu: 250m
            memory: 512Mi
        ports:
         - containerPort: 8200
           name: templates
---
apiVersion: v1
kind: Service
metadata:
  name: templates
spec:
  ports:
  - port: 8200
  selector:
    app: templates

但是,如果我想用get服务调用外部IP地址,状态是

S /home/jan-marius> kubectl get service apigateway
NAME         TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
apigateway   LoadBalancer   10.0.181.113   <pending>     8800:30817/TCP   19h
PS /home/jan-marius> kubectl describe service apigateway
Name:                     apigateway
Namespace:                default
Labels:                   <none>
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{"service.beta.kubernetes.io/azure-dns-label-name":"tegos-sendmessage"},"nam...
                          service.beta.kubernetes.io/azure-dns-label-name: tegos-sendmessage
Selector:                 app=apigateway
Type:                     LoadBalancer
IP:                       10.0.181.113
IP:                       20.50.10.36
Port:                     <unset>  8800/TCP
TargetPort:               8800/TCP
NodePort:                 <unset>  30817/TCP
Endpoints:                10.244.0.14:8800
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age                 From                Message
  ----    ------                ----                ----                -------
  Normal  EnsuringLoadBalancer  5m (x216 over 17h)  service-controller  Ensuring load balancer

我在网上看到,如果集群的位置与外部 IP 或 LoadBalancer 类型不匹配,就会发生此错误。我确信位置匹配。我不能确定 LoadBalancer 类型。外部 IP SKU 设置为标准。但是,我从来没有定义过LoadBalancer的类型,也不知道在哪里可以找到。谁能告诉我哪里做错了以及如何提供网络服务?

[![在此处输入图片描述][1]][1]
PS /home/jan-marius> az aks show -g SendMessageResource -n SendMessageCluster
{
  "aadProfile": null,
  "addonProfiles": {
    "httpapplicationrouting": {
      "config": {
        "HTTPApplicationRoutingZoneName": "e6e284534ad74c0d9c01.westeurope.aksapp.io"
      },
      "enabled": true,
      "identity": null
    },
    "omsagent": {
      "config": {
        "loganalyticsworkspaceresourceid": "/subscriptions/a553134ba7eb-cb83-484d-a05d-44bb70125b8a/resourcegroups/defaultresourcegroup-weu/providers/microsoft.operationalinsights/workspaces/defaultworkspace-a55ba7eb-cb83-484d-a05d-44bb334170125b8a-weu"
      },
      "enabled": true,
      "identity": null
    }
  },
  "agentPoolProfiles": [
    {
      "availabilityZones": null,
      "count": 1,
      "enableAutoScaling": null,
      "enableNodePublicIp": false,
      "maxCount": null,
      "maxPods": 110,
      "minCount": null,
      "mode": "System",
      "name": "nodepool1",
      "nodeLabels": {},
      "nodeTaints": null,
      "orchestratorVersion": "1.15.11",
      "osDiskSizeGb": 100,
      "osType": "Linux",
      "provisioningState": "Succeeded",
      "scaleSetEvictionPolicy": null,
      "scaleSetPriority": null,
      "spotMaxPrice": null,
      "tags": null,
      "type": "VirtualMachineScaleSets",
      "vmSize": "Standard_DS2_v2"
    }
  ],
  "apiServerAccessProfile": null,
  "autoScalerProfile": null,
  "diskEncryptionSetId": null,
  "dnsPrefix": "SendMessag-SendMessageResou-a55ba7",
  "enablePodSecurityPolicy": null,
  "enableRbac": true,
  "fqdn": "sendmessag-sendmessageresou-a55ba7-14596671.hcp.westeurope.azmk8s.io",
  "id": "/subscriptions/a55b3141a7eb-cb83-484d-a05d-44bb70125b8a/resourcegroups/SendMessageResource/providers/Microsoft.ContainerService/managedClusters/SendMessageCluster",
  "identity": null,
  "identityProfile": null,
  "kubernetesVersion": "1.15.11",
  "linuxProfile": {
    "adminUsername": "azureuser",
    "ssh": {
      "publicKeys": [
        {
          "keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7bzXktZht3zLbHrz3Xpv3VNhtrj/XmBKOIHB0D0ZpBIrsfXcg9veBov8n3cU/F/oKIfqcL2xaoktVwZFz9AjEi7qPXdxrsVLjV2+w0kPyC3ZC5JbtLSO4CFgn0MtclC6mE3OPYczYPoFdZI3/w/AmoZ6TsT7MupkCjKtrYIIaDZ/22zuTMYMvJro7cfjKI5OSR7soybXcoFKw+3tzwO9Mv9lUQr7x0eRCUAUJN6OziEI9p36fLEnNgRG4GiJJZP5aqqsVRUDuu8PF9pO0YLMBr3b2HHgzpDwSebZ6TU//okuc30cqG/2v2LkjBDRGrs5YxiSv3+ejr/9A4XGWup4Z"
        }
      ]
    }
  },
  "location": "westeurope",
  "maxAgentPools": 10,
  "name": "SendMessageCluster",
  "networkProfile": {
    "dnsServiceIp": "10.0.0.10",
    "dockerBridgeCidr": "172.17.0.1/16",
    "loadBalancerProfile": {
      "allocatedOutboundPorts": null,
      "effectiveOutboundIps": [
        {
          "id": "/subscriptions/a55b3142a7eb-cb83-484d-a05d-44bb70125b8a/resourceGroups/MC_SendMessageResource_SendMessageCluster_westeurope/providers/Microsoft.Network/publicIPAddresses/988314172c28-d4da-431e-b7f8-5acb08e468b4",
          "resourceGroup": "MC_SendMessageResource_SendMessageCluster_westeurope"
        }
      ],
      "idleTimeoutInMinutes": null,
      "managedOutboundIps": {
        "count": 1
      },
      "outboundIpPrefixes": null,
      "outboundIps": null
    },
    "loadBalancerSku": "Standard",
    "networkMode": null,
    "networkPlugin": "kubenet",
    "networkPolicy": null,
    "outboundType": "loadBalancer",
    "podCidr": "10.244.0.0/16",
    "serviceCidr": "10.0.0.0/16"
  },
  "nodeResourceGroup": "MC_SendMessageResource_SendMessageCluster_westeurope",
  "privateFqdn": null,
  "provisioningState": "Succeeded",
  "resourceGroup": "SendMessageResource",
  "servicePrincipalProfile": {
    "clientId": "9009bcd8-4933-4641-b00b-237e157d86589b"
  },
  "sku": {
    "name": "Basic",
    "tier": "Free"
  },
  "type": "Microsoft.ContainerService/ManagedClusters",
  "windowsProfile": null
}

如果您的 publicip 在另一个资源组中 - 您需要为 ip 指定资源组:

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-dns-label-name: tegos-sendmessage
    service.beta.kubernetes.io/azure-load-balancer-resource-group: myResourceGroup 
  name: apigateway
spec:
  loadBalancerIP: 20.50.10.36
  type: LoadBalancer
  ports:
  - port: 8800
  selector:
    app: apigateway