Skip to content

Submit a Run:ai Job via Kubernetes API


Researcher Kubernetes API is deprecated. See Cluster API for its replacement.

This article is a complementary article to the article on launching jobs via YAML. It shows how to use a programming language and Kubernetes API to submit jobs.

The article uses Python, though Kubernetes API is available in several other programming languages.

Submit a Run:ai Job

from __future__ import print_function
import kubernetes
from kubernetes import client, config
from pprint import pprint
import json


with client.ApiClient() as api_client:

    namespace = 'runai-team-a'  # Run:ai project name is prefixed by runai-
    jobname = 'my-job'
    username = 'john'  # used in un-authenticated systems only
    gpus = 1

    body = client.V1Job(api_version="", kind="RunaiJob")
    body.metadata = client.V1ObjectMeta(namespace=namespace, name=jobname)

    template = client.V1PodTemplate()
    template.template = client.V1PodTemplateSpec()
    template.template.metadata = client.V1ObjectMeta(labels = {'user' : username})

    resource = client.V1ResourceRequirements(limits= {'' : gpus})
    container = client.V1Container(
        name=jobname, image='', resources=resource)
    template.template.spec = client.V1PodSpec(
        containers=[container], restart_policy='Never', scheduler_name='runai-scheduler')
    body.spec = client.V1JobSpec(template=template.template)


        api_instance = client.CustomObjectsApi(api_client)
        api_response = api_instance.create_namespaced_custom_object(
            "", "v1", namespace, "runaijobs", body)
    except as e:
        print("Exception when calling AppsV1Api->create_namespaced_job: %s\n" % e)