kubectl run is deprecated - looking for alternative

后端 未结 7 566
长情又很酷
长情又很酷 2020-12-23 13:48

I\'m using kubectl run with environment parameters to create temporary docker containers for me (e.g. some forwarding for debugging purposes). Since several wee

相关标签:
7条回答
  • 2020-12-23 14:21

    you can use:

    kubectl run --generator=run-pod/v1 --image=busybox busybox --dry-run --env=foo=bar
    

    Which isn't being deprecated.

    0 讨论(0)
  • 2020-12-23 14:22

    To run a pod, this simple command is enough:

    kubectl run --restart=Never <name> --image=<image>
    

    Check https://www.k8s-school.fr/resources/blog/1-kubectl-run-deprecated/#pod for additional informations.

    0 讨论(0)
  • 2020-12-23 14:23

    kubectl run by default, will create a Deployment.

    The command in its full extend is:

    kubectl run --generator=deployment/apps.v1 <deployment_name> --image=<image_to_use_in_the_container_of_the_deployment's_pod>
    

    So the kubernetes resource that will be created upon execution of the run command is defined by the value of the --generator flag.

    What the deprecation message hints (and is also clarified by the answer provided by @soltysh) is that the particular practice will be removed.

    So in future kubernetes versions, the run command will by default (and as only option) create pods (and not deployments), i.e. the command in its full extend will become:

    kubectl run --generator=run-pod/v1 <pod_name> --image=<image_of_the_container_of_the_pod>
    

    In case you want to create any other kubernetes resource type, this will be impossible via run command so you will have to resort to explicit imperative create or declarative apply -f, the later pointing to kubernetes yml files with the corresponding resource defintition, as in

    kubernetes apply -f <yaml_file_with_my_deployment.yml>
    
    0 讨论(0)
  • 2020-12-23 14:25

    When you run

    kubectl run <name> --image=<image> --port=<port>
    

    You are implicitly running

    kubectl run --generator=deployment/apps.v1 run <name> --image=<image> --port=<port>
    

    Which tells kubernetes what resource it needs to generate

    It is quite overwhelming to deal with such a variety of parameters with run

    Hence, as of v1.15 and greater, all --generators apart from run-pod are deprecated.

    See the table below

    Pod                                 v1                  kubectl run --generator=run-pod/v1
    ReplicationController (deprecated)  v1                  kubectl run --generator=run/v1
    Deployment (deprecated)         extensions/v1beta1      kubectl run --generator=deployment/v1beta1
    Deployment (deprecated)         apps/v1beta1            kubectl run --generator=deployment/apps.v1beta1
    Job (deprecated)                batch/v1                kubectl run --generator=job/v1
    CronJob (deprecated)            batch/v2alpha1          kubectl run --generator=cronjob/v2alpha1
    CronJob (deprecated)            batch/v1beta1           kubectl run --generator=cronjob/v1beta1
    

    Solution is to either use create or apply -f. The latter uses a yml file.

    0 讨论(0)
  • 2020-12-23 14:26

    Like the message said, you should use kubectl create . Just define a minimal pod yaml definition and use kubectl create -f mypod.yml

    0 讨论(0)
  • 2020-12-23 14:30

    I noticed that running the following command WITHOUT specifying the generator parameter:

    kubectl run <name> --image=<image>
    

    It returns this error:

    kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
    

    What's very confusing about this message is that you never specified the --generator parameter in the first place. However the main point here is to explicitly specify the generator as directed by the error message as follows:

    kubectl run --generator=run-pod/v1 <name> --image=<image>
    

    Then it should run successfully. (they should have just defaulted the generator to run-pod/v1 to avoid this confusion and/or just encouraged the use of create).

    However, based on @soltysh answer, it sounds as if they are now recommending 'create' over 'run.'

    0 讨论(0)
提交回复
热议问题