Search⌘ K

Creating the Split API Pods

Explore how to create split backend API Pods in Kubernetes using ReplicaSets and Services. Learn to set replica counts, use labels for Pod distinction, configure readinessProbes for request routing, and expose APIs via NodePort Services. Understand how these components ensure stable communication and accessibility, and practice deploying and deleting these resources to manage your cluster effectively.

Looking into the definition

Let’s see the definition of the backend API go-demo-2-api-rs.yml.

YAML
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: go-demo-2-api
spec:
replicas: 3
selector:
matchLabels:
type: api
service: go-demo-2
template:
metadata:
labels:
type: api
service: go-demo-2
language: go
spec:
containers:
- name: api
image: vfarcic/go-demo-2
env:
- name: DB
value: go-demo-2-db
readinessProbe:
httpGet:
path: /demo/hello
port: 8080
periodSeconds: 1
livenessProbe:
httpGet:
path: /demo/hello
port: 8080

Just as with the database, this ReplicaSet should be familiar since it’s very similar to the one we used before. We’ll comment only on the differences.

  • Line 6: The number of replicas is set to 3. That solves one of the main problems we had with the previous ReplicaSets that defined Pods with both containers. Now the number of replicas can differ, and we have one Pod for the database, and three for the backend API.

  • Line 14: In the labels section, type label is set to api so that both the ReplicaSet and the (soon to come) Service can distinguish the Pods from those created for the database.

  • Lines 22–23: We have the environment variable DB set to go-demo-2-db. The code behind the vfarcic/go-demo-2 image is written in a way that the connection to the database is established by reading that variable. In this case, we can say that it will try to connect to the ...