Use python client to create Kubernetes CronJob from yaml

6/14/2019

I am trying to use the K8S python client to create a bunch of cronjobs on my cluster. I can't seem to find a create_from_yaml for cornjobs or any resources other than deployments for that matter. What I want to do is:

from kubernetes import client, utils

batchv1beta1 = client.BatchV1beta1Api()
utils.create_from_yaml(batchv1beta1, 'jobs/job-01.yaml')

But this doesn't work obviously since this is not a valid attribute. Any guidance is appreciated!

-- cookiedough
kubernetes
kubernetes-python-client
python

1 Answer

6/24/2019

Actually, utils.create_from_yaml supports any Kubernetes objects. This should work:

from kubernetes import client, utils 

k8s_client = client.ApiClient() 
utils.create_from_yaml(k8s_client, 'jobs/job-01.yaml') 
-- PjoterS
Source: StackOverflow