Skip to content

kubectl create -f <yaml file> #504

Closed

Description

@viveknair

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

Activity

  1. sebgoa commented on Apr 5, 2018

    @sebgoa
    Contributor

    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

  2. viveknair commented on Apr 5, 2018

    @viveknair
    Author

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

  3. inc0 commented on Apr 9, 2018

    @inc0

    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)

  4. mmumshad commented on Sep 20, 2018

    @mmumshad

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

  5. nerdinand commented on Sep 20, 2018

    @nerdinand

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

  6. mitar commented on Oct 12, 2018

    @mitar
    Contributor

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

  7. added
    kind/featureCategorizes issue or PR as related to a new feature.
    good first issueDenotes an issue ready for a new contributor, according to the "help wanted" guidelines.
    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
    on Oct 12, 2018
  8. JonathanRRogers commented on Oct 13, 2018

    @JonathanRRogers

    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.

  9. sebgoa commented on Oct 13, 2018

    @sebgoa
    Contributor

    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.

  10. mitar commented on Oct 14, 2018

    @mitar
    Contributor

    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.

  11. eagle9527 commented on Oct 15, 2018

    @eagle9527

    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

  12. micw523 commented on Oct 17, 2018

    @micw523
    Contributor

    I'll take a crack at it.

  13. roycaihw commented on Oct 17, 2018

    @roycaihw
    Member

    /assign @micw523

  14. k8s-ci-robot commented on Oct 17, 2018

    @k8s-ci-robot
    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

    Details

    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.

  15. nakulpathak3 commented on Oct 25, 2018

    @nakulpathak3

    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.

  16. micw523 commented on Oct 25, 2018

    @micw523
    Contributor

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

  17. micw523 commented on Nov 1, 2018

    @micw523
    Contributor

    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.

  18. nakulpathak3 commented on Nov 1, 2018

    @nakulpathak3

    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

  19. roycaihw commented on Nov 6, 2018

    @roycaihw
    Member

    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

  20. k8s-ci-robot commented on Nov 6, 2018

    @k8s-ci-robot
    Contributor

    @roycaihw: Closing this issue.

    Details

    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.

  21. davi5e commented on Dec 18, 2018

    @davi5e

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

  22. zgfh commented on Dec 24, 2018

    @zgfh

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueDenotes an issue ready for a new contributor, according to the "help wanted" guidelines.help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions