Reputation: 23
I have a requirement to convert a multipod setup to a single pod with multiple container. I had pod x running x microservice and pod y running y microservice with below rest endpoint.
http://x:8080/{context path-x}/endpoint
http://y:8080/{context path-y}/endpoint
I want to have pod z with x and y microservice with container x exposed on 8080 port and y on 8081 within same pod. I am able to achieve these with multi-container pod.
My problem is now the URL are changed
http://z:8080/{context path-x}/endpoint
http://z:8081/{context path-y}/endpoint
I am looking for way in which I can hit endpoints without the change is URL or minimum hit with below URLs
http://x:8080/{context path-x}/endpoint
http://y:8081/{context path-y}/endpoint
My real project requirement has 5 container on single pods and has 100s of endpoints exposed
How can I achieve this?
Upvotes: 0
Views: 1747
Reputation: 23
Here's how I addressed my problem:
Application Deployment File (x and y containers on deployment z)
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: z
spec:
replicas: 1
progressDeadlineSeconds: 600
selector:
matchLabels:
component: z
template:
metadata:
annotations:
version: v1.0
labels:
component: z
occloud.oracle.com/open-network-policy: allow
name: z
spec:
containers:
- name: x
image:x:dev
ports:
- containerPort: 8080
- name: y
image: y:dev
ports:
- containerPort: 8081
---
kind: Service
apiVersion: v1
metadata:
name: x
annotations:
version: v1.0
spec:
selector:
component: z
ports:
- name: x
port: 8080
targetPort: 8080
type: ClusterIP
---
kind: Service
apiVersion: v1
metadata:
name: y
annotations:
version: v1.0
spec:
selector:
component: z
ports:
- name: y
port: 8080
targetPort: 8081
type: ClusterIP
http://x:8080/{context path-x}/endpoint http://y:8080/{context path-y}/endpoint
Upvotes: 2
Reputation: 5892
K8s services are the way to expose your application. Since you have two applications and want to run them as two different containers inside a single Pod and you want minimum changes in your application API URL, then simply create create two different Services having your trageted ports. Thus you need 0 changes in your application's APP url.
In K8s cluster, you can use simply the name of the service name as the host name from the same namespace. You can see FQDN (fully qualified domain name) convention for a service.
Hence, you can create two Services with name x
and y
, where x
have the port 8080 and y
have the port 8081. Thus you can use the same urls as before.
NOTE: There may exist different ways to achieve one's goal(s) but may arise different issues.
Upvotes: 1