Hey team,
Firstly, I absolutely love the Python client.
That said, I'm running into an issue with how to use the Python client to emulate the behavior from the command line, specifically kubectl create -f <yaml file>
Is there a way that I can accomplish this currently?
Regards,
Vivek
The easiest is load the yaml file and use it as body to a specific method, see:
https://github.com/kubernetes-client/python/blob/master/examples/create_deployment.py
Ah, I see that makes a lot of sense thanks.
I will bump this issue - any method that would accept raw datastructure rather than create_namespaced_deployment?
My use case is to create multiple resources of different types in same loop. Think of trying example @sebgoa mentioned, but where https://github.com/kubernetes-client/python/blob/master/examples/nginx-deployment.yaml will have more resources (like Namespace or Service)
+1 I wonder what is beneath the create_namespaced_* calls. Where can we see the source of these calls?
I think at this point the easiest thing to do is just to use kubectl. But I'd really like a built-in solution in the API client too...
I cannot really believe this functionality is not there. So strange.
I cannot really believe this functionality is not there. So strange.
I think the purpose of kubernetes-client is to give access to APIs in as flexible a way as possible, not duplicate kubectl. Perhaps higher level functionality like this issue describes would make more sense in a separate library that wraps kubernetes-client.
I don't understand the discussion actually. You can create any object with the python client, you just need to find the correct method for it.
what kubectl does is that it adds a bit of parsing to detect the object kind and post on the correct endpoint. You could right a python wrapper that does the same things with this library. But indeed it is available out of the box.
Exactly, there is a bit of this magic: parsing of YAML files, going over each object in them, determining which type it is, and then calling the appropriate create method. This would be great to have here in Python interface.
I created an application with the idea of using a yaml template to specify values that need to be changed, passing directly to the dictionary that was created in the past
I'll take a crack at it.
/assign @micw523
@roycaihw: GitHub didn't allow me to assign the following users: micw523.
Note that only kubernetes-client members and repo collaborators can be assigned.
For more information please see the contributor guide
In response to this:
/assign @micw523
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
I'm not sure how different apply and create are (https://stackoverflow.com/questions/47369351/kubectl-apply-vs-kubectl-create this kinda helped..) but do we need a separate PR/issue for something similar to that in the python client? Or is there a way to combine @micw523's PR with some existing methods to get the same behaviour as kubectl apply -f. I'm trying to replace an apply -f call for a ConfigMap type YAML file.
@nakulpathak3 I think using "apply" is a separate feature and could be possibly filed as another issue. Although, I don't think the implementation would be too different from what I have in #655 ...
Please try out #655 (already merged in Master). This functionality is not perfect yet, subject to an existing issue #376 such as when you need to create a CRD, and it is not able to create lists #671. Otherwise please file complaints here and I鈥檒l tend to it.
Apply would require an internal diff and I鈥檒l see if the repo owners are interested in rolling out this function before I test the waters.
Is apply potentially just an upsert in k8s (i.e., if create gives a 409, do an update)? Or can we get partial objects which can't just replace the older versions and need examining of the old object to figure out the internal diff like you mentioned? Sorry not that familiar with kubernetes yet
kubectl apply is more advanced compared to kubectl create, and it's non-trivial to implement on client side.
I'm interested in the Kubernetes server-side apply feature, which has more capability than client-side (kubectl) apply. Hopefully that feature will rollout in 1.13 as alpha and we can try it out using the python client.
The original feature requested by this issue (create -f) has been added. Closing this issue now
/close
@roycaihw: Closing this issue.
In response to this:
kubectl applyis more advanced compared tokubectl create, and it's non-trivial to implement on client side.I'm interested in the Kubernetes server-side apply feature, which has more capability than client-side (kubectl) apply. Hopefully that feature will rollout in 1.13 as alpha and we can try it out using the python client.
The original feature requested by this issue (create -f) has been added. Closing this issue now
/close
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Just another point of view to complement the discussion, having the Python client execute YAML files enables the versioning of said YAML files, separate from the script code.
That is in itself very useful, at least for me :) It's wasn't about replicating kubectl per se...
kubectl delete -f <yaml file> is in plan?
Most helpful comment
I will bump this issue - any method that would accept raw datastructure rather than create_namespaced_deployment?
My use case is to create multiple resources of different types in same loop. Think of trying example @sebgoa mentioned, but where https://github.com/kubernetes-client/python/blob/master/examples/nginx-deployment.yaml will have more resources (like Namespace or Service)