All Products
Search
Document Center

Batch Compute:VPC connection

Last Updated:Feb 24, 2023

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:

ClusterDescription clusterDescription = new ClusterDescription();
Configs cfgs = new Configs();
Networks nw = new Networks();
VPC vpc = new VPC();
vpc.setCidrBlock("192.168.0.1/16");  //Sets the network segment
vpc.setVpcId("vpc-xxyyzz");  //This field is required when you want to use your VPC.
nw.setVpc(vpc);
cfgs.setNetworks(nw);
clusterDescription.setConfigs(cfgs);
...

When creating a job, specify:

TaskDescription taskDescription = new TaskDescription();
Configs cfgs = new Configs();
Networks nw = new Networks();
VPC vpc = new VPC();
vpc.setCidrBlock("192.168.0.1/16"); //Sets the network segment
vpc.setVpcId("vpc-xxyyzz");  //This field is required when you want to use your VPC.
nw.setVpc(vpc);
cfgs.setNetworks(nw);
AutoCluster autoCluster = new AutoCluster();
taskDescription.setAutoCluster(autoCluster);
...

2. Use the Python SDK

When creating a cluster, specify:

from batchcompute.resources import ClusterDescription

cluster_desc = ClusterDescription()
cluster_desc.Configs.Networks.VPC.CidrBlock = "192.168.0.1/16"
cluster_desc.Configs.Networks.VPC.VpcId = "vpc-xxyyzz"  # This field is required when you want to use your VPC.
...

When creating a job, specify:

from batchcompute.resources import TaskDescription

task_desc = TaskDescription()
task_desc.AutoCluster.Configs.Networks.VPC.CidrBlock = "192.168.0.1/16"
task_desc.AutoCluster.Configs.Networks.VPC.VpcId = "vpc-xxyyzz"  # This field is required when you want to use your VPC.
...

3. Use a command line tool

When creating a job, specify:

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

When creating a cluster, specify:

bcs cc myCluster --vpc_cidr_block 192.168.0.0/16
bcs cc myCluster --vpc_cidr_block 192.168.0.0/16 --vpc_id vpc-xxyyzz