Creating a backend Service

Next, we should deploy a Service that sits in front of the backend Pods. As a recap, every backend Pod inside the backend Deployment will have its own IP address, but these addresses can change as Pods are destroyed and created. Having a Service that sits in front of these Pods allow other parts of the application to access these backend Pods in a consistent manner.

Create a new manifest file at ./manifests/backend/service.yaml with the following content:

apiVersion: v1kind: Servicemetadata:  name: backend  labels:    app: backendspec:  selector:    app: backend  ports:
  - port: 8080    name: api  - port: 8100    name: docs

And deploy it using kubectl apply:

$ kubectl apply -f ./manifests/backend/service.yamlservice "backend" created ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.