<p>I'm using Rancher over Kubernetes to create our test/dev environment. First of all, it's a great tool and I'm amazed of how it simplify the management of such environments.</p>

<p>That said, I have an issue (which is probably more a knowledge lack of Rancher). I try to automate the deployment via Jenkins, and as we will have several stacks into our test environment, I want to dynamically update the loadbalancer instances to add routes for new environement from Jenkins with Rancher CLI.</p>

<p>At the moment, I just try to run this command :</p>

<pre><code>rancher --url http://myrancher_server:8080 --access-key &lt;key&gt; --secret-key &lt;secret&gt; --env dev-test stack create kubernetes-ingress-lbs -r loadbalancer-rancher-service.yml
</code></pre>

<p>My docker-compose.yml file is like the following :</p>

<pre><code>version: '2'
services:
  frontend:
    image: 172.19.51.97:5000/frontend
  dev-test-lb:
    image: rancher/load-balancer-service
    ports:
  - 82: 8086
links:
  - fronted:frontend
</code></pre>

<p>My rancher compose file is like this:</p>

<pre><code>version: '2'
services:
  dev-test-lb:
    scale: 4
    lb_config:
      port_rules:
      - source_port: 82
        path: /products
        target_port: 8086
        service: products
      - source_port: 82
        path: /
        target_port: 4201
        service: frontend
  health_check:
    port: 42
    interval: 2000
    unhealthy_threshold: 3
    healthy_threshold: 2
    response_timeout: 2000
</code></pre>

<p>Now when I execute this I have the following response :</p>

<pre><code>Bad response statusCode [422]. Status [422 status code 422]. Body: [code=NotUnique, fieldName=name, baseType=error] from [http://myrancher_server:8080/v2-beta/projects/1a21/stacks]
</code></pre>

<p>Obviously I can't edit an existing stack with a service that already exsit. Do you know if it's best practice do to this like that ? I checked man, and I only see the "create" action on "rancher stack", so I'm wondering if we can update ?</p>

<p>My rancher server is v1.5.10 and all my rancher agents and Kubernetes drivers are up-to-date.</p>

<p>Thanks a lot for your help fellows :)</p>

<p>Ok, just for the information, I found that this is possible via the Rest API of Rancher.</p>

<p>Check the following link : <a href="http://docs.rancher.com/rancher/v1.2/en/api/v2-beta/api-resources/service/" rel="nofollow noreferrer">http://docs.rancher.com/rancher/v1.2/en/api/v2-beta/api-resources/service/</a></p>

<p>I didn't found that at first 'cause the Googling I've done around was all about rancher cli at first. But as it's still beta, we can't do the same stuff as via the rest API.</p>

<p>Basically, just send an update resource query :</p>

<p>PUT rancherserver/v2-beta/projects/1a12/services/</p>

<pre><code>{
    "description": "Loadbalancer for our test env",
    "lbConfig": {
        "portRules": [
            {
                "hostname": "",
                "protocol": "http",
                "source_port": "80",
                "targetPort": "4200",
                "path": "/"
            }
        ]
    },
    "name": "kubernetes-ingress-lbs"
}
</code></pre>
