Enable loadbalancer.sticky for ECS
This commit is contained in:
parent
8235cd3645
commit
086a85d2f0
3 changed files with 61 additions and 19 deletions
|
@ -1777,6 +1777,8 @@ Labels can be used on task containers to override default behaviour:
|
||||||
- `traefik.protocol=https`: override the default `http` protocol
|
- `traefik.protocol=https`: override the default `http` protocol
|
||||||
- `traefik.weight=10`: assign this weight to the container
|
- `traefik.weight=10`: assign this weight to the container
|
||||||
- `traefik.enable=false`: disable this container in Træfik
|
- `traefik.enable=false`: disable this container in Træfik
|
||||||
|
- `traefik.backend.loadbalancer.method=drr`: override the default `wrr` load balancer algorithm
|
||||||
|
- `traefik.backend.loadbalancer.sticky=true`: enable backend sticky sessions
|
||||||
- `traefik.frontend.rule=Host:test.traefik.io`: override the default frontend rule (Default: `Host:{containerName}.{domain}`).
|
- `traefik.frontend.rule=Host:test.traefik.io`: override the default frontend rule (Default: `Host:{containerName}.{domain}`).
|
||||||
- `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend.
|
- `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend.
|
||||||
- `traefik.frontend.priority=10`: override default frontend priority
|
- `traefik.frontend.priority=10`: override default frontend priority
|
||||||
|
|
|
@ -182,6 +182,8 @@ func (p *Provider) loadECSConfig(ctx context.Context, client *awsClient) (*types
|
||||||
var ecsFuncMap = template.FuncMap{
|
var ecsFuncMap = template.FuncMap{
|
||||||
"filterFrontends": p.filterFrontends,
|
"filterFrontends": p.filterFrontends,
|
||||||
"getFrontendRule": p.getFrontendRule,
|
"getFrontendRule": p.getFrontendRule,
|
||||||
|
"getLoadBalancerSticky": p.getLoadBalancerSticky,
|
||||||
|
"getLoadBalancerMethod": p.getLoadBalancerMethod,
|
||||||
}
|
}
|
||||||
|
|
||||||
instances, err := p.listInstances(ctx, client)
|
instances, err := p.listInstances(ctx, client)
|
||||||
|
@ -191,10 +193,20 @@ func (p *Provider) loadECSConfig(ctx context.Context, client *awsClient) (*types
|
||||||
|
|
||||||
instances = fun.Filter(p.filterInstance, instances).([]ecsInstance)
|
instances = fun.Filter(p.filterInstance, instances).([]ecsInstance)
|
||||||
|
|
||||||
|
services := make(map[string][]ecsInstance)
|
||||||
|
|
||||||
|
for _, instance := range instances {
|
||||||
|
if serviceInstances, ok := services[instance.Name]; ok {
|
||||||
|
services[instance.Name] = append(serviceInstances, instance)
|
||||||
|
} else {
|
||||||
|
services[instance.Name] = []ecsInstance{instance}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
|
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
|
||||||
Instances []ecsInstance
|
Services map[string][]ecsInstance
|
||||||
}{
|
}{
|
||||||
instances,
|
services,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,6 +469,26 @@ func (p *Provider) getFrontendRule(i ecsInstance) string {
|
||||||
return "Host:" + strings.ToLower(strings.Replace(i.Name, "_", "-", -1)) + "." + p.Domain
|
return "Host:" + strings.ToLower(strings.Replace(i.Name, "_", "-", -1)) + "." + p.Domain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Provider) getLoadBalancerSticky(instances []ecsInstance) string {
|
||||||
|
if len(instances) > 0 {
|
||||||
|
label := instances[0].label(types.LabelBackendLoadbalancerSticky)
|
||||||
|
if label != "" {
|
||||||
|
return label
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) getLoadBalancerMethod(instances []ecsInstance) string {
|
||||||
|
if len(instances) > 0 {
|
||||||
|
label := instances[0].label(types.LabelBackendLoadbalancerMethod)
|
||||||
|
if label != "" {
|
||||||
|
return label
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "wrr"
|
||||||
|
}
|
||||||
|
|
||||||
// Provider expects no more than 100 parameters be passed to a DescribeTask call; thus, pack
|
// Provider expects no more than 100 parameters be passed to a DescribeTask call; thus, pack
|
||||||
// each string into an array capped at 100 elements
|
// each string into an array capped at 100 elements
|
||||||
func (p *Provider) chunkedTaskArns(tasks []*string) [][]*string {
|
func (p *Provider) chunkedTaskArns(tasks []*string) [][]*string {
|
||||||
|
|
|
@ -1,17 +1,25 @@
|
||||||
[backends]{{range .Instances}}
|
[backends]{{range $serviceName, $instances := .Services}}
|
||||||
[backends.backend-{{ .Name }}.servers.server-{{ .Name }}{{ .ID }}]
|
[backends.backend-{{ $serviceName }}.loadbalancer]
|
||||||
url = "{{ .Protocol }}://{{ .Host }}:{{ .Port }}"
|
sticky = {{ getLoadBalancerSticky $instances}}
|
||||||
weight = {{ .Weight }}
|
method = "{{ getLoadBalancerMethod $instances}}"
|
||||||
|
|
||||||
|
{{range $index, $i := $instances}}
|
||||||
|
[backends.backend-{{ $i.Name }}.servers.server-{{ $i.Name }}{{ $i.ID }}]
|
||||||
|
url = "{{ $i.Protocol }}://{{ $i.Host }}:{{ $i.Port }}"
|
||||||
|
weight = {{ $i.Weight }}
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
[frontends]{{range filterFrontends .Instances}}
|
[frontends]{{range $serviceName, $instances := .Services}}
|
||||||
[frontends.frontend-{{ .Name }}]
|
{{range filterFrontends $instances}}
|
||||||
backend = "backend-{{ .Name }}"
|
[frontends.frontend-{{ $serviceName }}]
|
||||||
|
backend = "backend-{{ $serviceName }}"
|
||||||
passHostHeader = {{ .PassHostHeader }}
|
passHostHeader = {{ .PassHostHeader }}
|
||||||
priority = {{ .Priority }}
|
priority = {{ .Priority }}
|
||||||
entryPoints = [{{range .EntryPoints }}
|
entryPoints = [{{range .EntryPoints }}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
[frontends.frontend-{{ .Name }}.routes.route-frontend-{{ .Name }}]
|
[frontends.frontend-{{ $serviceName }}.routes.route-frontend-{{ $serviceName }}]
|
||||||
rule = "{{getFrontendRule .}}"
|
rule = "{{getFrontendRule .}}"
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
Loading…
Reference in a new issue