Search⌘ K

Splitting the Pod and Establishing Communication through Services

Explore how to split a Kubernetes Pod into separate components and establish communication between them using Services. Understand ReplicaSets for managing Pod replicas and how Services support fixed DNS communication within the cluster. Gain practical experience creating ReplicaSets and Services to maintain database and API Pods communicating internally.

Looking into the definition

Let’s look at a ReplicaSet definition go-demo-2-db-rs.yml for a Pod with only the database.

YAML
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: go-demo-2-db
spec:
selector:
matchLabels:
type: db
service: go-demo-2
template:
metadata:
labels:
type: db
service: go-demo-2
vendor: MongoLabs
spec:
containers:
- name: db
image: mongo:3.3
ports:
- containerPort: 28017

We’ll comment only on the things that changed.

Since this ReplicaSet defines only the database, we reduce the number of replicas to 1. We should scale MongoDB as well, but that’s out of the scope of this chapter. For now, we’ll consider that one replica of a database is enough.

Since selector ...