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


Python client.V1ServicePort方法代码示例

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


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

示例1: create_service

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ServicePort [as 别名]
def create_service():
    core_v1_api = client.CoreV1Api()
    body = client.V1Service(
        api_version="v1",
        kind="Service",
        metadata=client.V1ObjectMeta(
            name="service-example"
        ),
        spec=client.V1ServiceSpec(
            selector={"app": "deployment"},
            ports=[client.V1ServicePort(
                port=5678,
                target_port=5678
            )]
        )
    )
    # Creation of the Deployment in specified namespace
    # (Can replace "default" with a namespace you may have created)
    core_v1_api.create_namespaced_service(namespace="default", body=body) 
开发者ID:kubernetes-client,项目名称:python,代码行数:21,代码来源:ingress_create.py

示例2: simple_service

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ServicePort [as 别名]
def simple_service():
    """Return the Kubernetes config matching the simple-service.yaml manifest."""
    return client.V1Service(
        api_version='v1',
        kind='Service',
        metadata=client.V1ObjectMeta(
            name='my-service'
        ),
        spec=client.V1ServiceSpec(
            selector={
                'app': 'MyApp'
            },
            ports=[
                client.V1ServicePort(
                    protocol='TCP',
                    port=80,
                    target_port=9376
                )
            ]
        )
    ) 
开发者ID:vapor-ware,项目名称:kubetest,代码行数:23,代码来源:conftest.py

示例3: k8s_ports_to_metadata_ports

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ServicePort [as 别名]
def k8s_ports_to_metadata_ports(k8s_ports):
    """
    :param k8s_ports: list of V1ServicePort
    :return: list of str, list of exposed ports, example:
            - ['1234/tcp', '8080/udp']
    """

    ports = []

    for k8s_port in k8s_ports:
        if k8s_port.protocol is not None:
            ports.append("%s/%s" % (k8s_port.port, k8s_port.protocol.lower()))
        else:
            ports.append(str(k8s_port.port))

    return ports 
开发者ID:user-cont,项目名称:conu,代码行数:18,代码来源:utils.py

示例4: metadata_ports_to_k8s_ports

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ServicePort [as 别名]
def metadata_ports_to_k8s_ports(ports):
    """
    :param ports: list of str, list of exposed ports, example:
            - ['1234/tcp', '8080/udp']
    :return: list of V1ServicePort
    """

    exposed_ports = []

    for port in ports:
        splits = port.split("/", 1)
        port = int(splits[0])
        protocol = splits[1].upper() if len(splits) > 1 else None
        exposed_ports.append(client.V1ServicePort(port=port, protocol=protocol))

    return exposed_ports 
开发者ID:user-cont,项目名称:conu,代码行数:18,代码来源:utils.py

示例5: create_svc_manifest

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ServicePort [as 别名]
def create_svc_manifest(name, port, target_port):
    spec = client.V1ServiceSpec(
            selector={"app": name},
            ports=[client.V1ServicePort(protocol="TCP", port=port, target_port=target_port)]
            )
    service = client.V1Service( metadata=client.V1ObjectMeta(name=name), spec=spec)
    return service 
开发者ID:mlperf,项目名称:training_results_v0.6,代码行数:9,代码来源:kubernetes.py

示例6: export_service

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ServicePort [as 别名]
def export_service(self,node_port):
        ports = [client.V1ServicePort(port=int(port), target_port=int(port)) for port in self.container_port]
        spec = client.V1ServiceSpec(ports=ports, selector={'project': self.dm_name},type='ClusterIP')
        if node_port:
            ports = [client.V1ServicePort(port=int(self.container_port[0]), target_port=int(self.container_port[0]),node_port=int(node_port))]
            spec = client.V1ServiceSpec(ports=ports,selector={'project':self.dm_name},type='NodePort')
        service = client.V1Service(
            api_version = 'v1',
            kind = 'Service',
            metadata=client.V1ObjectMeta(name=self.dm_name),
            spec=spec)
        return service 
开发者ID:wylok,项目名称:sparrow,代码行数:14,代码来源:k8s_resource.py

示例7: update_service

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ServicePort [as 别名]
def update_service(service, name, app, port):
    service.metadata = k8sclient.V1ObjectMeta()
    service.metadata.name = name
    service.metadata.labels = {"app": app}
    service.spec = k8sclient.V1ServiceSpec()
    service.spec.selector = {"app": app}
    service_port = k8sclient.V1ServicePort(port=port, target_port=port)
    service.spec.ports = [service_port] 
开发者ID:intel,项目名称:CPU-Manager-for-Kubernetes,代码行数:10,代码来源:clusterinit.py

示例8: createService

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ServicePort [as 别名]
def createService(cls, cluster_object: V1MongoClusterConfiguration) -> client.V1Service:
        """
        Creates a service model object.
        :param cluster_object: The cluster object from the YAML file.
        :return: The service object.
        """
        # Parse cluster data object.
        name = cluster_object.metadata.name

        # Create service.
        return client.V1Service(
            metadata=client.V1ObjectMeta(
                name=name,
                namespace=cluster_object.metadata.namespace,
                labels=cls.createDefaultLabels(name),
            ),
            spec=client.V1ServiceSpec(
                cluster_ip="None",  # create headless service, no load-balancing and a single service IP
                selector=cls.createDefaultLabels(name),
                ports=[client.V1ServicePort(
                    name="mongod",
                    port=cls.MONGO_PORT,
                    protocol="TCP"
                )],
            ),
        ) 
开发者ID:Ultimaker,项目名称:k8s-mongo-operator,代码行数:28,代码来源:KubernetesResources.py

示例9: init_service

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ServicePort [as 别名]
def init_service(self, tosca_kube_obj, kube_obj_name):
        list_service_port = list()
        service_label = tosca_kube_obj.labels
        for port in tosca_kube_obj.mapping_ports:
            if COLON_CHARACTER in port:
                ports = port.split(COLON_CHARACTER)
                published_port = int(ports[0])
                target_port = int(ports[1])
            else:
                target_port = published_port = int(port)
            service_port = client.V1ServicePort(
                name=str(published_port),
                port=published_port,
                target_port=target_port)
            list_service_port.append(service_port)

        deployment_name = kube_obj_name
        selector_by_name = self.config_labels(deployment_name)
        if tosca_kube_obj.labels:
            selectors = tosca_kube_obj.labels.copy()
        else:
            selectors = selector_by_name
        if tosca_kube_obj.mgmt_connection_point:
            service_label['management_connection'] = 'True'
        if tosca_kube_obj.network_name:
            service_label['network_name'] = tosca_kube_obj.network_name
        service_label['vdu_name'] = tosca_kube_obj.name

        metadata = client.V1ObjectMeta(name=deployment_name,
                                       labels=service_label)
        if tosca_kube_obj.service_type:
            service_type = tosca_kube_obj.service_type
        else:
            service_type = None
        service_spec = client.V1ServiceSpec(
            selector=selectors,
            ports=list_service_port,
            type=service_type)

        service = client.V1Service(
            api_version="v1",
            kind="Service",
            spec=service_spec,
            metadata=metadata)
        return service

    # init_config_map initializes Kubernetes ConfigMap object 
开发者ID:openstack,项目名称:tacker,代码行数:49,代码来源:translate_outputs.py


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