0

I'm writing something to clean up our old Azure resources, and one thing that comes up from time to time is public-ips still bound to a kubernetes-created loadbalancer even after the Ingress was deleted.

Using the azure CLI, I can get the public IP, find the ipConfiguration from that, which is used to name the load balancer rules and frontend ipconfig for that IP. I can get the load balancer rule resource IDs and delete those with "az resource delete" or the ResourceManagementClient. However I can't do the same with the LB Front End config even though it does have a resource_id. The AZ CLI has az network lb frontend-ip delete but I can't find the Azure API that this is calling. NetworkManagementClient.load_balancer_frontend_ip_configurations only has list() and get() methods, not delete().

I did try looking at the AZ CLI source here, but it is not easy reading! https://github.com/Azure/azure-cli/blob/dev/src/azure-cli/azure/cli/command_modules/network/aaz/latest/network/lb/frontend_ip/_delete.py#L64

What is the "approved" way to do this?

4
  • To delete the Load Balancer Frontend IP configuration using the Azure API, you're right that the Azure SDK (specifically NetworkManagementClient) doesn't provide a direct delete() method for the load_balancer_frontend_ip_configurations. You can use CLI command to delete az network lb frontend-ip delete -g MyResourceGroup --lb-name MyLb -n MyFrontendIp Commented Sep 17, 2024 at 11:35
  • OK, but the Azure CLI is written using the Python SDK isn't it? So there must be a way to do this in python, too... Commented Sep 17, 2024 at 11:37
  • @AnotherHowie - right now your question is only a requirement. If you want help with a python solution, you should first edit your question to show your relevant work so far (code, data, expected vs actual behavior, errors, etc - a minimal reproducible example) Commented Sep 18, 2024 at 3:33
  • How do you write a reproducible example of something that (at the time of writing the question) I can't find exists? ie. "Actual Behaviour: nothing happens because the API appears to not exist. Errors: there is no function call.". I'm not even looking for working code, just the intended way to manage these objects which don't behave like other Azure resources. Commented Sep 18, 2024 at 9:22

1 Answer 1

0

Deleting an Azure Loadbalancer Frontend IP configuration from python?

Here is the Python code to delete the Azure Loadbalancer Frontend IP configuration using SDK NetworkManagementClient

from azure.identity import DefaultAzureCredential
from azure.mgmt.network import NetworkManagementClient


credential = DefaultAzureCredential()
subscription_id = "8332bf56-fnfnvnvnv4daa-a507-d7e60e5f09a9"
network_client = NetworkManagementClient(credential, subscription_id)


resource_group_name = "biceprg"
lb_name = "venkat-lb"
frontend_ip_name = "venkat-frontend"


load_balancer = network_client.load_balancers.get(resource_group_name, lb_name)

configuration
if len(load_balancer.frontend_ip_configurations) <= 1:
    print(f"Cannot delete the only frontend IP configuration from load balancer '{lb_name}'.")
else:

    new_frontend_ip_configurations = [
        ipconfig for ipconfig in load_balancer.frontend_ip_configurations
        if ipconfig.name != frontend_ip_name
    ]


    load_balancer.frontend_ip_configurations = new_frontend_ip_configurations


    poller = network_client.load_balancers.begin_create_or_update(
        resource_group_name,
        lb_name,
        load_balancer
    )

    result = poller.result()
    print(f"Frontend IP configuration '{frontend_ip_name}' deleted successfully.")

Before executing the python script, I have 2 Frontend IP configurations.

enter image description here

After executing the code, the frontend named venkat-frontend configuration from the load balancer has been deleted successfully.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Once again: this is a custom solution based on nothing but a requirement. You didn't actually answer any question. Just give feedback to the OP in a comment under the question (as I've already done)
But, @DavidMakogon it was useful information that got me to working solution, instead of criticizing the format of the question. The (auto-generated?) Azure docs are particularly bad at this kind of overview information about how the various API objects fit together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.