Yes, you can do it with ingress, here are both solutions:
for my-domain.com/xxx
in ingress service you do something like:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
labels:
name: ingress-service
namespace: my-namespace
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: my-domain.com
http:
paths:
- path: /xx/(.*)
pathType: Prefix
backend:
service:
name: xx
port:
number: 80
- path: /yy/(.*)
pathType: Prefix
backend:
service:
name: yy
port:
number: 80
so everything that is pointed to my-domain.com/xx
will be pointed out to xx
service and it will remove /xx/
from the path, ex:
If you make a request to my-domain.com/xx/values
, the request will be forwarded as my-domain.com/values
to the xx
service.
Learn more about it at https://kubernetes.io/docs/concepts/services-networking/ingress/#simple-fanout
As well as you can see here how the paths work: https://kubernetes.io/docs/concepts/services-networking/ingress/#examples
The other solution for xx.my-domain.com
you can do it like this:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
labels:
name: ingress-service
namespace: my-namespace
spec:
rules:
- host: xx.my-domain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: xx
port:
number: 80
- host: yy.my-domain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: yy
port:
number: 80
You can learn more about it at https://kubernetes.io/docs/concepts/services-networking/ingress/#hostname-wildcards