本文整理汇总了Python中kubernetes.client.V1Service方法的典型用法代码示例。如果您正苦于以下问题:Python client.V1Service方法的具体用法?Python client.V1Service怎么用?Python client.V1Service使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kubernetes.client
的用法示例。
在下文中一共展示了client.V1Service方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_service
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [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)
示例2: create_service
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [as 别名]
def create_service(self, name, app, ns, port, svc_type="NodePort", traffic_policy="Local", cluster_ip=None, ipv6=False):
service = client.V1Service(
metadata=client.V1ObjectMeta(
name=name,
labels={"name": name},
),
spec={
"ports": [{"port": port}],
"selector": {"app": app},
"type": svc_type,
"externalTrafficPolicy": traffic_policy,
}
)
if cluster_ip:
service.spec["clusterIP"] = cluster_ip
if ipv6:
service.spec["ipFamily"] = "IPv6"
api_response = self.cluster.create_namespaced_service(
body=service,
namespace=ns,
)
logger.debug("Additional Service created. status='%s'" % str(api_response.status))
示例3: simple_service
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [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
)
]
)
)
示例4: create_svc_manifest
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [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
示例5: export_service
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [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
示例6: createService
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [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"
)],
),
)
示例7: listResources
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [as 别名]
def listResources(self) -> List[V1Service]:
return self.kubernetes_service.listAllServicesWithLabels().items
示例8: getResource
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [as 别名]
def getResource(self, cluster_object: V1MongoClusterConfiguration) -> V1Service:
return self.kubernetes_service.getService(cluster_object.metadata.name, cluster_object.metadata.namespace)
示例9: createResource
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [as 别名]
def createResource(self, cluster_object: V1MongoClusterConfiguration) -> V1Service:
return self.kubernetes_service.createService(cluster_object)
示例10: updateResource
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [as 别名]
def updateResource(self, cluster_object: V1MongoClusterConfiguration) -> V1Service:
return self.kubernetes_service.updateService(cluster_object)
示例11: createService
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [as 别名]
def createService(self, cluster_object: V1MongoClusterConfiguration) -> Optional[client.V1Service]:
"""
Creates the given cluster.
:param cluster_object: The cluster object from the YAML file.
:return: The created service.
"""
namespace = cluster_object.metadata.namespace
body = KubernetesResources.createService(cluster_object)
logging.info("Creating service %s @ ns/%s.", body.metadata.name, namespace)
with IgnoreIfExists():
return self.core_api.create_namespaced_service(namespace, body)
示例12: updateService
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [as 别名]
def updateService(self, cluster_object: V1MongoClusterConfiguration) -> client.V1Service:
"""
Updates the given cluster.
:param cluster_object: The cluster object from the YAML file.
:return: The updated service.
"""
name = cluster_object.metadata.name
namespace = cluster_object.metadata.namespace
body = KubernetesResources.createService(cluster_object)
logging.info("Updating service %s @ ns/%s.", name, namespace)
return self.core_api.patch_namespaced_service(name, namespace, body)
示例13: test_simple_service_ok
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [as 别名]
def test_simple_service_ok(self, manifest_dir, simple_service):
"""Test loading the simple service successfully."""
obj = manifest.load_type(
client.V1Service,
os.path.join(manifest_dir, 'simple-service.yaml')
)
assert obj == simple_service
示例14: test_ok_multi
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [as 别名]
def test_ok_multi(self, manifest_dir):
"""Load manifest file with multiple object definitions."""
objs = manifest.load_file(
os.path.join(manifest_dir, 'multi-obj-manifest.yaml')
)
assert len(objs) == 3
assert isinstance(objs[0], client.models.v1_service.V1Service)
assert isinstance(objs[1], client.models.v1_service.V1Service)
assert isinstance(objs[2], client.models.v1_deployment.V1Deployment)
示例15: _create_config_service
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Service [as 别名]
def _create_config_service(self):
metadata = k8s_client.V1ObjectMeta(namespace=self._namespace, name=self.config_path, labels=self._labels)
body = k8s_client.V1Service(metadata=metadata, spec=k8s_client.V1ServiceSpec(cluster_ip='None'))
try:
if not self._api.create_namespaced_service(self._namespace, body):
return
except Exception as e:
if not isinstance(e, k8s_client.rest.ApiException) or e.status != 409: # Service already exists
return logger.exception('create_config_service failed')
self._should_create_config_service = False