Esempio n. 1
0
def rescale_deployment(v1, name, num_replicas):
    logger.info("Rescaling deployment {} to {} replicas", name, num_replicas)

    scale = client.V1Scale(spec=client.V1ScaleSpec(replicas=num_replicas))
    v1.patch_namespaced_deployment_scale(name=name,
                                         namespace=NAMESPACE,
                                         body=scale)
Esempio n. 2
0
def main():
    #load kubernetes configs
    config.load_incluster_config()
    configuration = client.Configuration()

    # create an instance of the API class
    api_instance = client.AppsV1Api(client.ApiClient(configuration))

    #set name, namespace, and body
    name = 'commerce-nginx'  # str | name of the Scale
    namespace = 'default'  # str | object name and auth scope, such as for teams and projects
    body = client.V1Scale(metadata=V1ObjectMeta(name=name,
                                                namespace=namespace),
                          spec=V1ScaleSpec(replicas=numpods))

    #run method with above parameters
    try:
        api_response = api_instance.replace_namespaced_deployment_scale(
            name, namespace, body)
        print("Scaling", name, "to", numpods, "pods.")  # print how many pods
        pprint(api_response)  #uncomment to see api response
    except ApiException as e:
        print(
            "Exception when calling AppsV1Api->replace_namespaced_deployment_scale: %s\n"
            % e)
Esempio n. 3
0
def create_scale_object(new_scale):
    scale_spec = client.V1ScaleSpec(replicas=new_scale)
    status = client.V1ScaleStatus(replicas=new_scale)
    scale = client.V1Scale(api_version='corev1',
                           kind='Scale',
                           spec=scale_spec,
                           status=status)
    return scale
Esempio n. 4
0
    def scale(self, deployment, replicas, wait_for=False):
        # create scale object
        scale_obj = client.V1Scale()
        scale_obj.metadata = client.V1ObjectMeta()
        scale_obj.metadata.name = deployment
        scale_obj.metadata.namespace = self.namespace
        scale_obj.spec = client.V1ScaleSpec()
        scale_obj.spec.replicas = replicas

        self.apps_v1_api.replace_namespaced_deployment_scale(deployment,
                                                             self.namespace,
                                                             body=scale_obj)

        if wait_for:
            self.wait_replicas(deployment, replicas)
Esempio n. 5
0
def set_deployment_scale(arg_cli,arg_ns,arg_rs,arg_scale):
        mt_config               =   client.V1ObjectMeta()
        mt_config.name          =   arg_rs
        mt_config. namespace    =   arg_ns
        rs_config               =   client.V1ScaleSpec()
        rs_config.replicas      =   arg_scale
        s_config                =   client.V1Scale()
        s_config.api_version    =   'autoscaling/v1'
        s_config.kind           =   "Scale"
        s_config.spec           =   rs_config
        s_config.metadata       =   mt_config

        try:
            ret_val = arg_cli.replace_namespaced_deployment_scale(name=arg_rs, namespace=arg_ns, body=s_config)
            #ret_val = arg_cli.replace_namespaced_replication_controller_scale(name=arg_rs, namespace=arg_ns, body=2)
            print(ret_val)
        except ApiException as e:
            print("Exception %s" % e )