ReplicationController
is a Kubernetes resource that ensures a specified number of replica pods is always running. It’s responsible for maintaining the desired state of a replicated application by creating or deleting pods as necessary to match the desired replica count.
If we want to create a ReplicationController
for an Apache container image to run three replicas of it on a cluster, we’ll define the kind
as ReplicationController
in the configuration YAML file. Additionally, we’ll specify the desired number of replicas
, which is three, to ensure that there are always three instances of the Apache pod running. Then the ReplicationController
will manage the lifecycle of these replicas, ensuring their availability and the desired state, as given in the following file.
apiVersion: v1kind: ReplicationControllermetadata:name: apachespec:replicas: 3selector:app: apachetemplate:metadata:name: apachelabels:app: apachespec:containers:- name: apacheimage: httpdports:- containerPort: 80
Line 2: We used the resource type of ReplicationController
, ensuring the number of replica pods running.
Line 6: We specified the number of replica pods we wanted to apply to our cluster.
Line 17: We specified the container image as httpd
, indicating that the Apache HTTP Server image will be used for the container.
To create the Kubernetes resources based on the configuration specified in the YAML file replicationController.yaml
, we can execute the following command in the terminal after clicking the “Run” button in the provided widget. This will initiate the creation of the cluster.
kubectl apply -f replicationController.yaml
Once the configuration is applied in the Kubernetes cluster defined in the YAML file, ensuring the desired state of the application, we can verify the number of replicas by using the following command:
kubectl describe replicationcontroller/apache
The output of this command will display the current count of running pods and the desired number of pods we aim to have in the cluster.
We can try it out ourselves below.
apiVersion: v1 kind: ReplicationController metadata: name: apache spec: replicas: 3 selector: app: apache template: metadata: name: apache labels: app: apache spec: containers: - name: apache image: httpd ports: - containerPort: 80
Unlock your potential: Kubernetes Essentials series, all in one place!
To deepen your understanding of Kubernetes, explore our series of Answers below:
What is Kubernetes?
Get an introduction to Kubernetes, the powerful container orchestration platform that automates deployment, scaling, and management of containerized applications.
What is Kubernetes Event-Driven Autoscaling (KEDA)?
Learn how KEDA enables event-driven scaling, allowing Kubernetes workloads to automatically scale based on external metrics such as message queues, databases, and cloud events.
Why do we use Kubernetes?
Understand the core benefits of Kubernetes, including automated deployment, scaling, and management of containerized applications across distributed environments.
What are Kubernetes namespaces?
Discover how Kubernetes namespaces help organize and isolate workloads within a cluster, enhancing security and resource allocation.
What are the different types of services in Kubernetes?
Explore the various Kubernetes service types—ClusterIP, NodePort, LoadBalancer, and ExternalName—and their roles in facilitating communication between applications.
ReplicationController in Kubernetes
Learn about the ReplicationController, its role in maintaining pod availability, and how it ensures that a specified number of pod replicas are always running.
ExternalDNS in Kubernetes
Understand how ExternalDNS simplifies service discovery by dynamically managing DNS records for Kubernetes services, making external access seamless.
What are taints and tolerations in Kubernetes?
Gain insights into taints and tolerations and how they control pod scheduling by preventing or allowing specific workloads to run on designated nodes.
Introduction to Node Affinity in Kubernetes
Discover how Node Affinity works in Kubernetes to influence pod scheduling by specifying node selection preferences and ensuring efficient workload distribution.
Free Resources