AKS does not create Loadbalancer in the correct subnet
I'm using https://docs.microsoft.com/en-us/azure/templates/microsoft.containerservice/managedclusters and the Terraform provider https://www.terraform.io/docs/providers/azurerm/r/kubernetes_cluster.html
AKS spins up the agent nodes in the specified subnet. However when I spin up a service with the yaml below, the internal load balancer is spun up in the MC_ resource group and the Vnet in the MC_resource group and not in the subnet specified in vnetSubnetID parameter
apiVersion: v1
kind: Service
metadata:
name: kuard-service-internal
annotations:
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
type: LoadBalancer
ports:
- port: 8080
selector:
app: kuard-front
Example response received:
Error creating load balancer (will retry): Failed to ensure load balancer for service default/kuard-service-internal: [ensure(default/kuard-service-internal): lb(kubernetes-internal) - failed to ensure host in pool: "network.InterfacesClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code=\"NetworkInterfaceAndInternalLoadBalancerMustUseSameVnet\" Message=\"Network interface /subscriptions/xxxxxxx/resourceGroups/MC_aks-cluster_westeurope/providers/Microsoft.Network/networkInterfaces/aks-pool0001-17812977-nic-0 uses internal load balancer /subscriptions/xxxxxxx/resourceGroups/MC_aks-cluster_westeurope/providers/Microsoft.Network/loadBalancers/kubernetes-internal but does not use the same VNET
Expected behaviour for AKS clusters using private vNets is the internal balancer appears in the same vNet as the agent NICs, which would allow successful creation.
Seems the subnet configured in azure cloud provider is not same with virtual machine's primary interface's subnet.
A workaround of this problem is set service annotation service.beta.kubernetes.io/azure-load-balancer-internal-subnet=<subnet-name>
@feiskyer we tried this but the annotation is ignored. It seems to be in 1.9 which hasn't been rolled out yet. #103
Adding the azure-load-balancer-internal-subnet annotation appears to cause AKS to try and create an LB in the correct Subnet as I received 403 error when it tried to configure the subnet. I got past that by adding the Service Principle as a Contributor to the subnet. However, I'm now stuck on a less descriptive error.
Error creating load balancer (will retry): failed to ensure load balancer for service default/azure-vote-front: ensure(default/azure-vote-front): lb(kubernetes-internal) - failed to get subnet: aks-vnet-11111111/aks-subnet
I am experiencing the same issue. The internal loadbalancer is created just fine when using aks basic network but but fails when using aks with advanced network. External loadbalancer creates fine on both however.
Using YAML of:
apiVersion: v1 kind: Service metadata: name: lb-int annotations: service.beta.kubernetes.io/azure-load-balancer-internal: "true" spec: type: LoadBalancer ports:
- name: hydro port: 80 targetPort: hydro-port selector: app: hydro
and error of: Code="NetworkInterfaceAndInternalLoadBalancerMustUseSameVnet"
Network interface /subscriptions/xxxxxxxxxxx/resourceGroups/MC_xxxxxxxxxx_centralus/providers/Microsoft.Network/networkInterfaces/aks-agentpool-10057859-nic-0
uses internal load balancer /subscriptions/xxxxxxxxxxx/resourceGroups/MC_hxxxxxxxxxx_centralus/providers/Microsoft.Network/loadBalancers/kubernetes-internal
but does not use the same VNET /subscriptions/xxxxxxxxxxx/resourceGroups/MC_xxxxxxxxxx_CENTRALUS/providers/Microsoft.Network/virtualNetworks/AKS-VNET-99999999) as the load balancer.
I am getting the same error in the Central US region as wittry. I do see the LB created as kubernetes-local but the backend pool named 'kubernetes' that is not associated to any availability set.
I'm able to repro this as well. I'm seeing "vnetName": "aks-vnet-28513887" inside /etc/kubernetes/azure.json on my nodes.
Looks like AKS auto-created a VNET and populated azure.json with its details rather than the VNET I specified at cluster creation time.
@noelbundick Yes, the default VNET got created and the wrong azure.json is a known issue and a fix is underway.
I am looking at the LB issue and will update soon.
@hibri @murraypete @feiskyer @cdhunt @wittry @bjd145 @noelbundick
Confirmed the reported internal LB creation issue. It is tied to the wrong Azure Cloud Config consumed in controller manager pod. The fix is currently being tested, and I will update in this issue.
Thanks for reporting this issue and your patience!
Experienced this today too
Region : EastUS K8s v : 1.9.6
Keep us posted on a resolution :)
The fixed has been tested and it is in the process of releasing. It is expected to be rolled out next week.
Unfortunately a new cluster needs to be deployed to fix this issue. Sorry for the inconvenience.
Could someone please clarify what is the format for the service.beta.kubernetes.io/azure-load-balancer-internal-subnet attribute value ? Should it be something like /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupId>/providers/Microsoft.Network/virtualNetworks/<vnetId>/subnets/<subnetId> ? Or is the syntax different?
service.beta.kubernetes.io/azure-load-balancer-internal-subnet
@valorl it is subnet name.
@hibri @murraypete @feiskyer @cdhunt @wittry @bjd145 @noelbundick @serbrech @valorl The fix has been sent out and in the pipeline for releasing. My estimate is that the whole releasing process will take 3-4 days WW.
@feiskyer so just the last <subnetId> part then ? E.g. if my subnet is called MySubnet and it's in the VNET MyVnet, I still just say MySubnet ? How does Kubernetes know which VNET is the subnet from. Also, doesn't seem to work for me, it just creates the ILB in the default 10.240.0.0/16 kubernetes subnet
It gets the subnet from configured VNET in /etc/kubernetes/azure.json ( vnetName).
Alright, my apologies, I didn't completely understand the azure.json issue before. I tried to manually edit azure.json on all my nodes with proper vnetName vnetResourceGroup and subnetName , but the ILB still got created in the incorrect subnet. Is there something in K8S I need to restart maybe ? Should this hack even work?
I don't think you could edit that in AKS. AKS manages kube-controller-manager for you. So if you want to use a different subnet (from azure.json one), you need to set annotation service.beta.kubernetes.io/azure-load-balancer-internal-subnet=<subnet-name>
Yeah ok, so that's not gonna work for me since my subnet is in a different vnet, which itself is in a different resource group. Looking at the source, there don't seem to be any annotations for that, only the subnet name. Hopefully the fix is gonna arrive soon :)
@valorl That's not supported on Azure. They should be on same vnet.