
- Replication – It can replicate or scale one pod to many
- Controller – It would control the desire number of pods with actual number of pod.
A ReplicationController is a Kubernetes controller that ensures that a specified number of pod replicas are running at any one time. In other words, a ReplicationController makes sure that a pod or a homogeneous set of pods is always up and available.
ReplicationControllers are useful for running stateful applications, such as databases and message queues, which need to be highly available. They can also be used to run stateless applications, such as web servers, which need to be scalable.
To create a ReplicationController, you need to specify the desired number of pod replicas and the pod template that you want to use. The pod template defines the pod specification, such as the container image and the resources that the pod needs.
Once you have created a ReplicationController, it will start creating and managing pod replicas. If a pod replica fails, the ReplicationController will create a new replica to replace it.
ReplicationControllers are a powerful tool for managing Kubernetes pods. They can help to ensure that your applications are always up and available, and that they can scale to meet demand.
Here are some examples of how ReplicationControllers can be used:
- A production team can use a ReplicationController to ensure that their production pods are always up and available.
- A development team can use a ReplicationController to scale their development pods up or down as needed.
- A company can use a ReplicationController to run a distributed database cluster.
- A website can use a ReplicationController to run a scalable web server farm.
ReplicationControllers are an important part of the Kubernetes ecosystem, and they are used by many organizations to manage their Kubernetes pods.
Absolutely! Here’s a detailed step-by-step tutorial on using Kubernetes ReplicationController
(RC), covering your sample YAML, key commands, scaling, and how RC manages Pods. This will walk you through the complete workflow, with explanations for every step.
Kubernetes ReplicationController Tutorial
1. What is a ReplicationController?
A ReplicationController ensures that a specified number of pod replicas are running at any one time. If a pod fails or is deleted, the RC automatically creates a new pod to replace it. Although RC is being replaced by ReplicaSet (used in Deployments), it’s important to understand RC for legacy and interview scenarios.
2. Sample ReplicationController YAML
Let’s start with the following rc.yaml
definition:
apiVersion: v1
kind: ReplicationController
metadata:
name: rajeshrc
spec:
replicas: 5
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: scmgalaxy/nginx-devopsschoolv1
Key sections:
- replicas: Number of pod copies to run (here, 5)
- template: Pod template to use (labels & containers)
3. Step-by-Step Workflow
3.1. Create the YAML file
vi rc.yaml
# (Paste the YAML above and save the file)
Code language: PHP (php)
3.2. Create the ReplicationController
kubectl create -f rc.yaml
Code language: CSS (css)
- This will create a ReplicationController named
rajeshrc
and start 5 pods with the nginx image.
3.3. Check the ReplicationController
kubectl get rc
Code language: JavaScript (javascript)
Expected output:
NAME DESIRED CURRENT READY AGE
rajeshrc 5 5 5 1m
3.4. View the Pods managed by RC
kubectl get pods
Code language: JavaScript (javascript)
- You’ll see 5 pods with names like
rajeshrc-xxxxx
.
3.5. Describe a Pod
kubectl describe pod <pod-name>
# Example:
kubectl describe pod rajeshrc-7tnm4
Code language: HTML, XML (xml)
- Shows detailed info about the pod: events, state, image, logs, etc.
4. Scaling the ReplicationController
4.1. Scale Up Pods
kubectl scale --replicas=20 rc/rajeshrc
- The RC will create additional pods (total 20).
kubectl get rc
kubectl get pods
Code language: JavaScript (javascript)
- Confirm there are now 20 pods.
4.2. Scale Down Pods
kubectl scale --replicas=2 rc/rajeshrc
- The RC will terminate excess pods to reach 2.
kubectl get pods
kubectl get rc
Code language: JavaScript (javascript)
5. Self-healing Demonstration
5.1. Delete a Pod Managed by RC
kubectl delete pod <pod-name>
# Example:
kubectl delete pod rajeshrc-n5flj
Code language: HTML, XML (xml)
- RC will immediately create a replacement pod to maintain the desired replica count.
kubectl get pods
Code language: JavaScript (javascript)
- Observe that the number of pods remains the same.
6. Deleting the ReplicationController
6.1. Delete using YAML
kubectl delete -f rc.yaml
Code language: JavaScript (javascript)
- This deletes the RC and by default deletes all managed pods as well.
7. Key Notes
- RC vs ReplicaSet: In modern Kubernetes, prefer ReplicaSet (and use Deployments), but RC is still available for backwards compatibility.
- Pod Naming: Pods created by RC have a generated suffix (e.g.,
rajeshrc-7tnm4
) for uniqueness. - Self-healing: RC ensures that the number of running pods always matches the
replicas
value.
8. Common RC Commands Reference
Action | Command |
---|---|
List all ReplicationControllers | kubectl get rc |
Describe a ReplicationController | kubectl describe rc <name> |
Get all pods managed by RC | kubectl get pods -l app=nginx |
Scale ReplicationController | kubectl scale --replicas=3 rc/rajeshrc |
Delete a ReplicationController | kubectl delete rc rajeshrc |
Delete RC using file | kubectl delete -f rc.yaml |
9. Full Example Session (Shell History)
Here’s a replay of the session you shared, annotated:
cd rajesh/ # Move to your project directory
vi rc.yaml # Create/Edit the RC YAML
kubectl get rc # See existing RCs
kubectl create -f rc.yaml # Create new RC
kubectl get rc # Confirm creation
kubectl get pods # See managed pods
kubectl describe pod <pod> # Get pod details
kubectl scale --replicas=20 rc/rajeshrc # Scale up
kubectl get pods
kubectl scale --replicas=2 rc/rajeshrc # Scale down
kubectl get pods
kubectl delete pods <pod> # Delete a pod, RC will recreate it
kubectl get pods
kubectl delete -f rc.yaml # Delete the RC and its pods
Code language: PHP (php)
10. Summary Table
Step | Command / Action | Purpose |
---|---|---|
Create YAML | vi rc.yaml | Define ReplicationController spec |
Create RC | kubectl create -f rc.yaml | Launch RC and pods |
List RCs/Pods | kubectl get rc , kubectl get pods | See running RCs and pods |
Scale RC | kubectl scale --replicas=N rc/<name> | Adjust pod count |
Delete Pod | kubectl delete pod <pod> | Remove a pod, RC will self-heal |
Delete RC | kubectl delete -f rc.yaml | Remove RC and all managed pods |
11. Conclusion
- ReplicationController is fundamental for managing pod replicas and self-healing workloads in Kubernetes.
- While you’ll mostly use Deployments and ReplicaSets in production, understanding RC is critical for foundational knowledge and troubleshooting.
Kubernetes Replication Controller Example Programs
apiVersion: v1
kind: ReplicationController
metadata:
# Unique key of the ReplicationController instance
name: replicationcontroller-example
spec:
# 3 Pods should exist at all times.
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
# Run the nginx image
- name: nginx
image: scmgalaxy/nginx-devopsschoolv1
Code language: PHP (php)
apiVersion: v1
kind: ReplicationController
metadata:
# Unique key of the ReplicationController instance
name: replicationcontroller-example
spec:
# 3 Pods should exist at all times.
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
# Run the nginx image
- name: nginx
image: nginx:1.10
# rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: hello-rc
spec:
replicas: 5
selector:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-ctr
image: nginx
ports:
- containerPort: 80
## Sample Replication Controller YAML file used in example :
apiVersion: v1
kind: ReplicationController
metadata:
name: hello-rc
spec:
replicas: 10
selector:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-ctr
image: nigelpoulton/pluralsight-docker-ci:latest
ports:
- containerPort: 8080
apiVersion: v1
kind: ReplicationController
metadata:
name: hello-rc
spec:
replicas: 3
selector:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-ctr
image: wardviaene/k8s-demo
ports:
- containerPort: 3000
apiVersion: v1
kind: ReplicationController
metadata:
name: helloworld-controller
spec:
replicas: 2
selector:
app: helloworld
template:
metadata:
labels:
app: helloworld
spec:
containers:
- name: k8s-demo
image: wardviaene/k8s-demo
ports:
- name: nodejs-port
containerPort: 3000
apiVersion: v1
kind: ReplicationController
metadata:
name: helloworld-controller
spec:
replicas: 2
selector:
app: helloworld
template:
metadata:
labels:
app: helloworld
spec:
containers:
- name: k8s-demo
image: wardviaene/k8s-demo
ports:
- name: nodejs-port
containerPort: 3000
Code language: PHP (php)
Use cases of ReplicationController?
A ReplicationController (often abbreviated as “RC”) is a Kubernetes resource that ensures a specified number of replica pods are running at all times. It helps maintain the desired number of pod replicas, automatically replacing failed pods or creating new ones when necessary. ReplicationControllers are part of Kubernetes’ core functionality and have several important use cases:
- High Availability: ReplicationControllers ensure that a specified number of pod replicas are always running. This helps maintain high availability of your application, even if some pods fail or become unavailable due to node failures or other issues.
- Scaling: ReplicationControllers can be used to scale your application horizontally. You can increase or decrease the desired replica count, and the ReplicationController will automatically create or terminate pods to meet that count. This is especially useful for handling increased or decreased traffic loads.
- Load Balancing: When combined with a Service resource, ReplicationControllers enable load balancing across multiple pod replicas. Requests to the Service are distributed evenly among the pods managed by the ReplicationController, ensuring efficient utilization of resources.
- Rolling Updates: ReplicationControllers facilitate rolling updates of your application. You can update the pod template in the ReplicationController specification with a new version of your application, and it will gradually replace old pods with new ones, ensuring zero-downtime deployments.
- Rollback: In case an update causes issues, you can easily roll back to a previous version by reverting to the previous pod template specification. This helps in maintaining application stability and mitigating issues quickly.
- Fault Tolerance: ReplicationControllers automatically replace failed pods. If a pod crashes or becomes unresponsive, the ReplicationController detects this and replaces it with a new pod, helping to maintain the desired replica count.
- Resource Scaling: You can configure autoscaling based on CPU or memory utilization using Horizontal Pod Autoscalers (HPA) in combination with ReplicationControllers. This allows your application to dynamically adapt to changing resource demands.
- Testing and Development: ReplicationControllers can be useful in testing and development environments. You can use them to create multiple replicas of your application for testing different scenarios, such as load testing or compatibility testing.
- Pod Distribution: If you have multiple nodes in your cluster, ReplicationControllers help distribute pods across nodes to ensure resource utilization and minimize the risk of node-specific failures affecting your application.
- Stateless Applications: ReplicationControllers are particularly well-suited for stateless applications where each pod is independent and can handle requests without relying on the state stored in other pods.

















I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND