I am facing a interesting problem in a Jenkins pipeline. I am trying to create a frontend ip for a load balancer in Azure with the following command:
sh "az network lb frontend-ip create \
-g ${RESOURCE_GROUP} \
--lb-name ${LB_NAME} \
--subnet '${SUBNET_ID}' \
--name ${DNS_HOST}
--zone {1,2,3} \
--only-show-errors"
The command works on my local computer, but in Jenkins sh puts single quotes around the --zone parameter and then the command fails (subnet was shortened to **** by me for better visibility):
+ az network lb frontend-ip create -g RG --lb-name LB --subnet '****' --name NAME --zone '{1,2,3}' --only-show-errors
ERROR: az network lb frontend-ip create: '{1,2,3}' is not a valid value for '--zone'. Allowed values: 1, 2, 3.
Examples from AI knowledge base:
az network lb frontend-ip create -g MyResourceGroup -n MyFrontendIp --lb-name MyLb --private-ip-address 10.10.10.100 --subnet MySubnet --vnet-name MyVnet
Create a frontend ip address for an internal load balancer.
az network lb frontend-ip create -g MyResourceGroup -n MyFrontendIp --lb-name MyLb --public-ip-address MyFrontendIp
Create a frontend ip address for a public load balancer.
https://aka.ms/cli_ref
Read more about the command in reference docs
I tried a lot of combinations of escapes \ and workarounds without success. Did anyone also faced this issue and was able to solve it?
Related
I have created a Kubernetes cluster ( 1 master, 2 workers VMs) using kubeadm on Azure. Node type service is working as expected. But Load Balancer service type is not working.
I have created the public IP address in azure and attached this IP to the service. I could see IP Address is attached for the service but this IP address is not accessible from outside.
And I have created the load balancer in Azure and attached the load balancer public IP address to the service that I have created in azure. This option also didn't work.
Just curious to know how to configure Load Balancer Service type in azure VM.
I have tried with aks and it worked with out any issues.
• I would suggest you to please follow the steps as given by me below for creating an AKS cluster in Azure and attaching a load balancer to that AKS cluster with a public IP for the front end for it. The steps for doing the said should be as below: -
a) Firstly, execute the below command in Azure CLI in Azure BASH cloud shell. The below creates an AKS cluster with two nodes in it of type ‘Linux’ with a ‘Standard’ load balancer in the said resource group where the ‘VM set type’ should be set as ‘VirtualMachineScaleSets’ with the appropriate version of Kubernetes being specified in it: -
az aks create \
--resource-group <resource group name>\
--name <AKS cluster name> \
--vm-set-type <VMSS or Availability set> \
--node-count <node count> \
--generate-ssh-keys \
--kubernetes-version <version number> \
--load-balancer-sku <basic or standard SKU>
Sample command: -
az aks create \
--resource-group AKSrg \
--name AKStestcluster \
--vm-set-type VirtualMachineScaleSets \
--node-count 2 \
--generate-ssh-keys \
--kubernetes-version 1.16.8 \
--load-balancer-sku standard
I would suggest you to please use the below command to check the installed version of Kubernetes orchestrator in your Azure BASH cloud shell according to the region specified and use the appropriate version in the above command: -
az aks get-versions --location eastus --output table
Then, I would suggest you use the below command for getting credentials of the AKS cluster created: -
az aks get-credentials --resource-group <resource group name> --name <AKS cluster name>
b) Then execute the below command for getting the information of the created nodes: -
kubectl get nodes
Once the information is fetched, then load the appropriate ‘YAML’ files in the AKS cluster and apply them to be run as an application on them. Then, check the service state as below: -
kubectl get service <application service name> --watch
c) Then press ‘Ctrl+C’, after noting the public IP address of the load balancer. Then execute the below command for setting the managed outbound public IP for the AKS cluster and the configured load balancer: -
az aks update \
--resource-group myResourceGroup \
--name myAKSCluster \
--load-balancer-managed-outbound-ip-count 1 ’
This will ensure that the services running in the back end will have only one public IP in the front end. In this way, you will be able to create an AKS cluster with load balancer having a public IP address.
This is the command that I tried to use and the error message received is shown below the command
az network lb create --name <name> -g <RG name> --frotnend-ip-name <frontend_name> --frontend-ip-zone "1","2","3" -l southeastasia --private-ip-address <“static_ip”> --private-ip-address-version IPv4 --sku Standard --subnet “<subnet_id>” --subnet-address-prefix “<prefix>” --vnet-name “<vnet_name>” --public-ip-address “”
Below is the error received for the command
az network lb create: '1, 2, 3' is not a valid value for '--frontend-ip-zone'. Allowed values: 1, 2, 3.
You should first create the LB then add frontend-IP to the LB,
Create LB:
az network lb create -g MyResourceGroup -n MyLb --sku Standard
Add Zone redundant frontend across Zones,
az network lb frontend-ip create -g {rg} --lb-name lb -n LoadBalancerFrontEnd -z 1 2 3 --vnet-name vnet --subnet subnet
We are working on Public PR to enable this feature during the creation of LB itself.
I have created my VNET & SubNet as mentioned below
RESOURCE_GROUP="POC-RG"
LOCATION="westus"
APIMNAME="poc-apim-98"
PUBLISHER="Demo"
PUBLISHEREMAIL="myemail#demo.com"
SKU="Premium"
VNETNAME="app-vnet"
APITYPE="External"
az network vnet create \
--resource-group ${RESOURCE_GROUP} \
--name ${VNETNAME} \
--location ${LOCATION}
az network vnet subnet create \
--resource-group ${RESOURCE_GROUP} \
--vnet-name ${VNETNAME} \
--name apim \
--address-prefixes 10.0.5.0/24
and I want to provision the Azure API Management in the apim subnet created above
az apim create --name ${APIMNAME} -g ${RESOURCE_GROUP} -l ${LOCATION} --sku-name ${SKU} --publisher-email ${PUBLISHEREMAIL} --publisher-name ${PUBLISHER} --virtual-network ${APITYPE}
Looks like Azure CLI does not take the subnet parameter while creating the APIM, how do I set the subnet and create the Azure API Management using azure cli?
You are right. For some reason az apim create does not provide option to input a subnet reference of a VNET.
You have 2 options:
Use ARM template. Refer Create an API Management service in External Virtual Network for sample template.
az group deployment create --resource-group <my-resource-group> --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/201-api-management-create-with-external-vnet/azuredeploy.json
Or,
Use az resource command to add subnet reference after you create APIM.
az apim create --name ${APIMNAME} -g ${RESOURCE_GROUP} -l ${LOCATION} --sku-name ${SKU} --publisher-email ${PUBLISHEREMAIL} --publisher-name ${PUBLISHER} --virtual-network ${APITYPE}
$apimResourceId = az apim show -n ${APIMNAME} -g ${RESOURCE_GROUP} --query 'id' -o json
$subnetResourceId = az network vnet subnet show -g ${RESOURCE_GROUP} -n apim --vnet-name ${VNETNAME} --query 'id' -o json
az resource update --ids $apimResourceId --set properties.virtualNetworkConfiguration.subnetResourceId=$subnetResourceId
I am taking a course and stuck for almost a week. I created a VM and now it wants me to change the IP config method to static. The exact words are.
"You have created a ubuntu virtual machine in the second step, in which check the public IP (publicIpAllocationMethod) address and change it to Static by executing the azure CLI commands."
I created the VM with below command.
az vm create -n MyVm1 -g groupname --admin-username "n1234" --admin-password "nk123#9090" --location westUS --image UbuntuLTS
Got the VM NIC with below command.
nic_id=$(az vm show -g gropname -n MyVm1 -d --query networkProfile.networkInterfaces[0].id)
az network nic show --ids MyVm1VMNic
I have the IP of the VM but not sure how to change it to static.
I got it resolved by using the below command.
az network public-ip update -g GROUPNAME -n MyVm1PublicIP --allocation-method Static
What you're looking for can be found here: https://learn.microsoft.com/en-us/cli/azure/network/nic/ip-config?view=azure-cli-latest#az-network-nic-ip-config-update
With your example, you would run the following:
nic_id=$(az vm show -g gropname -n MyVm1 -d --query
networkProfile.networkInterfaces[0].id --output tsv)
nicName=$(az network nic show --ids $nic_id --query name --output tsv)
ipconfig=$(az network nic show --ids $nic_id --query ipConfigurations[0].name
--output tsv)
az network nic ip-config update -g gropname --nic-name $nicName -n $ipconfig --private-ip-address <static ip address>
By setting the private IP, the IP configuration will be updated to static. The above code relies on the VM having a single NIC, which is assumed based on your example.
Hopefully that helps!
I'm trying to automate few of our BAT script and for this our script need to know the private IP of each instances of VMSS(no public IP for instances).
Is there a way to query the private IP of all instances under a particular VMSS using azure cli. I tried few command of LB and VMSS but didn't find a solution yet.
az vmss show -g <rg> -n <vmss>
az vmss list-instances -g <rg> -n <vmss>
az vmss nic list-vm-nics -g <rg> --vmss-name <vmss> --ids <id>
az network lb address-pool list -g <rg> --lb-name <lb>
az vmss list-instance-connection-info -g <rg> -n <vmss>
Any help is highly appreciable and I'm not looking for powershell.
You can use the Azure CLI and bash command:
az vmss nic list -g groupName --vmss-name ScaleSetName | grep -w "privateIpAddress"
It can show all the private ips like this:
"privateIpAddress": "192.168.1.4",
"privateIpAddress": "192.168.1.5",