Reputation: 869
In Kubernetes, one communicates with a specific service X
by doing http requests to http://X:9999
. X
here is the application name. I wonder, can one add multiple names, or alias, to which it will point to http://X:9999
? I.e can I forward/point http://Y:9999
to http://X:9999
?
Upvotes: 5
Views: 4007
Reputation: 674
Yes you can have multiple hostnames point to the same Pod(s).
You can achieve this by creating multiple Services with the same label selectors.
A service creates endpoints to Pod IPs based on label selectors.
Services will match their selectors against Pod labels.
If multiple Services (with different names) have the same label selectors, they will create multiple endpoints to the same Pods.
First service:
apiVersion: v1
kind: Service
metadata:
name: nginx1
namespace: nginx
spec:
selector:
app: nginx
...
Second service:
apiVersion: v1
kind: Service
metadata:
name: nginx2
namespace: nginx
spec:
selector:
app: nginx
...
Each Service will create an endpoint pointing to any Pods with the label app: nginx
.
So you could hit the same Pods using nginx2:<port>
and nginx1:<port>
.
Upvotes: 9