code: def __dict_to_service_spec(spec):
      '''
      Converts a dictionary into kubernetes V1ServiceSpec instance.
      '''
      spec_obj = kubernetes.client.V1ServiceSpec()
      for key, value in iteritems(spec):  # pylint: disable=too-many-nested-blocks
          if key == 'ports':
              spec_obj.ports = []
              for port in value:
                  kube_port = kubernetes.client.V1ServicePort()
                  if isinstance(port, dict):
                      for port_key, port_value in iteritems(port):
                          if hasattr(kube_port, port_key):
                              setattr(kube_port, port_key, port_value)
                  else:
                      kube_port.port = port
                  spec_obj.ports.append(kube_port)
          elif hasattr(spec_obj, key):
              setattr(spec_obj, key, value)
  
      return spec_obf __dict_to_service_spec(spec):
      '''
      Converts a dictionary into kubernetes V1ServiceSpec instance.
      '''
      spec_obj = kubernetes.client.V1ServiceSpec()
      for key, value in iteritems(spec):  # pylint: disable=too-many-nested-blocks
          if key == 'ports':
              spec_obj.ports = []
              for port in value:
                  kube_port = kubernetes.client.V1ServicePort()
                  if isinstance(port, dict):
                      for port_key, port_value in iteritems(port):
                          if hasattr(kube_port, port_key):
                              setattr(kube_port, port_key, port_value)
                  else:
                      kube_port.port = port
                  spec_obj.ports.append(kube_port)
          elif hasattr(spec_obj, key):
              setattr(spec_obj, key, value)
  
      return spec_obj
docs: Converts a dictionary into kubernetes V1ServiceSpec instance.