Merge pull request #3954 from Shopify/lb-configmap
Fix load-balance configmap value
This commit is contained in:
commit
39ecab8d5a
4 changed files with 89 additions and 21 deletions
|
@ -585,12 +585,13 @@ Sets the algorithm to use for load balancing.
|
||||||
The value can either be:
|
The value can either be:
|
||||||
|
|
||||||
- round_robin: to use the default round robin loadbalancer
|
- round_robin: to use the default round robin loadbalancer
|
||||||
- least_conn: to use the least connected method (_note_ that this is available only in non-dynamic mode: `--enable-dynamic-configuration=false`)
|
|
||||||
- ip_hash: to use a hash of the server for routing (_note_ that this is available only in non-dynamic mode: `--enable-dynamic-configuration=false`, but alternatively you can consider using `nginx.ingress.kubernetes.io/upstream-hash-by`)
|
|
||||||
- ewma: to use the Peak EWMA method for routing ([implementation](https://github.com/kubernetes/ingress-nginx/blob/master/rootfs/etc/nginx/lua/balancer/ewma.lua))
|
- ewma: to use the Peak EWMA method for routing ([implementation](https://github.com/kubernetes/ingress-nginx/blob/master/rootfs/etc/nginx/lua/balancer/ewma.lua))
|
||||||
|
|
||||||
The default is `round_robin`.
|
The default is `round_robin`.
|
||||||
|
|
||||||
|
- To load balance using consistent hashing of IP or other variables, consider the `nginx.ingress.kubernetes.io/upstream-hash-by` annotation.
|
||||||
|
- To load balance using session cookies, consider the `nginx.ingress.kubernetes.io/affinity` annotation.
|
||||||
|
|
||||||
_References:_
|
_References:_
|
||||||
[http://nginx.org/en/docs/http/load_balancing.html](http://nginx.org/en/docs/http/load_balancing.html)
|
[http://nginx.org/en/docs/http/load_balancing.html](http://nginx.org/en/docs/http/load_balancing.html)
|
||||||
|
|
||||||
|
|
|
@ -619,18 +619,16 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
||||||
|
|
||||||
klog.V(3).Infof("Creating upstream %q", defBackend)
|
klog.V(3).Infof("Creating upstream %q", defBackend)
|
||||||
upstreams[defBackend] = newUpstream(defBackend)
|
upstreams[defBackend] = newUpstream(defBackend)
|
||||||
if upstreams[defBackend].SecureCACert.Secret == "" {
|
|
||||||
upstreams[defBackend].SecureCACert = anns.SecureUpstream.CACert
|
|
||||||
}
|
|
||||||
|
|
||||||
if upstreams[defBackend].UpstreamHashBy.UpstreamHashBy == "" {
|
upstreams[defBackend].SecureCACert = anns.SecureUpstream.CACert
|
||||||
|
|
||||||
upstreams[defBackend].UpstreamHashBy.UpstreamHashBy = anns.UpstreamHashBy.UpstreamHashBy
|
upstreams[defBackend].UpstreamHashBy.UpstreamHashBy = anns.UpstreamHashBy.UpstreamHashBy
|
||||||
upstreams[defBackend].UpstreamHashBy.UpstreamHashBySubset = anns.UpstreamHashBy.UpstreamHashBySubset
|
upstreams[defBackend].UpstreamHashBy.UpstreamHashBySubset = anns.UpstreamHashBy.UpstreamHashBySubset
|
||||||
upstreams[defBackend].UpstreamHashBy.UpstreamHashBySubsetSize = anns.UpstreamHashBy.UpstreamHashBySubsetSize
|
upstreams[defBackend].UpstreamHashBy.UpstreamHashBySubsetSize = anns.UpstreamHashBy.UpstreamHashBySubsetSize
|
||||||
}
|
|
||||||
|
|
||||||
if upstreams[defBackend].LoadBalancing == "" {
|
|
||||||
upstreams[defBackend].LoadBalancing = anns.LoadBalancing
|
upstreams[defBackend].LoadBalancing = anns.LoadBalancing
|
||||||
|
if upstreams[defBackend].LoadBalancing == "" {
|
||||||
|
upstreams[defBackend].LoadBalancing = n.store.GetBackendConfiguration().LoadBalancing
|
||||||
}
|
}
|
||||||
|
|
||||||
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, ing.Spec.Backend.ServiceName)
|
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, ing.Spec.Backend.ServiceName)
|
||||||
|
@ -687,18 +685,15 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
||||||
upstreams[name] = newUpstream(name)
|
upstreams[name] = newUpstream(name)
|
||||||
upstreams[name].Port = path.Backend.ServicePort
|
upstreams[name].Port = path.Backend.ServicePort
|
||||||
|
|
||||||
if upstreams[name].SecureCACert.Secret == "" {
|
|
||||||
upstreams[name].SecureCACert = anns.SecureUpstream.CACert
|
upstreams[name].SecureCACert = anns.SecureUpstream.CACert
|
||||||
}
|
|
||||||
|
|
||||||
if upstreams[name].UpstreamHashBy.UpstreamHashBy == "" {
|
|
||||||
upstreams[name].UpstreamHashBy.UpstreamHashBy = anns.UpstreamHashBy.UpstreamHashBy
|
upstreams[name].UpstreamHashBy.UpstreamHashBy = anns.UpstreamHashBy.UpstreamHashBy
|
||||||
upstreams[name].UpstreamHashBy.UpstreamHashBySubset = anns.UpstreamHashBy.UpstreamHashBySubset
|
upstreams[name].UpstreamHashBy.UpstreamHashBySubset = anns.UpstreamHashBy.UpstreamHashBySubset
|
||||||
upstreams[name].UpstreamHashBy.UpstreamHashBySubsetSize = anns.UpstreamHashBy.UpstreamHashBySubsetSize
|
upstreams[name].UpstreamHashBy.UpstreamHashBySubsetSize = anns.UpstreamHashBy.UpstreamHashBySubsetSize
|
||||||
}
|
|
||||||
|
|
||||||
if upstreams[name].LoadBalancing == "" {
|
|
||||||
upstreams[name].LoadBalancing = anns.LoadBalancing
|
upstreams[name].LoadBalancing = anns.LoadBalancing
|
||||||
|
if upstreams[name].LoadBalancing == "" {
|
||||||
|
upstreams[name].LoadBalancing = n.store.GetBackendConfiguration().LoadBalancing
|
||||||
}
|
}
|
||||||
|
|
||||||
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, path.Backend.ServiceName)
|
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, path.Backend.ServiceName)
|
||||||
|
|
72
test/e2e/loadbalance/configmap.go
Normal file
72
test/e2e/loadbalance/configmap.go
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package loadbalance
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
waitForLuaSync = 5 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = framework.IngressNginxDescribe("Load Balance - Configmap value", func() {
|
||||||
|
f := framework.NewDefaultFramework("lb-configmap")
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
f.NewEchoDeploymentWithReplicas(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
AfterEach(func() {
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should apply the configmap load-balance setting", func() {
|
||||||
|
host := "load-balance.com"
|
||||||
|
|
||||||
|
f.UpdateNginxConfigMapData("load-balance", "ewma")
|
||||||
|
|
||||||
|
f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, "http-svc", 80, nil))
|
||||||
|
f.WaitForNginxServer(host,
|
||||||
|
func(server string) bool {
|
||||||
|
return strings.Contains(server, "server_name load-balance.com")
|
||||||
|
})
|
||||||
|
time.Sleep(waitForLuaSync)
|
||||||
|
|
||||||
|
getCmd := "/dbg backends all"
|
||||||
|
output, err := f.ExecIngressPod(getCmd)
|
||||||
|
Expect(err).Should(BeNil())
|
||||||
|
|
||||||
|
var backends []map[string]interface{}
|
||||||
|
unmarshalErr := json.Unmarshal([]byte(output), &backends)
|
||||||
|
Expect(unmarshalErr).Should(BeNil())
|
||||||
|
|
||||||
|
for _, backend := range backends {
|
||||||
|
if backend["name"].(string) != "upstream-default-backend" {
|
||||||
|
lb, ok := backend["load-balance"].(string)
|
||||||
|
Expect(ok).Should(Equal(true))
|
||||||
|
Expect(lb).Should(Equal("ewma"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package settings
|
package loadbalance
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
Loading…
Reference in a new issue