Skip to main content

How to create Service type LoadBalancer with private ip address from assigned vnet-subnet

Use-case - To expose the service within virtual network as Internal LoadBalancer

By default, when we create service type LoadBalancer without customized annotations in AKS(Azure Kubernetes Service), then AKS will create Load Balancer with Public IP attached to it, through which application can be accessible to internet world.

However, it is possible that we may need to create service to be exposed within virtual network only, however with service type Load Balancer.

For this, we need to add service.beta.kubernetes.io/azure-load-balancer-internal: "true" in annotations in kubernetes service manifest file.

Create an Internal LoadBalancer

            
apiVersion: v1
kind: Service
metadata:
  name: nameOfService
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
  type: LoadBalancer
  ports:
  - port: 8080
    targetPort: 8080
  selector:
    app: nameOfApplication               
            
        

Define particular private ip address

For this, we need to add loadBalancerIP in spec with required IP address from the same subnet of AKS.

Ex.

            
apiVersion: v1
kind: Service
metadata:
  name: nameOfService
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
  type: LoadBalancer
  loadBalancerIP: 10.10.10.10
  ports:
  - port: 8080
    targetPort: 8080
  selector:
    app: nameOfApplication                 
            
        

Define particular subnet

For this, we need to add service.beta.kubernetes.io/azure-load-balancer-internal-subnet: "subnetName" in annotations

Ex.

            
apiVersion: v1
kind: Service
metadata:
  name: nameOfService
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
    service.beta.kubernetes.io/azure-load-balancer-internal-subnet: "subnetName"
spec:
  type: LoadBalancer
  loadBalancerIP: 10.10.10.10
  ports:
  - port: 8080
    targetPort: 8080
  selector:
    app: nameOfApplication                  
            
        

Comments

Popular posts from this blog

Install InfluxDB on AWS EKS using Helm

Create namespace for influxdb kubectl create ns influxdb We'll store InfluxDB data on AWS EBS as persistent storage, hence for that create storage class apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: influxdb provisioner: kubernetes.io/aws-ebs parameters: type: gp2 fsType: ext4 allowVolumeExpansion: true Install using Helm - In this command we've set few values like namespace, service type, storageclass and its size helm install influxdb stable/influxdb --namespace influxdb --set service.type=LoadBalancer,persistence.enabled=true,persistence.storageClass=influxdb,persistence.size=...

How to clone Github repository using SSH

Run ssh-keygen Upload ssh public key to github account curl -u "gitUsername:password" --data '{"title":"keyName","key":"'"$(cat ~/.ssh/id_rsa.pub)"'"}' https://api.github.com/user/keys Sample output of ssh public key upload command { "id": 1234567890, "key": "ssh-rsa aaaaaaaaaaaaaaaaaaaa/dddd/+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "url": "https://api.github.com/user/keys/123456...

How to read user's input in Bash Script

Create shell script file as below: #!/bin/bash echo "Enter your name!" read name echo "Welcome to Mars $name" Make script file executable chmod u+x test.sh Run script sh test.sh Output of the script: Enter your name! Rectangle Welcome to Mars Rectangle