I want to deploy many Pods in Google Kubernetes Engine and then establish a TCP connection to each specific Pod by Subdomain like pod-name-or-label.mydomain.com or path routing like protocol://mydomain.com:7878/pod-name-or-label.
I have looked in different directions like Istio or nginx-ingress, but that seems to me to be too complicated.
Is not there a simple solution for that?
Now i have that solution with istio installed on the cluster:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: echo-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "dev.sample.com"
With that gateway i can apply that Deployment, Service, VirtualService
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-echo-1000-deployment
labels:
echoservice: echo-1000
spec:
replicas: 1
selector:
matchLabels:
echoservice: echo-1000
template:
metadata:
labels:
echoservice: echo-1000
spec:
containers:
- image: gcr.io/google-containers/echoserver:1.10
imagePullPolicy: IfNotPresent
name: my-echo-run-container
ports:
- containerPort: 8080
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: my-echo-1000-service
labels:
echoservice: echo-1000
spec:
ports:
- port: 8080
name: http
selector:
echoservice: echo-1000
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: my-echo-1000-vservice
spec:
hosts:
- "dev.sample.com"
gateways:
- echo-gateway
http:
- match:
- uri:
exact: /echo-1000
route:
- destination:
host: my-echo-1000-service
port:
number: 8080
Get the LoadbalancerIP from istio-ingressgateway and make an entry in /etc/hosts for dev.sample.com
Now i can get the echoserver in specific Pod with http://dev.sample.com/echo-1000
Is that a good solution or is there a better one?
For Istio, You can use VirtualService to control the routing rules to the target subset with defining by DestinationRules.
The DestinationRule will route to the target Pods by the specified label pods.
The request flow will like to:
+--------------------+
| |
| Istio Gateway |
| |
| |
+---------+----------+
|traffic incoming
|
+---------v----------+
| |
| VirtualService |
| |
| |
+---------+----------+
|route to subset by the routing rules
v
+--------------------+
| |
| DestinationRules |
| |
| |
+---------+----------+
|route traffic to target pods
v
+--------------------+
| |
| |
| Pods |
| |
+--------------------+
so as @ericstaples said you should create different Deployments with different pod labels to achieve separating traffic to the target pods, Example:
s1
subsets1
route to the target podsalso for expose Gateway, you can use ClusterIP or NodePort like ** Kubernetes** other service did, see more of Istio Traffic.
There are some references maybe it's helpful:
https://istio.io/docs/concepts/traffic-management/
https://istio.io/docs/tasks/traffic-management/request-routing/