Since our backend API is a stateless application, we don't need to deploy a StatefulSet like we did with Elasticsearch. We can simply use a simpler Kubernetes Object that we've encountered already—Deployment.
Create a new manifest at manifests/backend/deployment.yaml with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
labels:
app: backend
spec:
selector:
matchLabels:
app: backend
replicas: 3
template:
metadata:
labels:
app: backend
spec:
containers:
- name: backend
image: d4nyll/hobnob:0.1.0
ports:
- containerPort: 8080
name: api
- containerPort: 8100
name: docs
env:
- name: ELASTICSEARCH_HOSTNAME
value: "http://elasticsearch"
- name: ELASTICSEARCH_PORT
value: "9200"
...
For the .spec.template.spec.containers[].env field, add in the same environment variables that we passed in to our Docker image from the previous chapter (the ones we stored inside our .env file). However, for the ELASTICSEARCH_PORT variable, hard-code it to "9200", and for ELASTICSEARCH_HOSTNAME, use the value "http://elasticsearch".