# Rancher CLI update loadbalancer

**URL:** <https://forums.suse.com/t/rancher-cli-update-loadbalancer/6581>\
**Category:** Rancher 1.x\
**Created:** [June 8, 2017, 4:12pm UTC](https://forums.suse.com/t/rancher-cli-update-loadbalancer/6581 "2017-06-08T16:12:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vespira](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vespira/32/2532_2.png) [@Vespira](https://forums.suse.com/u/Vespira)\
**Post date:** [June 8, 2017, 4:12pm UTC](https://forums.suse.com/t/rancher-cli-update-loadbalancer/6581/1 "2017-06-08T16:12:40Z")

</div>

Hi there,

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.

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.

At the moment, I just try to run this command :

`rancher --url http://myrancher_server:8080 --access-key <key> --secret-key <secret> --env dev-test stack create kubernetes-ingress-lbs -r loadbalancer-rancher-service.yml`

My docker-compose.yml file is like the following :

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

My rancher compose file is like this:

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

Now when I execute this I have the following response :

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

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 ?

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

Thanks a lot for your help fellows 🙂

EDIT : I know it’s a very specific question, and I will also post it on Stackoverflow to increase my chances that someone who know well Kubernetes/Rancher could help me. Sorry for replica.

---

<div class="post-metadata">

**Author:** ![Vespira](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vespira/32/2532_2.png) [@Vespira](https://forums.suse.com/u/Vespira)\
**Post date:** [June 12, 2017, 7:38am UTC](https://forums.suse.com/t/rancher-cli-update-loadbalancer/6581/2 "2017-06-12T07:38:16Z")

</div>

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

Check the following link : [http://docs.rancher.com/rancher/v1.2/en/api/v2-beta/api-resources/service/](http://docs.rancher.com/rancher/v1.2/en/api/v2-beta/api-resources/service/)

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.

Basically, just send an update resource query :

**PUT rancherserver/v2-beta/projects/1a12/services/\<id\_of\_your\_service\>**

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