How we can assign External IP's to our service in kubernetes with metallb

kanav sharma 0 Reputation points
2023-12-21T18:27:44.6433333+00:00

Hello,

I have created a cluster using kubeadm with two azure virtual machines(one master and one node). Now i need external IP's for service LoadBalancer, i am using metalLB for assinging external IP's. I need the IP's from azure i.e virtual machines that i have created. Please do the needful.

Thanks,

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,780 questions
Azure Kubernetes Service
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,463 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Anveshreddy Nimmala 3,550 Reputation points Moderator
    2023-12-27T04:00:24.9133333+00:00

    Hello kanav sharma,

    Welcome to Microsoft Q&A Platform, thanks for posting your query here.

    1.Create a new Public IP address in Azure portal or using Azure CLI.

    az network public-ip create --name <your-ip-name> --resource-group <your-resource-group> --allocation-method Static --sku Standard

    2.Get the IP address of the Public IP address you just created in portal or by azure CLI.

    az network public-ip show --name <your-ip-name> --resource-group <your-resource-group> --query ipAddress --output tsv

    3.Create a new config map for MetalLB.

    4.Create a new service of type LoadBalancer.

    apiVersion: v1
    kind: Service
    metadata:
      name: <your-service-name>
      annotations:
        metallb.universe.tf/address-pool: <your-ip-address>
    spec:
      type: LoadBalancer
      ports:
      - name: http
        port: 80
        targetPort: 8080
      selector:
        app: <your-app-label>
    

    5.Wait for the external IP address to be assigned.

    Hopes this answer is helpful, Please accept the answer for community purpose.


  2. Anveshreddy Nimmala 3,550 Reputation points Moderator
    2024-01-09T04:50:21.9566667+00:00

    Hello kanav sharma,

    Thankyou for replying back,

    yes, you can use Azure Public IP address prefix to associate a range of public IP addresses to your Kubernetes services.

    This will allow you to assign external IP addresses to a large number of pods without having to create individual public IP addresses for each pod.

    1.Create an Azure Public IP address prefix. use this document to create public IP prefix.

    https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/public-ip-address-prefix

    2.Create a Kubernetes Service of type LoadBalancer.

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service
      annotations:
        service.beta.kubernetes.io/azure-load-balancer-resource-group: my-resource-group
        service.beta.kubernetes.io/azure-load-balancer-internal: "false"
        service.beta.kubernetes.io/azure-load-balancer-public-ip-prefix: my-public-ip-prefix
    spec:
      type: LoadBalancer
      ports:
      - port: 80
        targetPort: 8080
      selector:
        app: my-app
    

    replace my-resource group with your azure resource group

    replace my-service with your service name

    replace 80 and 8080 with port you want expose and target port

    3.Wait for the Azure Load Balancer to get created.

    kubectl get service my-service -w

    4Once Azure Load Balancer creation completes, the EXTERNAL-IP will be available.

    NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

    my-service LoadBalancer 10.0.68.83 20.81.108.180 80:31523/TCP 18s

    Hope this Answer helps you , please accept the answer if it is helpful for community purpose so that it can help others, else post back if any query we will work on it to provide better solution.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.