Alias name for a service to hide the deployment details

Hi,

what would be the best way to define an alias name for a service to hide the deployment details e.g. the namespace in which a service is running inside of k8.
Example:

  1. deployment of service sample-service in namespace sample-ns1.
  2. deployment of service sample-service in namespace sample-ns2.

Goal: have an alias name e.g. sample-service.cluster.local that can be used by consuming apps that hide deployment details.

My first thought was something like this:

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: sample-service
spec:
  hosts:
  - "sample-service.cluster.local"  
  location: MESH_INTERNAL
  ports:
  - number: 443
    name: grpc
    protocol: GRPC
  resolution: NONE
  
  
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: sample-service
spec:
  hosts:
  - "sample-service.cluster.local"  
  route:
   - destination:
       host: sample-service.sample-ns1.svc.cluster.local

Hi,

the approach with the service entry didn’t work for me. After some tries I came up with the following solution:

  1. I created a new namespace that locates all alias service names: namespacece alias
  2. Create a Service without selectors and a VirtualService that routes traffic from the alias service to the real service.
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: httpbin
    spec:
      hosts:
        - httpbin.alias.svc.cluster.local
      http:
        - route:
            - destination:
                host: httpbin.playground.svc.cluster.local
                port:
                  number: 8000
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: httpbin
    spec:
      ports:
        - name: http
          port: 8000
    

Any comments or feedback on that solution?