Update Node Selector field for PODs on the flyHow do you update a node/minion's label in Kubernetes?DaemonSets on Google Container Engine (Kubernetes)Are there issues with running user pods on a Kubernetes master node?How to set label to Kubernetes node at creation time?what is the benefit of the taint model over node selectorUpdate API Server pods when more than 1 mastersHow to convert Daemonsets to kind DeploymentKubernetes: Dynamically identify node and taintPod from StatefulSet stuck in ContainerCreating state - FailedCreatePodSandBoxDoesn't Kubernetes honor HPA configuration when we execute “kubectl scale deploy”?

Super Regeneration Detector

Ethiopian Airlines tickets seem to always have the same price regardless of the proximity of the date?

Did Don Young threaten John Boehner with a 10 inch blade to the throat?

I have a domain, static IP and many devices I'd like to access outside my house. How to route them?

Remove side menu(right side) from finder

Difference between string += s1 and string = string + s1

Is there an English word to describe when a sound "protrudes"?

A bicolour masyu

Router restarts after big git push or big file upload

Does the Bracer of Flying Daggers really let a thief make 4 attacks per round?

Grease/lubricate rubber stabilizer bar bushings?

How was Luke's prosthetic hand in Episode V filmed?

What is the minimum wait before I may I re-enter the USA after a 90 day visit on the Visa B-2 Program?

Why should fork() have been designed to return a file descriptor?

Why did conquered countries after WWII recover, but countries conquered later continue suffering?

What is the origin of "Wonder begets wisdom?"

Do gauntlets count as armor?

Do I care if the housing market has gone up or down, if I'm moving from one house to another?

How to split the polynomial .

I want light controlled by one switch, not two

why neutral does not shock. how can a neutral be neutral in ac current?

ESTA Travel not Authorized. Accepted twice before!

Would using carbon dioxide as fuel work to reduce the greenhouse effect?

How to tell readers that I know my story is factually incorrect?



Update Node Selector field for PODs on the fly


How do you update a node/minion's label in Kubernetes?DaemonSets on Google Container Engine (Kubernetes)Are there issues with running user pods on a Kubernetes master node?How to set label to Kubernetes node at creation time?what is the benefit of the taint model over node selectorUpdate API Server pods when more than 1 mastersHow to convert Daemonsets to kind DeploymentKubernetes: Dynamically identify node and taintPod from StatefulSet stuck in ContainerCreating state - FailedCreatePodSandBoxDoesn't Kubernetes honor HPA configuration when we execute “kubectl scale deploy”?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have been trying different things around k8s these days. I am wondering about the field nodeSelector in the POD specification.
As I understand we have to assign some labels to the nodes and these labels can further be used in the nodeSelector field part of the POD specification.



Assignment of the node to pods based on nodeSelector works fine. But, after I create the pod, now I want to update/overwrite the nodeSelector field which would deploy my pod to new node based on new nodeSelector label updated.



I am thinking this in the same way it is done for the normal labels using kubectl label command.



Are there any hacks to achieve such a case ?



If this is not possible for the current latest versions of the kubernetes, why should not we consider it ?



Thanks.










share|improve this question

















  • 2





    You can change the nodeSelector values through kubectl edit deploy [DEPLOYMENT] -n [NAMESPACE] -o yaml. Once changed, the old pod will be terminated, and the new one will be scheduled on the new node.

    – cookiedough
    Mar 26 at 15:15

















1















I have been trying different things around k8s these days. I am wondering about the field nodeSelector in the POD specification.
As I understand we have to assign some labels to the nodes and these labels can further be used in the nodeSelector field part of the POD specification.



Assignment of the node to pods based on nodeSelector works fine. But, after I create the pod, now I want to update/overwrite the nodeSelector field which would deploy my pod to new node based on new nodeSelector label updated.



I am thinking this in the same way it is done for the normal labels using kubectl label command.



Are there any hacks to achieve such a case ?



If this is not possible for the current latest versions of the kubernetes, why should not we consider it ?



Thanks.










share|improve this question

















  • 2





    You can change the nodeSelector values through kubectl edit deploy [DEPLOYMENT] -n [NAMESPACE] -o yaml. Once changed, the old pod will be terminated, and the new one will be scheduled on the new node.

    – cookiedough
    Mar 26 at 15:15













1












1








1








I have been trying different things around k8s these days. I am wondering about the field nodeSelector in the POD specification.
As I understand we have to assign some labels to the nodes and these labels can further be used in the nodeSelector field part of the POD specification.



Assignment of the node to pods based on nodeSelector works fine. But, after I create the pod, now I want to update/overwrite the nodeSelector field which would deploy my pod to new node based on new nodeSelector label updated.



I am thinking this in the same way it is done for the normal labels using kubectl label command.



Are there any hacks to achieve such a case ?



If this is not possible for the current latest versions of the kubernetes, why should not we consider it ?



Thanks.










share|improve this question














I have been trying different things around k8s these days. I am wondering about the field nodeSelector in the POD specification.
As I understand we have to assign some labels to the nodes and these labels can further be used in the nodeSelector field part of the POD specification.



Assignment of the node to pods based on nodeSelector works fine. But, after I create the pod, now I want to update/overwrite the nodeSelector field which would deploy my pod to new node based on new nodeSelector label updated.



I am thinking this in the same way it is done for the normal labels using kubectl label command.



Are there any hacks to achieve such a case ?



If this is not possible for the current latest versions of the kubernetes, why should not we consider it ?



Thanks.







kubernetes kubectl pod






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 12:32









Pert8SPert8S

3031 silver badge14 bronze badges




3031 silver badge14 bronze badges







  • 2





    You can change the nodeSelector values through kubectl edit deploy [DEPLOYMENT] -n [NAMESPACE] -o yaml. Once changed, the old pod will be terminated, and the new one will be scheduled on the new node.

    – cookiedough
    Mar 26 at 15:15












  • 2





    You can change the nodeSelector values through kubectl edit deploy [DEPLOYMENT] -n [NAMESPACE] -o yaml. Once changed, the old pod will be terminated, and the new one will be scheduled on the new node.

    – cookiedough
    Mar 26 at 15:15







2




2





You can change the nodeSelector values through kubectl edit deploy [DEPLOYMENT] -n [NAMESPACE] -o yaml. Once changed, the old pod will be terminated, and the new one will be scheduled on the new node.

– cookiedough
Mar 26 at 15:15





You can change the nodeSelector values through kubectl edit deploy [DEPLOYMENT] -n [NAMESPACE] -o yaml. Once changed, the old pod will be terminated, and the new one will be scheduled on the new node.

– cookiedough
Mar 26 at 15:15












1 Answer
1






active

oldest

votes


















3














While editing deployment manually as cookiedough suggested is one of the options, I believe using kubctl patch would be a better solution.



You can either patch by using yaml file or JSON string, which makes it easier to integrate thing into scripts. Here is a complete reference.




Example



Here's a simple deployment of nginx I used, which will be created on node-1:



apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
nodeSelector:
kubernetes.io/hostname: node-1


JSON patch



You can patch the deployment to change the desired node as follows:
kubectl patch deployments nginx-deployment -p '"spec": "template": "spec": "nodeSelector": "kubernetes.io/hostname": "node-2"'



YAML patch



By running kubectl patch deployment nginx-deployment --patch "$(cat patch.yaml)", where patch.yaml is prepared as follows:



spec:
template:
spec:
nodeSelector:
kubernetes.io/hostname: node-2


Both will result in scheduler scheduling new pod on requested node, and terminating the old one as soon as the new one is ready.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55357287%2fupdate-node-selector-field-for-pods-on-the-fly%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    While editing deployment manually as cookiedough suggested is one of the options, I believe using kubctl patch would be a better solution.



    You can either patch by using yaml file or JSON string, which makes it easier to integrate thing into scripts. Here is a complete reference.




    Example



    Here's a simple deployment of nginx I used, which will be created on node-1:



    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: nginx-deployment
    labels:
    app: nginx
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: nginx
    template:
    metadata:
    labels:
    app: nginx
    spec:
    containers:
    - name: nginx
    image: nginx:1.7.9
    ports:
    - containerPort: 80
    nodeSelector:
    kubernetes.io/hostname: node-1


    JSON patch



    You can patch the deployment to change the desired node as follows:
    kubectl patch deployments nginx-deployment -p '"spec": "template": "spec": "nodeSelector": "kubernetes.io/hostname": "node-2"'



    YAML patch



    By running kubectl patch deployment nginx-deployment --patch "$(cat patch.yaml)", where patch.yaml is prepared as follows:



    spec:
    template:
    spec:
    nodeSelector:
    kubernetes.io/hostname: node-2


    Both will result in scheduler scheduling new pod on requested node, and terminating the old one as soon as the new one is ready.






    share|improve this answer



























      3














      While editing deployment manually as cookiedough suggested is one of the options, I believe using kubctl patch would be a better solution.



      You can either patch by using yaml file or JSON string, which makes it easier to integrate thing into scripts. Here is a complete reference.




      Example



      Here's a simple deployment of nginx I used, which will be created on node-1:



      apiVersion: apps/v1
      kind: Deployment
      metadata:
      name: nginx-deployment
      labels:
      app: nginx
      spec:
      replicas: 1
      selector:
      matchLabels:
      app: nginx
      template:
      metadata:
      labels:
      app: nginx
      spec:
      containers:
      - name: nginx
      image: nginx:1.7.9
      ports:
      - containerPort: 80
      nodeSelector:
      kubernetes.io/hostname: node-1


      JSON patch



      You can patch the deployment to change the desired node as follows:
      kubectl patch deployments nginx-deployment -p '"spec": "template": "spec": "nodeSelector": "kubernetes.io/hostname": "node-2"'



      YAML patch



      By running kubectl patch deployment nginx-deployment --patch "$(cat patch.yaml)", where patch.yaml is prepared as follows:



      spec:
      template:
      spec:
      nodeSelector:
      kubernetes.io/hostname: node-2


      Both will result in scheduler scheduling new pod on requested node, and terminating the old one as soon as the new one is ready.






      share|improve this answer

























        3












        3








        3







        While editing deployment manually as cookiedough suggested is one of the options, I believe using kubctl patch would be a better solution.



        You can either patch by using yaml file or JSON string, which makes it easier to integrate thing into scripts. Here is a complete reference.




        Example



        Here's a simple deployment of nginx I used, which will be created on node-1:



        apiVersion: apps/v1
        kind: Deployment
        metadata:
        name: nginx-deployment
        labels:
        app: nginx
        spec:
        replicas: 1
        selector:
        matchLabels:
        app: nginx
        template:
        metadata:
        labels:
        app: nginx
        spec:
        containers:
        - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
        nodeSelector:
        kubernetes.io/hostname: node-1


        JSON patch



        You can patch the deployment to change the desired node as follows:
        kubectl patch deployments nginx-deployment -p '"spec": "template": "spec": "nodeSelector": "kubernetes.io/hostname": "node-2"'



        YAML patch



        By running kubectl patch deployment nginx-deployment --patch "$(cat patch.yaml)", where patch.yaml is prepared as follows:



        spec:
        template:
        spec:
        nodeSelector:
        kubernetes.io/hostname: node-2


        Both will result in scheduler scheduling new pod on requested node, and terminating the old one as soon as the new one is ready.






        share|improve this answer













        While editing deployment manually as cookiedough suggested is one of the options, I believe using kubctl patch would be a better solution.



        You can either patch by using yaml file or JSON string, which makes it easier to integrate thing into scripts. Here is a complete reference.




        Example



        Here's a simple deployment of nginx I used, which will be created on node-1:



        apiVersion: apps/v1
        kind: Deployment
        metadata:
        name: nginx-deployment
        labels:
        app: nginx
        spec:
        replicas: 1
        selector:
        matchLabels:
        app: nginx
        template:
        metadata:
        labels:
        app: nginx
        spec:
        containers:
        - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
        nodeSelector:
        kubernetes.io/hostname: node-1


        JSON patch



        You can patch the deployment to change the desired node as follows:
        kubectl patch deployments nginx-deployment -p '"spec": "template": "spec": "nodeSelector": "kubernetes.io/hostname": "node-2"'



        YAML patch



        By running kubectl patch deployment nginx-deployment --patch "$(cat patch.yaml)", where patch.yaml is prepared as follows:



        spec:
        template:
        spec:
        nodeSelector:
        kubernetes.io/hostname: node-2


        Both will result in scheduler scheduling new pod on requested node, and terminating the old one as soon as the new one is ready.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 17:25









        MWZMWZ

        3429 bronze badges




        3429 bronze badges
















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55357287%2fupdate-node-selector-field-for-pods-on-the-fly%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript