How to deploy a Hybrid Application with Legacy Backend on a Kubernetes Cluster

In an enterprise, it’s very common to have a hybrid application topology consisting of a cloud-native frontend and a legacy backend eg. database cluster. If you are using Kubernetes cluster for your cloud-native applications, then there is an easy way – or let’s say a Kubernetes-native way, to integrate your cloud-native applications with legacy backends.

Normally a Kubernetes service provides an abstraction of the Pods (endpoints) deployed in a cluster. Additionally Kubernetes also allows creating services to abstract backends (endpoints) that are outside of Kubernetes cluster.
Let’s say we have an application deployed via Kubernetes which needs to access a legacy database backend at IP address and port 1040.

First, we need to create a Kubernetes endpoint to map the legacy database backend and then create a service mapping the endpoint.

The following shows the specification for the endpoint describing the database backend.

# cat legacy-ep.yaml
kind: Endpoints
 apiVersion: v1
   name: db-cluster
   - addresses:
       - ip:
       - port: 1040

The following command will create an endpoint to map the legacy database backend.

# kubectl create -f legacy-ep.yaml

The following shows the service specification for exposing the above endpoint to any Kubernetes Pod.

# cat legacy-service.yaml
apiVersion: v1
 kind: Service
     name: db-cluster
   name: db-cluster
     # the port that this service should serve on
     - port: 1040
   externalIPs: []

The following command will create a Kubernetes service and expose the service at thereby enabling access from any Kubernetes Pod.

# kubectl create -f legacy-service.yaml

Once the Kubernetes service for the legacy database is created any Kubernetes Pod (or service) should be able to access it by leveraging Kubernetes service discovery mechanisms viz. environment variables or DNS.

Pradipta Kumar Banerjee

I'm a Cloud and Linux/ OpenSource enthusiast, with 16 years of industry experience at IBM. You can find more details about me here - Linkedin

You may also like...