How to use the kubernetes.client.ExtensionsV1beta1Api function in kubernetes

To help you get started, we’ve selected a few kubernetes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aionnetwork / aion / DockerAutomation / k8s / redeploy.py View on Github external
def reload(deployment):

    with open(path.join(path.dirname(__file__), "aion_node.yaml")) as f:
        dep = yaml.safe_load(f)
        k8s_beta = client.ExtensionsV1beta1Api()
        
        to_update = "-".join((deployment.metadata.name).split('-')[0:2])
        dep["metadata"]["name"]=to_update
        dep["spec"]["template"]["spec"]["containers"][0]["image"] = deployment.spec.containers[0].image
        dep["spec"]["template"]["metadata"]["labels"]["app"] = deployment.metadata.labels['app']
        update_annotations(dep)

        print(dep)
        print("-----------------------------------------------------------------------------------")
        try:
            resp = k8s_beta.patch_namespaced_deployment(
            name=to_update,
            body=dep, 
            namespace=namespace)
            print("Deployment  %s updated to latest build; status: %s" % (to_update, resp.status))
        except ApiException as e:
github IntelAI / nauta / applications / tensorboard-service / app / k8s / client.py View on Github external
def __init__(self):
        self.apps_api_client = client.AppsV1Api()
        self.extensions_v1beta1_api_client = client.ExtensionsV1beta1Api()
        self.v1_api_client = client.CoreV1Api()
        self.custom_objects_client = client.CustomObjectsApi()
github GoogleCloudPlatform / django-cloud-deploy / django_cloud_deploy / cloudlib / container.py View on Github external
"""Update a Kubernetes Deployment.

        A Kubernetes Deployment describes a desired state of your application.
        For example, it manages creation of Pods by means of ReplicaSets, and
        defines what images to use for the containers.

        Args:
            deployment_data: Definition of the deployment.
            configuration: A Kubernetes configuration which has access to the
                cluster for the deployment. If not set, it will use the default
                kubernetes configuration.
            namespace: Namespace of the deployment.
        """

        api_client = kubernetes.client.ApiClient(configuration)
        api_instance = kubernetes.client.ExtensionsV1beta1Api(api_client)

        deployment_name = deployment_data['metadata']['name']

        # TODO: Find a better way to do update.
        # Right now we scale the replicas to 0 and then scale it back. This
        # will trigger an image update.
        replicas = deployment_data['spec']['replicas']
        deployment_data['spec']['replicas'] = 0
        api_instance.patch_namespaced_deployment(name=deployment_name,
                                                 namespace=namespace,
                                                 body=deployment_data)
        deployment_data['spec']['replicas'] = replicas
        api_instance.patch_namespaced_deployment(name=deployment_name,
                                                 namespace=namespace,
                                                 body=deployment_data)
github ANRGUSC / Jupiter / mulhome_scripts / delete_all_circe.py View on Github external
dag_info = utilities.k8s_read_config(path1)
    dag = dag_info[1]

    """
        This loads the kubernetes instance configuration.
        In our case this is stored in admin.conf.
        You should set the config file path in the jupiter_config.py file.
    """
    config.load_kube_config(config_file = jupiter_config.KUBECONFIG_PATH)


    # We have defined the namespace for deployments in jupiter_config
    namespace = jupiter_config.DEPLOYMENT_NAMESPACE

    # Get proper handles or pointers to the k8-python tool to call different functions.
    extensions_v1_beta1_api = client.ExtensionsV1beta1Api()
    v1_delete_options = client.V1DeleteOptions()
    core_v1_api = client.CoreV1Api()

    """
        Loop through the list of tasks in the dag and delete the respective k8 deployment, replicaset, pods, and service.
        The deletion should follow this particular order for a proper removal.
        You can always check if a service/pod/deployment is running after running this script via kubectl command.
        E.g., 
            kubectl get svc -n "namespace name"
            kubectl get deployement -n "namespace name"
            kubectl get replicaset -n "namespace name"
            kubectl get pod -n "namespace name"
    """
    for key, value in dag.items():

        print(key)
github PaddlePaddle / cloud / python / paddlecloud / notebook / utils.py View on Github external
def __create_ingress(self, username, namespace):
        v1beta1api = kubernetes.client.ExtensionsV1beta1Api(api_client=get_user_api_client(username))
        ing_list = v1beta1api.list_namespaced_ingress(namespace)
        if not self.__find_item(ing_list, "cloud-notebook-ingress"):
            # FIXME: must split this for different users
            ing_body = copy.deepcopy(self.ing_body)
            ing_body["spec"]["rules"][0]["http"]["paths"][0]["path"] = "/notebook/" + self.get_notebook_id(username)
            resp = v1beta1api.create_namespaced_ingress(namespace, body=ing_body)
            self.__wait_api_response(resp)
github airshipit / armada / armada / handlers / k8s.py View on Github external
except config.config_exception.ConfigException:
            config.load_kube_config()

        if self.bearer_token:
            # Configure API key authorization: Bearer Token
            configuration = client.Configuration()
            configuration.api_key_prefix['authorization'] = 'Bearer'
            configuration.api_key['authorization'] = self.bearer_token
            api_client = client.ApiClient(configuration)

        self.client = client.CoreV1Api(api_client)
        self.batch_api = client.BatchV1Api(api_client)
        self.batch_v1beta1_api = client.BatchV1beta1Api(api_client)
        self.custom_objects = client.CustomObjectsApi(api_client)
        self.api_extensions = client.ApiextensionsV1beta1Api(api_client)
        self.extension_api = client.ExtensionsV1beta1Api(api_client)
        self.apps_v1_api = client.AppsV1Api(api_client)
github ANRGUSC / Jupiter / mulhome_scripts / k8s_decoupled_pricing_circe_scheduler.py View on Github external
nodes, homes = utilities.k8s_get_nodes_worker(path1)
    pprint(nodes)

    """
        This loads the kubernetes instance configuration.
        In our case this is stored in admin.conf.
        You should set the config file path in the jupiter_config.py file.
    """
    config.load_kube_config(config_file = jupiter_config.KUBECONFIG_PATH)
    namespace = jupiter_config.DEPLOYMENT_NAMESPACE


    # We have defined the namespace for deployments in jupiter_config

    # Get proper handles or pointers to the k8-python tool to call different functions.
    extensions_v1_beta1_api = client.ExtensionsV1beta1Api()
    v1_delete_options = client.V1DeleteOptions()
    core_v1_api = client.CoreV1Api()

    result = True
    for key in nodes:

        label = "app=%s_wave_"%(app_name)
        label = label + key
        resp = None

        resp = core_v1_api.list_namespaced_pod(namespace, label_selector = label)
        # if a pod is running just delete it
        if resp.items:
            a=resp.items[0]
            if a.status.phase != "Running":
                logging.debug("Pod Not Running", key)
github intel / CPU-Manager-for-Kubernetes / intel / reconcile.py View on Github external
else:
        seconds = int(seconds)

    should_exit = (seconds <= 0)

    while True:
        with conf.lock():
            report = generate_report(conf)
            print(report.json())
            reclaim_cpu_lists(conf, report)

        if publish and report is not None:
            logging.debug("Publishing reconcile report to "
                          "Kubernetes API server")
            k8sconfig.load_incluster_config()
            v1beta = k8sclient.ExtensionsV1beta1Api()

            version = util.parse_version(k8s.get_kube_version(None))

            if version >= util.parse_version("v1.7.0"):
                reconcile_report_type = \
                    custom_resource.CustomResourceDefinitionType(
                        v1beta,
                        "intel.com",
                        "cmk-reconcilereport",
                        ["cmk-rr"]
                    )

                node_name = os.getenv("NODE_NAME")
                reconcile_report = reconcile_report_type.create(node_name)
                reconcile_report.body["spec"]["report"] = report
                reconcile_report.save()