2

我想从 python 以编程方式将 SparkApplication 提交Kubernetes 集群。

job.yaml像这样的工作定义

apiVersion: sparkoperator.k8s.io/v1beta1
kind: SparkApplication
metadata:
  name: my-test
  namespace: default
spec:
  sparkVersion: "2.4.0"
  type: Python
...

使用 运行没有问题kubectl apply -f job.yaml,但我不知道是否以及如何使用kubernetes-client以编程方式开始这项工作。

有谁知道如何做到这一点?

4

2 回答 2

0

这可能是您正在寻找的:

from __future__ import print_function
import time
import kubernetes.client
from kubernetes.client.rest import ApiException
from pprint import pprint

# Configure API key authorization: BearerToken
configuration = kubernetes.client.Configuration()
configuration.api_key['authorization'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['authorization'] = 'Bearer'

# create an instance of the API class
api_instance = kubernetes.client.CustomObjectsApi(kubernetes.client.ApiClient(configuration))
group = 'group_example' # str | The custom resource's group name
version = 'version_example' # str | The custom resource's version
namespace = 'namespace_example' # str | The custom resource's namespace
plural = 'plural_example' # str | The custom resource's plural name. For TPRs this would be lowercase plural kind.
body = NULL # object | The JSON schema of the Resource to create.
pretty = 'pretty_example' # str | If 'true', then the output is pretty printed. (optional)

try: 
    api_response = api_instance.create_namespaced_custom_object(group, version, namespace, plural, body, pretty=pretty)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling CustomObjectsApi->create_namespaced_custom_object: %s\n" % e)

来源https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CustomObjectsApi.md#create_namespaced_custom_object

于 2019-06-28T11:42:44.603 回答
0

这是提到的示例,如何使用 kubernetes python 客户端在 kubernetes 上创建第三方资源。

https://github.com/kubernetes-client/python/blob/master/examples/create_thirdparty_resource.md

希望这可以帮助。

于 2019-02-14T10:26:00.647 回答