Reading Time: 3 minutes
Follow by Email

The more I use AKS the more cool things I find. This article is one of them. So when AKS is created Azure creates a special resource group for all of the resources like load balancers, vmss, etc. This resource group starts with MC_. When you create a service in kubernetes that uses type load balancer it will add a public IP address to this resource group too. Nice and easy. But say you have a public IP address already created but not in use, one that you have given access through some NSG’s or Firewalls to your other resources. Using this guide below you can do this. It even shows you how to create a new public IP address and set the correct permissions.

Enough talk lets get to it. Oh and as you can probably see I have a little video that walks through the steps also.

Create a static IP address and set permissions

To create a Public IP address use the following command. Just change the resource group and name to something you want to use.

If you missed the IP address in the output above you can use the following command to retrieve it.

So now we have our public IP It’s time to give the service principal used by the AKS cluster the delegated permissions to the resource group the public IP address resides in. To do that use the following. Just make sure you change the 3 environment values to match yours.

Create a kubernetes service using the static IP

To use the IP address we need to add an annotation to the service definition. You can see my example below with the annotation. Just make sure you change the resource group and IP address values to match yours.

apiVersion: v1
kind: Service
annotations: Pixel-General-UKS
name: azurelbpip
type: LoadBalancer
- port: 433
app: azurelbpip
view raw azurelbpip.yaml hosted with ❤ by GitHub

Save the above as azurelbpip.yaml and save it somewhere reachable.

Then navigate to the folder that has your yaml file in and run the following.

To check the IP address has been assigned use the following command.

As soon as you see the IP address you are all set. Just hit Ctrl+C to exit the watch.

There you have it! You have now created an Azure load balancer with a static IP address for your AKS cluster.

I hope you found this article helpful. If you have any questions please reach put.

Follow by Email

Pixel Robots.

I’m Richard Hooper aka Pixel Robots. I started this blog in 2016 for a couple reasons. The first reason was basically just a place for me to store my step by step guides, troubleshooting guides and just plain ideas about being a sysadmin. The second reason was to share what I have learned and found out with other people like me. Hopefully, you can find something useful on the site.

1 Comment

Romain Wilbert · February 4, 2020 at 9:20 am

I can’t figure if this is possible to use same public IP for mutiple services using different ports. This is silly to burn a public IP each time a new service is deployed.

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *