Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Multiple Services on Port 80 in same Kubernetes Cluster on Google Container Engine

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
like image 336
Caleb Avatar asked Dec 04 '14 16:12

Caleb


People also ask

Can 2 services use the same port Kubernetes?

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.

Which service would you use to manage multiple Kubernetes cluster through Google cloud?

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.

Can a Kubernetes pod have multiple service accounts?

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.

Can two containers in a pod use the same port?

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.


3 Answers

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
like image 191
Reese Avatar answered Oct 17 '22 04:10

Reese


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.

like image 7
shubham_asati Avatar answered Oct 17 '22 04:10

shubham_asati


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.

like image 5
proppy Avatar answered Oct 17 '22 02:10

proppy