Cloud Container Engine (CCE)¶
CCE Cluster¶
Cloud Container Engine (CCE) is a highly reliable and high-performance service that allows enterprises to manage containerized applications. With support for Kubernetes-native applications and tools, CCE makes it simple to set up an environment for running containers in the cloud. CCE Clusters are the environment where cluster nodes are administrated. The core component is a Kubernetes Cluster with advanced features.
List CCE Clusters¶
This interface is used to query all CCE clusters and to filter the output with query parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
for cluster in conn.cce.clusters():
print(cluster)
Create CCE Cluster¶
This interface is used to create a CCE cluster instance with parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
"kind": "Cluster",
"apiVersion": "v3",
"metadata": {
"name": "test2"
},
"spec": {
"type": "VirtualMachine",
"flavor": "cce.s1.small",
"version": "v1.13.10-r0",
"az": "eu-de-01",
"supportIstio": True,
"hostNetwork": {
"vpc": "26ca2783-dc40-4e3a-95b1-5a0756441e12",
"subnet": "25d24fc8-d019-4a34-9fff-0a09fde6a9cb",
"SecurityGroup": "f9ae0767-25be-44fc-a21c-5b8a0da66dec"
},
"containerNetwork": {
"mode": "overlay_l2",
"cidr": "172.16.0.0/16"
},
"authentication": {
"mode": "rbac",
"authenticatingProxy": {}
},
"billingMode": 0,
"kubernetesSvcIpRange": "10.247.0.0/16",
"kubeProxyMode": "iptables"
}
}
conn.cce.create_cluster(**attrs)
Get CCE Cluster¶
This interface is used to get a CCE cluster by ID
or an instance of class
Cluster
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster_id = "123456_cluster_id"
cluster = conn.cce.get_cluster(cluster_id)
print(cluster)
Find CCE Cluster¶
This interface is used to find a CCE cluster by ID or name.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster = "cluster_name_or_id"
cluster = conn.cce.find_cluster(cluster)
print(cluster)
Delete CCE Cluster¶
This interface is used to delete a CCE cluster by ID
or an instance of class
Cluster
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster_name = "cluster_name"
cluster = conn.cce.find_cluster(cluster_name)
print(cluster)
conn.cce.delete_cluster(cluster)
CCE Node¶
A CCE cluster node is the computing instance of a CCE cluster where containers are hosted. One cluster can manage several nodes which can be distributed over different availability zones to increase reliability.
List CCE Cluster Nodes¶
This interface is used to query all nodes of a CCE cluster and to filter the output with query parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster = "cluster_name_or_id"
cluster = conn.cce.find_cluster(cluster)
for node in conn.cce.cluster_nodes(cluster):
print(node)
Create CCE Cluster Node¶
This interface is used to create a CCE cluster node instance with parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
'kind': 'Node',
'apiVersion': 'v3',
'metadata': {
'name': 'myhost',
'labels': {
'foo': 'bar'
},
'annotations': {
'annotation1': 'abc'
}
},
'spec': {
'flavor': 's2.large.2',
'az': 'eu-de-02',
'login': {
'sshKey': 'keypair-pub'
},
'rootVolume': {
'size': 40,
'volumetype': 'SATA'
},
'dataVolumes': [
{
'size': 100,
'volumetype': 'SATA'
}
],
'userTags': [
{
'key': 'tag1',
'value': 'aaaa'
Get CCE Cluster Node¶
This interface is used to get a CCE cluster by ID
or an instance of class
ClusterNode
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster = "cluster_name_or_id"
cluster = conn.cce.find_cluster(cluster)
node_id = "node_id"
node = conn.cce.get_cluster_node(cluster, node_id)
print(node)
Find CCE Cluster Node¶
This interface is used to find a node of a CCE cluster by ID or name.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster = conn.cce.find_cluster(cluster='name_or_id')
node = conn.cce.find_cluster_node(cluster=cluster, node='name_or_id')
print(node)
Delete CCE Cluster Node¶
This interface is used to delete a CCE cluster node by ID
or an instance of class
ClusterNode
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster = "cluster_name_or_id"
cluster = conn.cce.find_cluster(cluster)
node_id = "node_id"
conn.cce.delete_cluster_node(cluster, node_id)
CCE Node Pool¶
A node pool is a group of one or more nodes with identical configuration in a cluster. In CCE, the nodes configured during cluster creation are grouped into the default node pool. The default node pool is named DefaultPool and cannot be edited, deleted, or migrated. In CCE SDK, you can create custom node pools in a cluster to organize cluster nodes into different pools so that you can edit or delete a node pool individually without affecting the entire cluster. All nodes in a custom node pool have identical parameters and node type. You cannot configure a single node in a node pool; any configuration changes affect all nodes in the node pool.
List CCE Node Pools¶
This interface is used to query all node pools of a CCE cluster and to filter the output with query parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster = 'name_or_id'
cluster = conn.cce.find_cluster(cluster)
for pool in conn.cce.node_pools(cluster):
print(pool)
Create CCE Node Pool¶
This interface is used to create a CCE node pool instance with parameters.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
attrs = {
'metadata': {
'name': 'test-node-pool'
},
'spec': {
'initialNodeCount': 0,
'type': 'vm',
'autoscaling': {
'enable': True,
'minNodeCount': 1,
'maxNodeCount': 3,
'scaleDownCooldownTime': 10,
'priority': 1
},
'nodeTemplate': {
'flavor': 's2.large.2',
'az': 'eu-de-01',
'os': 'CentOS 7.7',
'login': {
'sshKey': 'sshkey-pub'
},
'rootVolume': {
'volumetype': 'SATA',
'size': 40
},
'dataVolumes': [
{
'volumetype': 'SATA',
'size': 100,
'extendParam': {
'useType': 'docker'
}
}
],
'billingMode': 0,
'extendParam': {
'maxPods': 110,
'DockerLVMConfigOverride': 'dockerThinpool=vgpaas/90%VG;'
'kubernetesLV=vgpaas/10%VG;'
'diskType=evs;lvType=linear'
},
'k8sTags': {
'tag1': 'value1',
'tag2': 'value2'
},
'taints': [
{
'key': 'aaa',
'value': 'bbb',
'effect': 'NoSchedule'
},
{
'key': 'ccc',
'value': 'ddd',
'effect': 'NoSchedule'
}
],
'userTags': [
{
'key': 'resource-tag1',
'value': 'value1'
},
{
'key': 'resource-tag2',
'value': 'value2'
}
],
'nodeNicSpec': {
'primaryNic': {
'subnetId': 'subnet_id'
}
}
}
}
}
cluster = 'name_or_id'
cluster = conn.cce.find_cluster(name_or_id=cluster)
conn.cce.create_node_pool(cluster=cluster, **attrs)
Get CCE Node Pool¶
This interface is used to get a CCE node pool by ID
or an instance of class
NodePool
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster = 'name_or_id'
node_pool_id = 'node_pool_id'
cluster = conn.cce.find_cluster(cluster)
pool = conn.cce.get_node_pool(cluster=cluster, node_pool_id=node_pool_id)
print(pool)
Find CCE Node Pool¶
This interface is used to find a node pool of a CCE cluster by ID or name.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster = 'name_or_id'
node_pool = 'name_or_id'
cluster = conn.cce.find_cluster(cluster)
pool = conn.cce.find_node_pool(cluster=cluster, node_pool=node_pool)
print(pool)
Delete CCE Node Pool¶
This interface is used to delete a CCE node pool by ID
or an instance of class
NodePool
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
cluster = 'name_or_id'
node_pool = 'name_or_id'
cluster = conn.cce.find_cluster(cluster)
node_pool = conn.cce.find_node_pool(cluster=cluster, node_pool=node_pool)
conn.cce.delete_node_pool(cluster=cluster, node_pool=node_pool)
Job Operations¶
Jobs are created while cluster creation and other similar operations have been started. Jobs have different phases and can be triggered by the following methods.
Get Job¶
This interface is used to get a CCE Job by ID
or an instance of class
Job
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
job_id = "123456_job_id"
job = conn.cce.get_job(job_id)
print(job)
Wait for a Job¶
This interface is used to wait for a CCE Job until reaches a specific state
by using ID or an instance of class
Job
.
import openstack
openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
job_id = "123456_job_id"
conn.cce.wait_for_job(job_id, status='success',
failures=None, interval=5, wait=3600)