from kubernetes import client, config def scale_up(namespace_name,deploy_name,replicas=1): config.load_kube_config(config_file='/kubeconfig/config') api = client.AppsV1Api() deployment = api.read_namespaced_deployment(name=deploy_name, namespace=namespace_name) deployment.spec.replicas = replicas resp = api.patch_namespaced_deployment( name=deploy_name, namespace=namespace_name, body=deployment); return 0 def scale_down(namespace_name,deploy_name): config.load_kube_config(config_file='/kubeconfig/config') api = client.AppsV1Api() deployment = api.read_namespaced_deployment(name=deploy_name, namespace=namespace_name) deployment.spec.replicas = 0 resp = api.patch_namespaced_deployment( name=deploy_name, namespace=namespace_name, body=deployment); return 0 def import_Deployments(): config.load_kube_config(config_file='/kubeconfig/config') api = client.AppsV1Api() deployment = api.list_deployment_for_all_namespaces() for i in range(1,len(deployment.items)): print(deployment.items[i].spec.template.spec.containers[0].name) len(deployment.items) #list all deployment inside the namespace test.items[0].spec.template.spec.containers[0].name # name the first deploy within the namespace test.items[2].spec.template.spec.containers[0].name # name the third deploy within the namespace return 0 def get_namespace(): config.load_kube_config(config_file='/kubeconfig/config') core = client.CoreV1Api() namespace = core.list_namespace() namespace_list = [] for i in range(1,len(namespace.items)): print(namespace.items[i].metadata.name) namespace_list.append(namespace.items[i].metadata.name) return namespace_list