Unable to assign public ip address to AKS: pending forever

6/25/2019

I allocated an IP address for my resource group as the following:

az network public-ip create --resource-group myResourceGroup --name ipName --allocation-method static

Now, I'd like to assign it to my AKS so I just altered the yaml as it follows:

 apiVersion: v1
 kind: Service
 metadata:
 name: nginx
 spec:
   loadBalancerIP: xx.xx.xxx.xxx <--the ip generated before
   type: LoadBalancer
   ports:
   - port: 80
   selector:
    app: nginx-sgr

Then I run:

kubectl apply -f mykube.yaml

But it appears to be stuck:

NAME        TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
nginx   LoadBalancer      10.0.77.234   <pending>     80:32320/TCP   79m

By executing describe I get indeed the following:

Warning  CreatingLoadBalancerFailed  21m (x19 over 86m)  service-controller  Error creating 
load balancer (will retry): failed to ensure 
  load balancer for service default/nginx: user supplied IP Address 
  xx.xx.xxx.xxx was not found in resource group 
  MC_**myResourceGroup**_myAKSCluster_westeurope

please note that it seems it's searching in a resource group that is composed by the resource group I specified in the first command (the same as kubernates is) and other information...what am I doing wrong?

-- Phate
azure
azure-kubernetes

1 Answer

6/25/2019

As I know, the possible reason is that you need to assign your AKS the permission of the resource group which you create the public IP if you create it in another group. For more details, see Use a static IP address outside of the node resource group. And you need to add the annotations like below:

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-resource-group: myResourceGroup
  name: azure-load-balancer
spec:
  loadBalancerIP: 40.121.183.52
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: azure-load-balancer

Or you can just create the public IP in your AKS cluster nodes group. For you, the group name can be found in the error you provide: MC_**myResourceGroup**_myAKSCluster_westeurope.

-- Charles Xu
Source: StackOverflow