Add service

This commit is contained in:
David Boreham 2023-11-21 14:34:01 -07:00
parent ee3d3364ba
commit b608a41ff1
2 changed files with 32 additions and 0 deletions

View File

@ -102,6 +102,21 @@ class ClusterInfo:
)
return ingress
def get_service(self):
service = client.V1Service(
metadata=client.V1ObjectMeta(name=f"{self.app_name}-service"),
spec=client.V1ServiceSpec(
type="ClusterIP",
ports=[client.V1ServicePort(
port=80,
target_port=80
)],
selector={"matchLabels":
{"app": self.app_name}}
)
)
return service
def get_pvcs(self):
result = []
volumes = named_volumes_from_pod_files(self.parsed_pod_yaml_map)

View File

@ -105,6 +105,15 @@ class K8sDeployer(Deployer):
print(f"{deployment_resp.metadata.namespace} {deployment_resp.metadata.name} \
{deployment_resp.metadata.generation} {deployment_resp.spec.template.spec.containers[0].image}")
service: client.V1Service = self.cluster_info.get_service()
service_resp = self.core_api.create_namespaced_service(
namespace=self.k8s_namespace,
body=service
)
if opts.o.debug:
print("Service created:")
print(f"{service_resp}")
# TODO: disable ingress for kind
ingress: client.V1Ingress = self.cluster_info.get_ingress()
@ -145,6 +154,14 @@ class K8sDeployer(Deployer):
name=deployment.metadata.name, namespace=self.k8s_namespace
)
service: client.V1Service = self.cluster_info.get_service()
if opts.o.debug:
print(f"Deleting service: {service}")
self.core_api.delete_namespaced_service(
namespace=self.k8s_namespace,
body=service
)
# TODO: disable ingress for kind
ingress: client.V1Ingress = self.cluster_info.get_ingress()
if opts.o.debug: