You need to enable JavaScript to run this app.
Volcengine Kubernetes Engine

Volcengine Kubernetes Engine

Copy page
Download PDF
SDK reference
Python SDK
Copy page
Download PDF
Python SDK
This topic describes how to install and configure the Python SDK of Volcengine Kubernetes Engine (VKE), and offers examples of using the Python SDK to call cloud-based API actions.​
Usage notes​
Only Python 2.7 or later is supported.​
Installation configuration​
Download the Python SDK from volcengine-python-sdk for installation and configuration.​
Examples of using the SDK​
Creating a cluster (CreateCluster)​
For more information on the parameters in the example below and how to configure them, refer to [CreateCluster](https://www.volcengine.com/docs/6460/115184?LibVersion=Volcano Engine).​
​
# Example Code generated by Southeast Volcano Engine Technology.​
from __future__ import print_function​
import volcenginesdkcore​
import volcenginesdkvke​
from volcenginesdkcore.rest import ApiException​
​
if __name__ == '__main__':​
# The AccessKey ID and Secret Access Key of your Volcano Engine account, and the Region where your business is located.​
configuration = volcenginesdkcore.Configuration()​
configuration.ak = "Your AK"​
configuration.sk = "Your SK"​
configuration.region = "Your Region"​
# set default configuration​
volcenginesdkcore.Configuration.set_default(configuration)​
​
# use global default configuration​
api_instance = volcenginesdkvke.VKEApi()​
req_public_access_network_config = volcenginesdkvke.PublicAccessNetworkConfigForCreateClusterInput(​
bandwidth=10,​
billing_type=3,​
)​
req_api_server_public_access_config = volcenginesdkvke.ApiServerPublicAccessConfigForCreateClusterInput(​
public_access_network_config=req_public_access_network_config,​
)​
req_cluster_config = volcenginesdkvke.ClusterConfigForCreateClusterInput(​
api_server_public_access_config=req_api_server_public_access_config,​
api_server_public_access_enabled=True,​
resource_public_access_default_enabled=False,​
subnet_ids=["subnet-id"],​
)​
req_flannel_config = volcenginesdkvke.FlannelConfigForCreateClusterInput(​
max_pods_per_node=64,​
pod_cidrs=["172.17.**.**/19"],​
)​
req_pods_config = volcenginesdkvke.PodsConfigForCreateClusterInput(​
flannel_config=req_flannel_config,​
pod_network_mode="Flannel",​
)​
req_services_config = volcenginesdkvke.ServicesConfigForCreateClusterInput(​
service_cidrsv4=["172.25.**.**/17"],​
)​
req_tags = volcenginesdkvke.TagForCreateClusterInput(​
key="tag-key",​
value="tag-value",​
)​
create_cluster_request = volcenginesdkvke.CreateClusterRequest(​
client_token="client-token",​
cluster_config=req_cluster_config,​
delete_protection_enabled=False,​
description="cluster-description",​
kubernetes_version="1.24",​
name="cluster-name",​
pods_config=req_pods_config,​
services_config=req_services_config,​
tags=[req_tags],​
)​
​
try:​
# Copy and run the sample code, and print the return values of the API action.​
api_instance.create_cluster(create_cluster_request)​
except ApiException as e:​
# Copy and run the sample code, and print the error message returned by the API action.​
# print("Exception when calling api: %s\n" % e)​
pass​
​
Updating the cluster configuration (UpdateClusterConfig)​
For more information on the parameters in the example below and how to configure them, refer to [UpdateClusterConfig](https://www.volcengine.com/docs/6460/115189?LibVersion=Volcano Engine).​
​
# Example Code generated by Southeast Volcano Engine Technology.​
from __future__ import print_function​
import volcenginesdkcore​
import volcenginesdkvke​
from volcenginesdkcore.rest import ApiException​
​
if __name__ == '__main__':​
# The AccessKey ID and Secret Access Key of your Volcano Engine account, and the Region where your business is located.​
configuration = volcenginesdkcore.Configuration()​
configuration.ak = "Your AK"​
configuration.sk = "Your SK"​
configuration.region = "Your Region"​
# set default configuration​
volcenginesdkcore.Configuration.set_default(configuration)​
​
# use global default configuration​
api_instance = volcenginesdkvke.VKEApi()​
req_public_access_network_config = volcenginesdkvke.PublicAccessNetworkConfigForUpdateClusterConfigInput(​
bandwidth=100,​
billing_type=3,​
)​
req_api_server_public_access_config = volcenginesdkvke.ApiServerPublicAccessConfigForUpdateClusterConfigInput(​
public_access_network_config=req_public_access_network_config,​
)​
req_cluster_config = volcenginesdkvke.ClusterConfigForUpdateClusterConfigInput(​
api_server_public_access_config=req_api_server_public_access_config,​
api_server_public_access_enabled=True,​
)​
update_cluster_config_request = volcenginesdkvke.UpdateClusterConfigRequest(​
client_token="client-token",​
cluster_config=req_cluster_config,​
description="cluster-description",​
id="cluster-id",​
name="cluster-name",​
)​
​
try:​
# Copy and run the sample code, and print the return values of the API action.​
api_instance.update_cluster_config(update_cluster_config_request)​
except ApiException as e:​
# Copy and run the sample code, and print the error message returned by the API action.​
# print("Exception when calling api: %s\n" % e)​
pass​
​
Getting the cluster list and details (ListClusters)​
For more information on the parameters in the example below and how to configure them, refer to [ListClusters](https://www.volcengine.com/docs/6460/115190?LibVersion=Volcano Engine).​
​
# Example Code generated by Southeast Volcano Engine Technology.​
from __future__ import print_function​
import volcenginesdkcore​
import volcenginesdkvke​
from volcenginesdkcore.rest import ApiException​
​
if __name__ == '__main__':​
# The AccessKey ID and Secret Access Key of your Volcano Engine account, and the Region where your business is located.​
configuration = volcenginesdkcore.Configuration()​
configuration.ak = "Your AK"​
configuration.sk = "Your SK"​
configuration.region = "Your Region"​
# set default configuration​
volcenginesdkcore.Configuration.set_default(configuration)​
​
# use global default configuration​
api_instance = volcenginesdkvke.VKEApi()​
req_filter = volcenginesdkvke.FilterForListClustersInput(​
ids=["cluster-id"],​
)​
list_clusters_request = volcenginesdkvke.ListClustersRequest(​
filter=req_filter,​
page_number=1,​
page_size=10,​
)​
​
try:​
# Copy and run the sample code, and print the return values of the API action.​
api_instance.list_clusters(list_clusters_request)​
except ApiException as e:​
# Copy and run the sample code, and print the error message returned by the API action.​
# print("Exception when calling api: %s\n" % e)​
pass​
​
Creating a NodePool (CreateNodePool)​
For more information on the parameters in the example below and how to configure them, refer to [CreateNodePool](https://www.volcengine.com/docs/6460/115194?LibVersion=Volcano Engine).​
​
# Example Code generated by Southeast Volcano Engine Technology.​
from __future__ import print_function​
import volcenginesdkcore​
import volcenginesdkvke​
from volcenginesdkcore.rest import ApiException​
​
if __name__ == '__main__':​
# The AccessKey ID and Secret Access Key of your Volcano Engine account, and the Region where your business is located.​
configuration = volcenginesdkcore.Configuration()​
configuration.ak = "Your AK"​
configuration.sk = "Your SK"​
configuration.region = "Your Region"​
# set default configuration​
volcenginesdkcore.Configuration.set_default(configuration)​
​
# use global default configuration​
api_instance = volcenginesdkvke.VKEApi()​
req_auto_scaling = volcenginesdkvke.AutoScalingForCreateNodePoolInput(​
desired_replicas=1,​
enabled=True,​
max_replicas=100,​
min_replicas=0,​
priority=10,​
)​
req_labels = volcenginesdkvke.LabelForCreateNodePoolInput(​
key="label-key",​
value="label-value",​
)​
req_taints = volcenginesdkvke.TaintForCreateNodePoolInput(​
effect="NoSchedule",​
key="taint-key",​
value="taint-value",​
)​
req_kubernetes_config = volcenginesdkvke.KubernetesConfigForCreateNodePoolInput(​
cordon=False,​
labels=[req_labels],​
taints=[req_taints],​
)​
req_data_volumes = volcenginesdkvke.DataVolumeForCreateNodePoolInput(​
size=20,​
type="ESSD_PL0",​
)​
req_login = volcenginesdkvke.LoginForCreateNodePoolInput(​
password="***",​
)​
req_security = volcenginesdkvke.SecurityForCreateNodePoolInput(​
login=req_login,​
security_strategies=["Hids"],​
)​
req_system_volume = volcenginesdkvke.SystemVolumeForCreateNodePoolInput(​
size=40,​
type="ESSD_PL0",​
)​
req_tags = volcenginesdkvke.TagForCreateNodePoolInput(​
key="tag-key",​
value="tag-value",​
)​
req_node_config = volcenginesdkvke.NodeConfigForCreateNodePoolInput(​
data_volumes=[req_data_volumes],​
image_id="image-id",​
instance_charge_type="PostPaid",​
instance_type_ids=["instance-type"],​
name_prefix="prefix",​
security=req_security,​
subnet_ids=["subnet-id"],​
system_volume=req_system_volume,​
tags=[req_tags],​
)​
req_tags1 = volcenginesdkvke.TagForCreateNodePoolInput(​
key="tag-key",​
value="tag-value",​
)​
create_node_pool_request = volcenginesdkvke.CreateNodePoolRequest(​
auto_scaling=req_auto_scaling,​
client_token="client-token",​
cluster_id="cluster-id",​
kubernetes_config=req_kubernetes_config,​
name="nodepool-name",​
node_config=req_node_config,​
tags=[req_tags1],​
)​
​
try:​
# Copy and run the sample code, and print the return values of the API action.​
api_instance.create_node_pool(create_node_pool_request)​
except ApiException as e:​
# Copy and run the sample code, and print the error message returned by the API action.​
# print("Exception when calling api: %s\n" % e)​
pass​
​
Updating the NodePool configuration (UpdateNodePoolConfig)​
For more information on the parameters in the example below and how to configure them, refer to [UpdateNodePoolConfig](https://www.volcengine.com/docs/6460/115195?LibVersion=Volcano Engine).​
​
# Example Code generated by Southeast Volcano Engine Technology.​
from __future__ import print_function​
import volcenginesdkcore​
import volcenginesdkvke​
from volcenginesdkcore.rest import ApiException​
​
if __name__ == '__main__':​
# The AccessKey ID and Secret Access Key of your Volcano Engine account, and the Region where your business is located.​
configuration = volcenginesdkcore.Configuration()​
configuration.ak = "Your AK"​
configuration.sk = "Your SK"​
configuration.region = "Your Region"​
# set default configuration​
volcenginesdkcore.Configuration.set_default(configuration)​
​
# use global default configuration​
api_instance = volcenginesdkvke.VKEApi()​
req_auto_scaling = volcenginesdkvke.AutoScalingForUpdateNodePoolConfigInput(​
desired_replicas=10,​
)​
update_node_pool_config_request = volcenginesdkvke.UpdateNodePoolConfigRequest(​
auto_scaling=req_auto_scaling,​
client_token="client-token",​
cluster_id="cluster-id",​
id="nodepool-id",​
name="nodepool-name",​
)​
​
try:​
# Copy and run the sample code, and print the return values of the API action.​
api_instance.update_node_pool_config(update_node_pool_config_request)​
except ApiException as e:​
# Copy and run the sample code, and print the error message returned by the API action.​
# print("Exception when calling api: %s\n" % e)​
pass​
​
Querying the NodePool list and details (ListNodePools)​
For more information on the parameters in the example below and how to configure them, refer to [ListNodePools](https://www.volcengine.com/docs/6460/115197?LibVersion=Volcano Engine).​
​
# Example Code generated by Southeast Volcano Engine Technology.​
from __future__ import print_function​
import volcenginesdkcore​
import volcenginesdkvke​
from volcenginesdkcore.rest import ApiException​
​
if __name__ == '__main__':​
# The AccessKey ID and Secret Access Key of your Volcano Engine account, and the Region where your business is located.​
configuration = volcenginesdkcore.Configuration()​
configuration.ak = "Your AK"​
configuration.sk = "Your SK"​
configuration.region = "Your Region"​
# set default configuration​
volcenginesdkcore.Configuration.set_default(configuration)​
​
# use global default configuration​
api_instance = volcenginesdkvke.VKEApi()​
req_filter = volcenginesdkvke.FilterForListNodePoolsInput(​
cluster_ids=["cluster-id"],​
ids=["nodepool-id"],​
)​
list_node_pools_request = volcenginesdkvke.ListNodePoolsRequest(​
filter=req_filter,​
page_number=1,​
page_size=10,​
)​
​
try:​
# Copy and run the sample code, and print the return values of the API action.​
api_instance.list_node_pools(list_node_pools_request)​
except ApiException as e:​
# Copy and run the sample code, and print the error message returned by the API action.​
# print("Exception when calling api: %s\n" % e)​
pass​
​
Installing an add-on (CreateAddon)​
For more information on the parameters in the example below and how to configure them, refer to [CreateAddon](https://www.volcengine.com/docs/6460/115202?LibVersion=Volcano Engine).​
​
# Example Code generated by Southeast Volcano Engine Technology.​
from __future__ import print_function​
import volcenginesdkcore​
import volcenginesdkvke​
from volcenginesdkcore.rest import ApiException​
​
if __name__ == '__main__':​
# The AccessKey ID and Secret Access Key of your Volcano Engine account, and the Region where your business is located.​
configuration = volcenginesdkcore.Configuration()​
configuration.ak = "Your AK"​
configuration.sk = "Your SK"​
configuration.region = "Your Region"​
# set default configuration​
volcenginesdkcore.Configuration.set_default(configuration)​
​
# use global default configuration​
api_instance = volcenginesdkvke.VKEApi()​
create_addon_request = volcenginesdkvke.CreateAddonRequest(​
client_token="client-token",​
cluster_id="cluster-id",​
deploy_mode="Managed",​
deploy_node_type="Node",​
name="cluster-autoscaler",​
)​
​
try:​
# Copy and run the sample code, and print the return values of the API action.​
api_instance.create_addon(create_addon_request)​
except ApiException as e:​
# Copy and run the sample code, and print the error message returned by the API action.​
# print("Exception when calling api: %s\n" % e)​
pass​
​
​
Last updated: 2026.03.31 10:58:11