12
votes

Can I run multiple services on port 80 in Kubernetes on Google Container Engine? Each service has a dedicated external IP Address, so theoretically the router should be able to route to each service based off it's IP Address.

So far I have created pods for "frontend-1" and "frontend-2" on Container Engine. I tried to create seperate services for them both running on Port 80 with unique External IPs, but it didn't work. Is there another way to accomplish this in Kubernetes without using a custom routing service?

service-1.yaml:

id: service-1
port: 80
containerPort: 8080
selector:
  name: frontend-1
createExternalLoadBalancer: true

service-2.yaml:

id: service-2
port: 80
containerPort: 8081
selector:
  name: frontend-2
createExternalLoadBalancer: true
3
This question was asked when Kubernetes was 0.4, much has changed since then. It's not relavent in the Kubernetes 1.x realm, I think it should be deleted.Caleb

3 Answers

15
votes

Kubernetes 1.1 has an Ingress type, which allows you to route different dns names/ips to different services. From github

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - backend:
          serviceName: s1
          servicePort: 80
  - host: bar.foo.com
    http:
      paths:
      - backend:
          serviceName: s2
          servicePort: 80
5
votes

Yes,multiple services can have same ports as it doesn't matter because each service gets it own IP address. In google kubernetes console run

kubectl get svc

This will list out all services and EXTERNAL IP can be checked by copying it in browser with the respective port number.

3
votes

As of today GKE relies on Kubernetes 0.4.x which allocates ports on every nodes for each services. With this configuration you can't have multiple services listening on port 80.

Kubernetes 0.5.x introduced a new networking model, which map an separate IP for each services. So once GKE upgrade you will be able to have multiple services exposed on different IP/ports.