diff --git a/apiserver/cmd/server/server.go b/apiserver/cmd/server/server.go index f8d81daf..da0a3541 100644 --- a/apiserver/cmd/server/server.go +++ b/apiserver/cmd/server/server.go @@ -1608,15 +1608,14 @@ func (s *Server) createKubernetesService(userId string, stack *api.Stack, spec * func (s *Server) createIngressRule(userId string, svc *k8api.Service, stack *api.Stack) error { - host := fmt.Sprintf("%s.%s", svc.Name, s.domain) - _, err := s.kube.CreateIngress(userId, host, svc.Name, - int(svc.Spec.Ports[0].Port), stack.Secure) + _, err := s.kube.CreateIngress(userId, s.domain, svc.Name, + svc.Spec.Ports, stack.Secure) if err != nil { glog.Errorf("Error creating ingress for %s\n", svc.Name) glog.Error(err) return err } - glog.V(4).Infof("Started ingress %s for service %s (secure=%t)\n", host, svc.Name, stack.Secure) + glog.V(4).Infof("Started ingress for service %s (secure=%t)\n", svc.Name, stack.Secure) return nil } @@ -2225,7 +2224,7 @@ func (s *Server) getStackWithStatus(userId string, sid string) (*api.Stack, erro endpoint.Protocol = specPort.Protocol endpoint.NodePort = k8port.NodePort if s.useLoadBalancer() && spec.Access == api.AccessExternal { - endpoint.Host = fmt.Sprintf("%s.%s", stackService.Id, s.domain) + endpoint.Host = fmt.Sprintf("%s-%d.%s", stackService.Id, specPort.Port, s.domain) endpoint.Path = specPort.ContextPath endpoint.URL = endpoint.Host + specPort.ContextPath } diff --git a/apiserver/pkg/kube/kube.go b/apiserver/pkg/kube/kube.go index 5711c61d..5f45b1a0 100644 --- a/apiserver/pkg/kube/kube.go +++ b/apiserver/pkg/kube/kube.go @@ -1156,7 +1156,7 @@ func (k *KubeHelper) Exec(pid string, pod string, container string, kube *KubeHe return &wsHandler } -func (k *KubeHelper) CreateIngress(pid string, host string, service string, port int, basicAuth bool) (*extensions.Ingress, error) { +func (k *KubeHelper) CreateIngress(pid string, domain string, service string, ports []api.ServicePort, basicAuth bool) (*extensions.Ingress, error) { name := service + "-ingress" update := true @@ -1170,27 +1170,31 @@ func (k *KubeHelper) CreateIngress(pid string, host string, service string, port Name: name, Namespace: pid, }, - Spec: extensions.IngressSpec{ - Rules: []extensions.IngressRule{ - extensions.IngressRule{ - Host: host, - IngressRuleValue: extensions.IngressRuleValue{ - HTTP: &extensions.HTTPIngressRuleValue{ - Paths: []extensions.HTTPIngressPath{ - extensions.HTTPIngressPath{ - Path: "/", - Backend: extensions.IngressBackend{ - ServiceName: service, - ServicePort: intstr.FromInt(port), - }, - }, - }, + } + } + + hosts := []string{} + for _, port := range ports { + + host := fmt.Sprintf("%s-%d.%s", service, port.Port, domain) + rule := extensions.IngressRule{ + Host: host, + IngressRuleValue: extensions.IngressRuleValue{ + HTTP: &extensions.HTTPIngressRuleValue{ + Paths: []extensions.HTTPIngressPath{ + extensions.HTTPIngressPath{ + Path: "/", + Backend: extensions.IngressBackend{ + ServiceName: service, + ServicePort: intstr.FromInt(int(port.Port)), }, }, }, }, }, } + ingress.Spec.Rules = append(ingress.Spec.Rules, rule) + hosts = append(hosts, host) } annotations := map[string]string{} @@ -1209,7 +1213,7 @@ func (k *KubeHelper) CreateIngress(pid string, host string, service string, port if secret != nil { ingress.Spec.TLS = []extensions.IngressTLS{ extensions.IngressTLS{ - Hosts: []string{host}, + Hosts: hosts, SecretName: tlsSecretName, }, }