What is the best practice for service discovery on the application layer in Kubernetes?

5/25/2019

I have 3 applications.

A Gateway, ServiceA & ServiceB.

Each application sits in its own namespace. Whenever there is a push to the CI/CD server on one of the all the 3. All get deployed based on the branch name.

Example:

  1. Create a new branch (feature-1) in ServiceA repo.
  2. Make and commit some changes
  3. The build server builds and deploys the feature-1 branch with a unique service name to the Kubernetes cluster.
  4. The build server looks at ServiceB and Gateway for branches feature-1 if not found defaults to develop. For the gateway it creates a feature-1 from develop and deploys that one.
  5. The gateway then needs to know the DNS URL of the ServiceA from feature-1 in order to be able to call it.

So my question is how to do service discovery on the application lvl using kubernetes?

-- Marti Markov
istio
kubernetes

1 Answer

6/19/2019

I think there are two ways to achieve that.

1) Query all services from Kubernetes master, with the API equivalent of kubectl get services --all-namespaces. Then you will ned to configure some logic for choosing the right service. For this you can use for example Selector, targetPort or specify ClusterIP. More details can be find in documentation.

2) Put application built from each branch in a new namespace, and let them route within the namespace to their usual names, without requiring any application changes. More information in documentation.

-- PjoterS
Source: StackOverflow