🚀 Getting Started with Kubernetes: ReplicationController vs ReplicaSet

Dechen TsheringDechen Tshering
3 min read

As I continue my Kubernetes learning journey, I recently dug into two fundamental building blocks that help manage pods: ReplicationControllers and ReplicaSets. Both are designed to ensure that a certain number of pod replicas are running at all times, making your applications more resilient and scalable.

In this post, I’ll walk through what I’ve learned about these two resources, how they differ, and the basic commands to manage them using kubectl.

What is a ReplicationController?

A ReplicationController (RC) is one of the original Kubernetes components used to manage pod replication. Its job is to ensure that a specific number of pod instances are always running. If a pod crashes or is deleted, the RC automatically brings up a replacement.

Even though it’s considered outdated and has largely been replaced by ReplicaSet, understanding it is valuable for grasping Kubernetes concepts.

Sample ReplicationController YAML:

apiVersion: v1
kind: ReplicationController
metadata: 
  name: myrc
spec: 
  replicas: 5
  template:
    metadata:
      labels: 
        app: web
    spec:
      containers:
      - name: c1
        image: nginx

Useful RC Commands:

List RCs:

kubectl get rc

Delete an RC:

kubectl delete rc <rc-name>

Scale the RC:

kubectl scale --replicas=<number> rc/<rc-name>

What is a ReplicaSet?

A ReplicaSet (RS) is the modern version of RC. It comes with better support for selectors (especially set-based), making it more powerful and flexible. ReplicaSets are commonly used behind the scenes by Deployments, but you can also use them directly.

Example 1: Equality-Based Selector:

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: mywebapp
spec:
  replicas: 5
  selector:
    matchLabels: 
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: c1
        image: nginx

Example 2: Set-Based Selector:

apiVersion: apps/v1
kind: ReplicaSet
metadata: 
  name: webdata
spec:
  replicas: 4
  selector:
    matchExpressions:
    - key: app
      operator: In
      values:
        - nginx
        - web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: c1
        image: nginx

Key ReplicaSet Commands:

List all ReplicaSets:

kubectl get rs

Describe a ReplicaSet:

kubectl describe rs <replicaset-name>

Delete a ReplicaSet:

kubectl delete rs <replicaset-name>

Scale a ReplicaSet:

kubectl scale rs/<replicaset-name> --replicas=3

Edit a ReplicaSet:

kubectl edit rs <replicaset-name>

Apply from a YAML file:

kubectl apply -f webrs.yml

List pods managed by a ReplicaSet:

kubectl get pods -l app=web

ReplicationController vs ReplicaSet: Key Differences

FeatureReplicationController (RC)ReplicaSet (RS)
API Versionv1apps/v1
Label Selector SupportEquality-based onlyEquality & set-based
UsageLegacy / older systemsModern replacement for RC
Used by DeploymentNoYes
FlexibilityLess flexibleMore flexible
Community SupportDeprecatedActively supported

Understanding ReplicationControllers and ReplicaSets gave me a solid foundation in managing pod replication in Kubernetes. While RCs are mostly phased out, learning about them helped me appreciate how things evolved in Kubernetes.

Up next, I'm diving into Deployments—which offer even more powerful features which uses ReplicaSets to manage and scale pods.

0
Subscribe to my newsletter

Read articles from Dechen Tshering directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Dechen Tshering
Dechen Tshering