-
Notifications
You must be signed in to change notification settings - Fork 4
/
sample.py
50 lines (45 loc) · 1.56 KB
/
sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from kubernetes import config, client
from kubernetes.dynamic import DynamicClient
# load the kubeconfig file from the default location
config.load_kube_config()
# create a dynamic client
dyn_client = DynamicClient(client.ApiClient())
# create a KubeBlocks Cluster
# define the Cluster object
cluster = {
'apiVersion': 'apps.kubeblocks.io/v1alpha1',
'kind': 'Cluster',
'metadata': {
'name': 'hello-python-sdk',
'namespace': 'default'
},
'spec': {
'clusterDefinitionRef': 'redis',
'clusterVersionRef': 'redis-7.0.6',
'componentSpecs': [
{
'componentDefRef': 'redis',
'name': 'redis',
'replicas': 1
},
{
'componentDefRef': 'redis-twemproxy',
'name': 'redis-twemproxy',
'replicas': 1
},
{
'componentDefRef': 'redis-sentinel',
'name': 'redis-sentinel',
'replicas': 3
}
],
'terminationPolicy': 'WipeOut',
}
}
# Create the Cluster using the dynamic client
cluster_resource = dyn_client.resources.get(api_version='apps.kubeblocks.io/v1alpha1', kind='Cluster')
created_resource = cluster_resource.create(body=cluster, namespace='default')
# Delete the Cluster resource
# uncomment the following two lines to delete the Cluster
# cluster_resource = dyn_client.resources.get(api_version='apps.kubeblocks.io/v1alpha1', kind='Cluster')
# cluster_resource.delete(name='hello-python-sdk', namespace='default')