code: def _get_service_port(
      service: str, namespace: str, target_port: int
  ) -> int:
      """Given a K8s service and a port targetted by the service, returns the
      corresponding port exposed by the service.
  
      Args:
          service: Name of a K8s service.
          namespace: Namespace to which the service belongs.
          target_port: Port targeted by the service.
  
      Returns:
          service_port: The port exposed by the service.
      """
      service_str = (
          subprocess.check_output(
              [
                  "kubectl",
                  "-n",
                  namespace,
                  "get",
                  "service",
                  service,
                  "-o",
                  "yaml",
              ]
          )
          .decode()
          .strip()
      )
      service_dict = yaml.safe_load(service_str)
      service_ports: List = service_dict["spec"]["ports"]
      matching_ports = [
          port
          for port in service_ports
          if port["targetPort"] == target_port
      ]
      assert matching_ports
      service_port = matching_ports[0]["port"]
      return service_port
  
imports: import atexit
  import contextlib
  import logging
  import pathlib
  import subprocess
  import tempfile
  import time
  from typing import Any, Dict, Generator, List, Optional
  import yaml
  import os
  import ray
  from ray.job_submission import JobStatus, JobSubmissionClient
label_desc: Use image node_id 15 for calling a global function with example usage: _get_service_port(service, namespace, target_port) and returns: service_port