def launch_kubernetes_kernel(kernel_id, port_range, response_addr, spark_context_init_mode):
    config.load_incluster_config()
    keywords = dict()
    keywords['eg_port_range'] = port_range
    keywords['eg_response_address'] = response_addr
    keywords['kernel_id'] = kernel_id
    keywords['kernel_name'] = os.path.basename(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    keywords['kernel_spark_context_init_mode'] = spark_context_init_mode
    for (name, value) in os.environ.items():
        if name.startswith('KERNEL_'):
            keywords[name.lower()] = yaml.safe_load(value)
    k8s_yaml = generate_kernel_pod_yaml(keywords)
    kernel_namespace = keywords['kernel_namespace']
    k8s_objs = yaml.safe_load_all(k8s_yaml)
    for k8s_obj in k8s_objs:
        if k8s_obj.get('kind'):
            if (k8s_obj['kind'] == 'Pod'):
                client.CoreV1Api(client.ApiClient()).create_namespaced_pod(body=k8s_obj, namespace=kernel_namespace)
            elif (k8s_obj['kind'] == 'Secret'):
                client.CoreV1Api(client.ApiClient()).create_namespaced_secret(body=k8s_obj, namespace=kernel_namespace)
            elif (k8s_obj['kind'] == 'PersistentVolumeClaim'):
                client.CoreV1Api(client.ApiClient()).create_namespaced_persistent_volume_claim(body=k8s_obj, namespace=kernel_namespace)
            elif (k8s_obj['kind'] == 'PersistentVolume'):
                client.CoreV1Api(client.ApiClient()).create_persistent_volume(body=k8s_obj)
            else:
                sys.exit("ERROR - Unhandled Kubernetes object kind '{}' found in yaml file - kernel launch terminating!".format(k8s_obj['kind']))
        else:
            sys.exit("ERROR - Unknown Kubernetes object '{}' found in yaml file - kernel launch terminating!".format(k8s_obj))
def launch_kubernetes_kernel(kernel_id, port_range, response_addr, spark_context_init_mode):
    config.load_incluster_config()
    keywords = dict()
    keywords['eg_port_range'] = port_range
    keywords['eg_response_address'] = response_addr
    keywords['kernel_id'] = kernel_id
    keywords['kernel_name'] = os.path.basename(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    keywords['kernel_spark_context_init_mode'] = spark_context_init_mode
    for (name, value) in os.environ.items():
        if name.startswith('KERNEL_'):
            keywords[name.lower()] = yaml.safe_load(value)
    k8s_yaml = generate_kernel_pod_yaml(keywords)
    kernel_namespace = keywords['kernel_namespace']
    k8s_objs = yaml.safe_load_all(k8s_yaml)
    for k8s_obj in k8s_objs:
        if k8s_obj.get('kind'):
            if (k8s_obj['kind'] == 'Pod'):
                client.CoreV1Api(client.ApiClient()).create_namespaced_pod(body=k8s_obj, namespace=kernel_namespace)
            elif (k8s_obj['kind'] == 'Secret'):
                client.CoreV1Api(client.ApiClient()).create_namespaced_secret(body=k8s_obj, namespace=kernel_namespace)
            elif (k8s_obj['kind'] == 'PersistentVolumeClaim'):
                client.CoreV1Api(client.ApiClient()).create_namespaced_persistent_volume_claim(body=k8s_obj, namespace=kernel_namespace)
            elif (k8s_obj['kind'] == 'PersistentVolume'):
                client.CoreV1Api(client.ApiClient()).create_persistent_volume(body=k8s_obj)
            else:
                sys.exit("ERROR - Unhandled Kubernetes object kind '{}' found in yaml file - kernel launch terminating!".format(k8s_obj['kind']))
        else:
            sys.exit("ERROR - Unknown Kubernetes object '{}' found in yaml file - kernel launch terminating!".format(k8s_obj))