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
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.
The Google Kubernetes Engine (GKE) MCS feature extends the reach of the Kubernetes Service beyond the cluster boundary and lets you discover and invoke Services across multiple GKE clusters.
Use Multiple Service Accounts To use a non-default service account, set the spec. serviceAccountName field of a pod to the name of the service account you wish to use. The service account has to exist at the time the pod is created, or it will be rejected.
I understand that containers within a Pod are actually under the same network namespace, which enables accessing another container in the Pod with localhost or 127.0. 0.1 . It means containers can't use the same port.
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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With