当前位置: 首页>>代码示例>>Python>>正文


Python client.AppsV1Api方法代码示例

本文整理汇总了Python中kubernetes.client.AppsV1Api方法的典型用法代码示例。如果您正苦于以下问题:Python client.AppsV1Api方法的具体用法?Python client.AppsV1Api怎么用?Python client.AppsV1Api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kubernetes.client的用法示例。


在下文中一共展示了client.AppsV1Api方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_statefulset

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def create_statefulset(spec_path: str, ns: str = "default",
                       secrets: Secrets = None):
    """
    Create a statefulset described by the service config, which must be
    the path to the JSON or YAML representation of the statefulset.
    """
    api = create_k8s_api_client(secrets)

    with open(spec_path) as f:
        p, ext = os.path.splitext(spec_path)
        if ext == '.json':
            statefulset = json.loads(f.read())
        elif ext in ['.yml', '.yaml']:
            statefulset = yaml.safe_load(f.read())
        else:
            raise ActivityFailed(
                "cannot process {path}".format(path=spec_path))

    v1 = client.AppsV1Api(api)
    v1.create_namespaced_stateful_set(ns, body=statefulset) 
开发者ID:chaostoolkit,项目名称:chaostoolkit-kubernetes,代码行数:22,代码来源:actions.py

示例2: scale_statefulset

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def scale_statefulset(name: str, replicas: int, ns: str = "default",
                      secrets: Secrets = None):
    """
    Scale a stateful set up or down. The `name` is the name of the stateful
    set.
    """
    api = create_k8s_api_client(secrets)

    v1 = client.AppsV1Api(api)
    body = {"spec": {"replicas": replicas}}
    try:
        v1.patch_namespaced_stateful_set(name, namespace=ns, body=body)
    except ApiException as e:
        raise ActivityFailed(
            "failed to scale '{s}' to {r} replicas: {e}".format(
                s=name, r=replicas, e=str(e))) 
开发者ID:chaostoolkit,项目名称:chaostoolkit-kubernetes,代码行数:18,代码来源:actions.py

示例3: main

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def main():
    # Configs can be set in Configuration class directly or using helper
    # utility. If no argument provided, the config will be loaded from
    # default location.
    config.load_kube_config()
    apps_v1 = client.AppsV1Api()

    # Uncomment the following lines to enable debug logging
    # c = client.Configuration()
    # c.debug = True
    # apps_v1 = client.AppsV1Api(api_client=client.ApiClient(configuration=c))

    # Create a deployment object with client-python API. The deployment we
    # created is same as the `nginx-deployment.yaml` in the /examples folder.
    deployment = create_deployment_object()

    create_deployment(apps_v1, deployment)

    update_deployment(apps_v1, deployment)

    delete_deployment(apps_v1) 
开发者ID:kubernetes-client,项目名称:python,代码行数:23,代码来源:deployment_crud.py

示例4: test_create_apps_deployment_from_yaml

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def test_create_apps_deployment_from_yaml(self):
        """
        Should be able to create an apps/v1 deployment.
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "apps-deployment.yaml")
        app_api = client.AppsV1Api(k8s_client)
        dep = app_api.read_namespaced_deployment(name="nginx-app",
                                                 namespace="default")
        self.assertIsNotNone(dep)
        while True:
            try:
                app_api.delete_namespaced_deployment(
                    name="nginx-app", namespace="default",
                    body={})
                break
            except ApiException:
                continue 
开发者ID:kubernetes-client,项目名称:python,代码行数:21,代码来源:test_utils.py

示例5: test_create_apps_deployment_from_yaml_obj

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def test_create_apps_deployment_from_yaml_obj(self):
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        with open(self.path_prefix + "apps-deployment.yaml") as f:
            yml_obj = yaml.safe_load(f)

        yml_obj["metadata"]["name"] = "nginx-app-3"

        utils.create_from_dict(k8s_client, yml_obj)

        app_api = client.AppsV1Api(k8s_client)
        dep = app_api.read_namespaced_deployment(name="nginx-app-3",
                                                 namespace="default")
        self.assertIsNotNone(dep)
        app_api.delete_namespaced_deployment(
            name="nginx-app-3", namespace="default",
            body={}) 
开发者ID:kubernetes-client,项目名称:python,代码行数:18,代码来源:test_utils.py

示例6: test_create_general_list_from_yaml

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def test_create_general_list_from_yaml(self):
        """
        Should be able to create a service and a deployment
        from a kind: List yaml file
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "list.yaml")
        core_api = client.CoreV1Api(k8s_client)
        ext_api = client.AppsV1Api(k8s_client)
        svc = core_api.read_namespaced_service(name="list-service-test",
                                               namespace="default")
        self.assertIsNotNone(svc)
        dep = ext_api.read_namespaced_deployment(name="list-deployment-test",
                                                 namespace="default")
        self.assertIsNotNone(dep)
        core_api.delete_namespaced_service(name="list-service-test",
                                           namespace="default", body={})
        ext_api.delete_namespaced_deployment(name="list-deployment-test",
                                             namespace="default", body={}) 
开发者ID:kubernetes-client,项目名称:python,代码行数:22,代码来源:test_utils.py

示例7: test_create_from_list_in_multi_resource_yaml

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def test_create_from_list_in_multi_resource_yaml(self):
        """
        Should be able to create the items in the PodList and a deployment
        specified in the multi-resource file
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "multi-resource-with-list.yaml")
        core_api = client.CoreV1Api(k8s_client)
        app_api = client.AppsV1Api(k8s_client)
        pod_0 = core_api.read_namespaced_pod(
            name="mock-pod-0", namespace="default")
        self.assertIsNotNone(pod_0)
        pod_1 = core_api.read_namespaced_pod(
            name="mock-pod-1", namespace="default")
        self.assertIsNotNone(pod_1)
        dep = app_api.read_namespaced_deployment(
            name="mock", namespace="default")
        self.assertIsNotNone(dep)
        core_api.delete_namespaced_pod(
            name="mock-pod-0", namespace="default", body={})
        core_api.delete_namespaced_pod(
            name="mock-pod-1", namespace="default", body={})
        app_api.delete_namespaced_deployment(
            name="mock", namespace="default", body={}) 
开发者ID:kubernetes-client,项目名称:python,代码行数:27,代码来源:test_utils.py

示例8: test_create_namespaced_apps_deployment_from_yaml

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def test_create_namespaced_apps_deployment_from_yaml(self):
        """
        Should be able to create an apps/v1beta1 deployment
		in a test namespace.
        """
        k8s_client = client.api_client.ApiClient(configuration=self.config)
        utils.create_from_yaml(
            k8s_client, self.path_prefix + "apps-deployment.yaml",
            namespace=self.test_namespace)
        app_api = client.AppsV1Api(k8s_client)
        dep = app_api.read_namespaced_deployment(name="nginx-app",
                                                 namespace=self.test_namespace)
        self.assertIsNotNone(dep)
        app_api.delete_namespaced_deployment(
            name="nginx-app", namespace=self.test_namespace,
            body={}) 
开发者ID:kubernetes-client,项目名称:python,代码行数:18,代码来源:test_utils.py

示例9: __init__

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def __init__(self) -> None:
        kube_config.load_kube_config(
            config_file=os.environ.get("KUBECONFIG", KUBE_CONFIG_PATH),
            context=os.environ.get("KUBECONTEXT"),
        )
        models.V1beta1PodDisruptionBudgetStatus.disrupted_pods = property(
            fget=lambda *args, **kwargs: models.V1beta1PodDisruptionBudgetStatus.disrupted_pods(
                *args, **kwargs
            ),
            fset=_set_disrupted_pods,
        )
        self.deployments = kube_client.AppsV1Api()
        self.core = kube_client.CoreV1Api()
        self.policy = kube_client.PolicyV1beta1Api()
        self.apiextensions = kube_client.ApiextensionsV1beta1Api()
        self.custom = kube_client.CustomObjectsApi()
        self.autoscaling = kube_client.AutoscalingV2beta1Api()
        self.request = kube_client.ApiClient().request 
开发者ID:Yelp,项目名称:paasta,代码行数:20,代码来源:kubernetes_tools.py

示例10: get_apps_api

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def get_apps_api():
    """
    Create instance of Apps V1 API of kubernetes:
    https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/AppsV1Api.md
    :return: instance of client
    """
    global apps_api

    if apps_api is None:
        config.load_kube_config()
        if API_KEY is not None:
            # Configure API key authorization: BearerToken
            configuration = client.Configuration()
            configuration.api_key['authorization'] = API_KEY
            configuration.api_key_prefix['authorization'] = 'Bearer'
            apps_api = client.AppsV1Api(client.ApiClient(configuration))
        else:
            apps_api = client.AppsV1Api()

    return apps_api 
开发者ID:user-cont,项目名称:conu,代码行数:22,代码来源:client.py

示例11: undeploy_k8s_nfs

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def undeploy_k8s_nfs(self) -> bool:
        from kubernetes import client as k8sclient

        del_options = k8sclient.V1DeleteOptions()

        k8s_apps_v1_api_client = k8sclient.AppsV1Api()
        try:
            k8s_apps_v1_api_client.delete_namespaced_deployment(self.params.name, self.params.namespace, del_options)
        except k8sclient.rest.ApiException as e:
            print("Got exception: %s\n while deleting nfs-server", e)
            return False

        k8s_core_v1_api_client = k8sclient.CoreV1Api()
        try:
            k8s_core_v1_api_client.delete_namespaced_service(self.params.svc_name, self.params.namespace, del_options)
        except k8sclient.rest.ApiException as e:
            print("Got exception: %s\n while deleting the service for nfs-server", e)
            return False

        return True 
开发者ID:NervanaSystems,项目名称:coach,代码行数:22,代码来源:nfs_data_store.py

示例12: undeploy

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def undeploy(self):
        """
        Undeploy the Redis Pub/Sub service in an orchestrator.
        """
        from kubernetes import client
        if self.params.deployed:
            return

        from kubernetes import client
        api_client = client.AppsV1Api()
        delete_options = client.V1DeleteOptions()
        try:
            api_client.delete_namespaced_deployment(self.redis_server_name, self.params.orchestrator_params['namespace'], delete_options)
        except client.rest.ApiException as e:
            print("Got exception: %s\n while deleting redis-server", e)

        api_client = client.CoreV1Api()
        try:
            api_client.delete_namespaced_service(self.redis_service_name, self.params.orchestrator_params['namespace'], delete_options)
        except client.rest.ApiException as e:
            print("Got exception: %s\n while deleting redis-server", e) 
开发者ID:NervanaSystems,项目名称:coach,代码行数:23,代码来源:redis.py

示例13: remove_statefulset

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def remove_statefulset(name: str = None, ns: str = "default",
                       label_selector: str = None, secrets: Secrets = None):
    """
    Remove a statefulset by `name` in the namespace `ns`.

    The statefulset is removed by deleting it without
        a graceful period to trigger an abrupt termination.

    The selected resources are matched by the given `label_selector`.
    """
    field_selector = "metadata.name={name}".format(name=name)
    api = create_k8s_api_client(secrets)

    v1 = client.AppsV1Api(api)
    if label_selector:
        ret = v1.list_namespaced_stateful_set(
            ns, field_selector=field_selector,
            label_selector=label_selector)
    else:
        ret = v1.list_namespaced_stateful_set(ns,
                                              field_selector=field_selector)

    logger.debug("Found {d} statefulset(s) named '{n}' in ns '{s}'".format(
        d=len(ret.items), n=name, s=ns))

    body = client.V1DeleteOptions()
    for d in ret.items:
        res = v1.delete_namespaced_stateful_set(
            d.metadata.name, ns, body=body) 
开发者ID:chaostoolkit,项目名称:chaostoolkit-kubernetes,代码行数:31,代码来源:actions.py

示例14: modify_k8s_autoscaler

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def modify_k8s_autoscaler(action):
    """
    Pauses or resumes the Kubernetes autoscaler
    """

    try:
        config.load_incluster_config()
    except config.ConfigException:
        try:
            config.load_kube_config()
        except config.ConfigException:
            raise Exception("Could not configure kubernetes python client")

    # Configure API key authorization: BearerToken
    configuration = client.Configuration()
    # create an instance of the API class
    k8s_api = client.AppsV1Api(client.ApiClient(configuration))
    if action == 'pause':
        logger.info('Pausing k8s autoscaler...')
        body = {'spec': {'replicas': 0}}
    elif action == 'resume':
        logger.info('Resuming k8s autoscaler...')
        body = {'spec': {'replicas': app_config['K8S_AUTOSCALER_REPLICAS']}}
    else:
        logger.info('Invalid k8s autoscaler option')
        sys.exit(1)
    try:
        k8s_api.patch_namespaced_deployment(
            app_config['K8S_AUTOSCALER_DEPLOYMENT'],
            app_config['K8S_AUTOSCALER_NAMESPACE'],
            body
        )
        logger.info('K8s autoscaler modified to replicas: {}'.format(body['spec']['replicas']))
    except ApiException as e:
        logger.info('Scaling of k8s autoscaler failed. Error code was {}, {}. Exiting.'.format(e.reason, e.body))
        sys.exit(1) 
开发者ID:hellofresh,项目名称:eks-rolling-update,代码行数:38,代码来源:k8s.py

示例15: __init__

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1Api [as 别名]
def __init__(self, bearer_token=None):
        '''
        Initialize connection to Kubernetes
        '''
        self.bearer_token = bearer_token
        api_client = None

        try:
            config.load_incluster_config()
        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) 
开发者ID:airshipit,项目名称:armada,代码行数:28,代码来源:k8s.py


注:本文中的kubernetes.client.AppsV1Api方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。