Skip to main content

Consuming external databases

When running applications in Kubernetes their databases usually run outside the Kubernetes cluster. In these scenarios the database commonly resides in different subnets or VPCs. Kubernetes worker nodes can route to the subnet or VPC but developers usually do not have direct access or require a VPN connection:

Consume can support external databases (or any external service) by applying a Kubernetes service manifest. Apply the following manifests to create an external service using Postgres as an example:

Use the database DNS in externalName. For example in AWS Aurora use the cluster endpoint or reader endpoint.

apiVersion: v1
kind: Service
metadata:
annotations:
name: postgres
namespace: example
spec:
externalName: <aurora cluster endpoint>
ports:
- port: 5432
protocol: TCP
targetPort: 5432
type: ExternalName
note

For Codezero to consume external services a service manifest must include ports.

You can now consume the above defined service example/postgres and access the Postgres database locally.