All Products
Search
Document Center

VPC connection

Last Updated: May 10, 2018

The Virtual Private Cloud (VPC) is an isolated network environment built on Alibaba Cloud. VPCs are logically isolated from each other. For more information, see What is VPC.

When creating a cluster or job on Batch Compute, you can set to create the cluster in a VPC (conflicting with the original classic network configuration). Then your program has to use the entry of a cloud product in the VPC when running or accessing the program of this cloud product in a cluster in the VPC. For more information, see relevant cloud product documentation to submit a ticket for consultation. The CidrBlock field of Configs.Networks. VPC in the cluster description identifies the network segment of the Batch Compute cluster. All instances in the cluster are in this network segment. VPC supports only private network segments, that is, 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16, and their subnets. Due to underlying VSwitch division restrictions, the network segment mask must range from 12 to 24. Therefore, the CidrBlock field can be a network segment selected from 10.0.0.0/12 - 10.0.0.0/24, 172.16.0.0/12 - 172.16.0.0/24, and 192.168.0.0/16 - 192.168.0.0/24; otherwise, the cluster creation may fail.

You are also allowed to create a cluster in a VPC under your account. In this way, the cluster can be interconnected to existing cloud service resources, such as NAS and ApsaraDB for RDS instances, in your account. To use this function, other than the Configs.Networks.VPC.CidrBlock field, you have to configure the Configs.Networks.VPC.VpcId field to identify the ID of your VPC in your account.Note that VSwitches and other resources are created in the VPC specified by you during cluster creation. Do not operate the VSwitches automatically created during existence of the cluster; otherwise, the cluster running may be affected. Besides, in this mode, multiple clusters can share the same CIDR network segment. Note that do not create VSwitch and other resources in this CIDR network segment.

The bcs instance type (in the format of bcs.xx.xxx for example) is not supported by a Batch Compute cluster in the VPC.

Update the SDK in the following example to the latest version before using it.

1. Use the Java SDK

When creating a cluster, specify:

  1. ClusterDescription clusterDescription = new ClusterDescription();
  2. Configs cfgs = new Configs();
  3. Networks nw = new Networks();
  4. VPC vpc = new VPC();
  5. vpc.setCidrBlock("192.168.0.1/16"); //Sets the network segment
  6. vpc.setVpcId("vpc-xxyyzz"); //This field is required when you want to use your VPC.
  7. nw.setVpc(vpc);
  8. cfgs.setNetworks(nw);
  9. clusterDescription.setConfigs(cfgs);
  10. ...

When creating a job, specify:

  1. TaskDescription taskDescription = new TaskDescription();
  2. Configs cfgs = new Configs();
  3. Networks nw = new Networks();
  4. VPC vpc = new VPC();
  5. vpc.setCidrBlock("192.168.0.1/16"); //Sets the network segment
  6. vpc.setVpcId("vpc-xxyyzz"); //This field is required when you want to use your VPC.
  7. nw.setVpc(vpc);
  8. cfgs.setNetworks(nw);
  9. AutoCluster autoCluster = new AutoCluster();
  10. taskDescription.setAutoCluster(autoCluster);
  11. ...

2. Use the Python SDK

When creating a cluster, specify:

  1. from batchcompute.resources import ClusterDescription
  2. cluster_desc = ClusterDescription()
  3. cluster_desc.Configs.Networks.VPC.CidrBlock = "192.168.0.1/16"
  4. cluster_desc.Configs.Networks.VPC.VpcId = "vpc-xxyyzz" # This field is required when you want to use your VPC.
  5. ...

When creating a job, specify:

  1. from batchcompute.resources import TaskDescription
  2. task_desc = TaskDescription()
  3. task_desc.AutoCluster.Configs.Networks.VPC.CidrBlock = "192.168.0.1/16"
  4. task_desc.AutoCluster.Configs.Networks.VPC.VpcId = "vpc-xxyyzz" # This field is required when you want to use your VPC.
  5. ...

3. Use a command line tool

When creating a job, specify:

  1. bcs sub "python test.py" --vpc_cidr_block 192.168.0.0/16
  2. bcs sub "python test.py" --vpc_cidr_block 192.168.0.0/16 --vpc_id vpc-xxyyzz

When creating a cluster, specify:

  1. bcs cc myCluster --vpc_cidr_block 192.168.0.0/16
  2. bcs cc myCluster --vpc_cidr_block 192.168.0.0/16 --vpc_id vpc-xxyyzz