Search code examples
azure-virtual-networkazure-container-instances

(NetcfgInvalidSubnet) Subnet 'mySubnet' is not valid in virtual network 'myVnet'


I have a weird issue while trying to create an azure container instance referencing an existing virtual network and subnet. For that I am using the following command describes in microsoft docuementation running from azure CLI:

az container create

--name mycontainer   --resource-group myresourcegroup  --image crazlabjira01.azurecr.io/jira-servicemanagement:4.19.0 --vnet **myVnet** --vnet-address-prefix 172.27.0.0/16 --subnet **mySubnet** --subnet-address-prefix 172.27.14.0/24

My subnet is in the range of the Vnet so why does the command returns the following error :

(NetcfgInvalidSubnet) Subnet 'mySubnet' is not valid in virtual network 'myVnet'

Please note that if I create that container using the UI and network defined above, it works without any trouble

Thanks for help


Solution

  • I tested in my environment and it is working fine for me.

    az container create --name myconatainer98044 -g v-ra****-***tr**e --image mycontainer7723.azurecr.io/atlassian/jira-servicemanagement:latest --vnet RG-VNET --vnet-address-prefix 10.0.0.0/16 --subnet TestSubnet --subnet-address-prefix 10.0.1.0/24
    

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    When you create a virtual network you can configure the address space. By default, I was given an address space of 10.0.0.0/16 which allows addresses from 10.0.0.0 to 10.0.255.255.

    By changing the subnet to a valid value for a 10.0.0.0/16 address space, like 10.0.1.0/24, you will likely be successful:

    For you Make Sure the subnet that you are trying to use is not being used by other resource provider. Here you might be trying to use a subnet with 172.27.14.0/24 which is already in use.

    Example : If you using a subnet for creating a SQL instance and the same subnet you are using for creating the Container Instance it will throw an error which you are getting. So Microsoft doesn’t support the same subnet to create a different resource provider.

    In my Case my TestSubnet is delegated to Microsoft.Containerintance

    enter image description here

    Please refer this document for get the clear understanding.