Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl create -f <yaml file> #504

Closed
viveknair opened this issue Apr 4, 2018 · 21 comments
Closed

kubectl create -f <yaml file> #504

viveknair opened this issue Apr 4, 2018 · 21 comments
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature.

Comments

@viveknair
Copy link

viveknair commented Apr 4, 2018

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

@sebgoa
Copy link
Contributor

sebgoa commented Apr 5, 2018

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

@viveknair
Copy link
Author

Ah, I see that makes a lot of sense thanks.

@inc0
Copy link

inc0 commented Apr 9, 2018

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)

@mmumshad
Copy link

+1 I wonder what is beneath the create_namespaced_* calls. Where can we see the source of these calls?

@nerdinand
Copy link

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...

@mitar
Copy link
Contributor

mitar commented Oct 12, 2018

I cannot really believe this functionality is not there. So strange.

@roycaihw roycaihw added kind/feature Categorizes issue or PR as related to a new feature. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Oct 12, 2018
@JonathanRRogers
Copy link

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.

@sebgoa
Copy link
Contributor

sebgoa commented Oct 13, 2018

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.

@mitar
Copy link
Contributor

mitar commented Oct 14, 2018

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.

@eagle9527
Copy link

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

@micw523
Copy link
Contributor

micw523 commented Oct 17, 2018

I'll take a crack at it.

@roycaihw
Copy link
Member

/assign @micw523

@k8s-ci-robot
Copy link
Contributor

@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.

@nakulpathak3
Copy link

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.

@micw523
Copy link
Contributor

micw523 commented Oct 25, 2018

@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 ...

@micw523
Copy link
Contributor

micw523 commented Nov 1, 2018

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’ll tend to it.

Apply would require an internal diff and I’ll see if the repo owners are interested in rolling out this function before I test the waters.

@nakulpathak3
Copy link

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

@roycaihw
Copy link
Member

roycaihw commented Nov 6, 2018

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

@k8s-ci-robot
Copy link
Contributor

@roycaihw: Closing this issue.

In response to this:

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

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.

@davi5e
Copy link

davi5e commented Dec 18, 2018

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...

@zgfh
Copy link

zgfh commented Dec 24, 2018

kubectl delete -f <yaml file> is in plan?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests