Skip to content

Latest commit

 

History

History
292 lines (206 loc) · 11.5 KB

subnet-create.md

File metadata and controls

292 lines (206 loc) · 11.5 KB

Creating a subnet

Subnets are created in cloud networks. A new subnet is located in one of the availability zones. Resources can be connected to a subnet if they reside in the same availability zone as the subnet itself.

{% list tabs group=instructions %}

  • Management console {#console}

    1. In the [management console]({{ link-console-main }}), go to the folder where you need to create a subnet.

    2. In the list of services, select {{ ui-key.yacloud.iam.folder.dashboard.label_vpc }}.

    3. In the left-hand panel, select subnets {{ ui-key.yacloud.vpc.switch_networks }}.

    4. At the top right, click {{ ui-key.yacloud.common.create }}.

    5. In the {{ ui-key.yacloud.vpc.subnetworks.create.field_name }} field, specify the subnet name. The naming requirements are as follows:

      {% include name-format %}

    6. (Optional) In the {{ ui-key.yacloud.vpc.subnetworks.create.field_description }} field, add a description.

    7. In the {{ ui-key.yacloud.vpc.subnetworks.create.field_zone }} field, select an availability zone from the drop-down list.

    8. In the {{ ui-key.yacloud.vpc.subnetworks.create.field_network }} field, specify a cloud network. Make sure to create it in advance.

    9. In the {{ ui-key.yacloud.vpc.subnetworks.create.field_ip }} field, enter the subnet IP address and mask. For more information about subnet IP address ranges, see Cloud networks and subnets. If you need to enter more CIDRs, click {{ ui-key.yacloud.vpc.subnetworks.create.button_add-cidr }}.

    10. (Optional) Set {{ ui-key.yacloud.vpc.subnetworks.create.section_dhcp-options }}. To do this:

      1. In the {{ ui-key.yacloud.vpc.subnetworks.create.field_domain-name }} field, specify a DNS domain to search for unqualified names.
      2. In the {{ ui-key.yacloud.vpc.subnetworks.create.field_domain-name-servers }} field, click {{ ui-key.yacloud.vpc.subnetworks.create.button_add-domain-name-server }} and enter the address of your DNS server. You can specify multiple DNS servers.
      3. In the {{ ui-key.yacloud.vpc.subnetworks.create.field_ntp-servers }} field, click {{ ui-key.yacloud.vpc.subnetworks.create.button_add-ntp-server }} and enter the address of your NTP server. You can specify multiple NTP servers.
    11. Click {{ ui-key.yacloud.vpc.subnetworks.create.button_create }}.

  • CLI {#cli}

    {% include include %}

    {% include default-catalogue %}

    To create a subnet:

    1. See the description of the CLI command for creating a subnet:

      yc vpc subnet create --help
      
    2. Get a list of cloud networks in the required folder:

      yc vpc network list --folder-id b1g6ci08ma55********
      

      Result:

      +----------------------+----------------+
      |          ID          |      NAME      |
      +----------------------+----------------+
      | enpavfmgapum******** | test-network-1 |
      | enplom7a98s1******** | default        |
      +----------------------+----------------+
      
    3. Select the NAME or ID of the cloud network you need. Create a subnet in the default folder:

      yc vpc subnet create \
        --name test-subnet-1 \
        --description "My test subnet" \
        --network-id enplom7a98s1******** \
        --zone {{ region-id }}-a \
        --range 192.168.0.0/24
      

      Where:

      • --network-id: Cloud network ID. You can also select a cloud network by specifying its name via the --network-name flag. Specify the name of the cloud network to create the subnet in and the CIDR.
      • --zone: Availability zone where the subnet is created. If this flag is not set, the subnet is created in the default availability zone.
      • --range: List of internal IPv4 addresses defined for this subnet, e.g., 10.0.0.0/22 or 192.168.0.0/16. Make sure the addresses are unique within the network. The minimum subnet size is /28, the maximum subnet size is /16. Only IPv4 is supported.

      The subnet naming requirements are as follows:

      {% include name-format %}

      yc vpc subnet create \
        --name test-subnet-1 \
        --description "My test subnet" \
        --network-name test-network-1 \
        --zone {{ region-id }}-a \
        --range 192.168.0.0/24
      

      The --name and --description flags are optional: you can create a subnet without any name or description and access it by ID.

    4. Get a list of all subnets in the default folder:

      yc vpc subnet list
      

      Result:

      +----------------------+-----------------------+------------------------+
      |          ID          |         NAME          | ... |       RANGE      |
      +----------------------+-----------------------+------------------------+
      ...
      | e2l0psbfoloe******** | test-subnet-1         | ... | [192.168.0.0/24] |
      ...
      +----------------------+-----------------------+-----+------------------+
      

      Get the same list with more details in YAML format:

      yc vpc subnet list --format yaml
      

      Result:

      ...
      
      - id: e2l0psbfoloe********
        folder_id: b1g6ci08ma55********
        created_at: "2018-10-24T12:25:58Z"
        name: test-subnet-1
        description: My test subnet
        network_id: enplom7a98s1********
        zone_id: {{ region-id }}-a
        v4_cidr_blocks:
        - 192.168.0.0/24
      
      ...
      
  • {{ TF }} {#tf}

    {% include terraform-definition %}

    {% include terraform-install %}

    1. In the configuration file, describe the subnet parameters:

      • name: Subnet name. The naming requirements are as follows:

        {% include name-format %}

      • description: Description of the subnet.

      • v4_cidr_blocks: List of IPv4 addresses to deal with outgoing and incoming traffic, e.g., 10.0.0.0/22 or 192.168.0.0/16. Make sure the addresses are unique within the network. The minimum subnet size is /28, the maximum subnet size is /16. Only IPv4 is supported.

      • zone: Availability zone.

      • network_id: ID of the network where the subnet is created.

      Here is an example of the configuration file structure:

      resource "yandex_vpc_subnet" "lab-subnet-a" {
        name           = "<subnet_name>"
        description    = "<subnet_description>"
        v4_cidr_blocks = ["<IPv4_address>"]
        zone           = "<availability_zone>"
        network_id     = "<network_ID>"
      }

      To add, update, or delete a subnet, use the yandex_vpc_subnet resource with the network specified in the network_id field (see an example).

      For more information about the parameters of the yandex_vpc_subnet resource in {{ TF }}, see the [provider documentation]({{ tf-provider-resources-link }}/vpc_subnet).

    2. Make sure the configuration files are correct.

      1. In the command line, go to the directory where you created the configuration file.

      2. Run a check using this command:

        terraform plan
        

      If the configuration is described correctly, the terminal will display a list of created resources and their parameters. If the configuration contains any errors, {{ TF }} will point them out.

    3. Deploy cloud resources.

      1. If the configuration does not contain any errors, run this command:

        terraform apply
        
      2. Confirm creating the resources: type yes in the terminal and press Enter.

        All the resources you need will then be created in the specified folder. You can check the new resources and their configuration using the [management console]({{ link-console-main }}) or these CLI commands:

        yc vpc subnet list
        
  • API {#api}

    To create a subnet, use the create REST API method for the Subnet resource or the SubnetService/Create gRPC API call, and provide the following in the request:

    • ID of the folder where the subnet will be placed, in the folderId parameter.
    • ID of the network where the subnet will be placed, in the networkId parameter.
    • ID of the availability zone where the subnet will be placed, in the zoneId parameter.
    • List of internal IPv4 addresses defined for this subnet, in the v4CidrBlocks[] array, e.g., 10.0.0.0/22 or 192.168.0.0/16. Make sure the addresses are unique within the network. The minimum subnet size is /28, the maximum subnet size is /16. Only IPv4 is supported.

    {% include get-subnet-id %}

    {% include get-catalog-id %}

{% endlist %}

Examples {#examples}

{% list tabs group=instructions %}

  • CLI {#cli}

    Create a subnet with a name and description in the selected folder:

    yc vpc subnet create \
      --name test-subnet-1 \
      --description "My test subnet" \
      --folder-id b1g6ci08ma55******** \
      --network-id enplom7a98s1******** \
      --zone {{ region-id }}-a \
      --range 192.168.0.0/24
    

    Create a subnet with DHCP settings:

    yc vpc subnet create \
      --name test-subnet-1 \
      --description "My test subnet" \
      --folder-id b1g6ci08ma55******** \
      --network-id enplom7a98s1******** \
      --zone {{ region-id }}-a \
      --range 192.168.0.0/24 \
      --domain-name test.domain \
      --domain-name-server 192.168.0.100 \
      --ntp-server 192.168.0.101
    
  • {{ TF }} {#tf}

    1. Describe the properties of the yandex_vpc_subnet resource in a configuration file:

      resource "yandex_vpc_network" "lab-net" {
        name        = "network-1"
        description = "My first network"
      }
      
      resource "yandex_vpc_subnet" "lab-subnet-a" {
        name           = "subnet-1"
        description    = "My first subnet"
        v4_cidr_blocks = ["10.2.0.0/16"]
        zone           = "{{ region-id }}-a"
        network_id     = "${yandex_vpc_network.lab-net.id}"
      }

      For more information about resource parameters in {{ TF }}, see the [provider documentation]({{ tf-provider-resources-link }}/vpc_subnet).

    2. Make sure the configuration files are correct.

      1. In the command line, go to the directory where you created the configuration file.

      2. Run a check using this command:

        terraform plan
        

      If the configuration is described correctly, the terminal will display a list of created resources and their parameters. If the configuration contains any errors, {{ TF }} will point them out.

    3. Deploy cloud resources.

      1. If the configuration does not contain any errors, run this command:

        terraform apply
        
      2. Confirm creating the resources: type yes in the terminal and press Enter.

        All the resources you need will then be created in the specified folder. You can check the new resources and their configuration using the [management console]({{ link-console-main }}) or these CLI commands:

        yc vpc subnet list
        

{% endlist %}