This small article is of creating ReplicaSet using Terraform

Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.

What is ReplicaSet ?

A ReplicaSet’s purpose is to maintain a stable set of replica Pods running at any given time. As such, it is often used to guarantee the availability of a specified number of identical Pods.

What is Terraform ?

Use Infrastructure as Code to provision and manage any cloud, infrastructure, or service. Terraform users define infrastructure in a simple, human-readable configuration language called HCL (HashiCorp Configuration Language). Users can write unique HCL configuration files or borrow existing templates from the public module registry.

I have created functioning/working of ReplicaSet using Terraform code below.

I have used resource “replication controller”, but according to the used case, we can also use resource “deployment” .

Autoscaling Replica set
  • → Selector field takes label as their reference to acquire pods within it, so that is why , I have written LABELS in the above code.
  • — “env, dev, dc, In” are environment, development, data_center, India respectively (like tags ).
  • Metadata is data of data ,we give information to metadata, when we launch something
  • → Name of our ReplicaSet is “replicaset”.
  • Spec block is Specification of what we are launching.
  • max_replicas are maximum replicas to be auto-scaled.
  • min_replicas are minimum replicas to be auto-scaled.
  • Lastly, we have to tell about the reference of scaling i.e “scale_target_ref” . In kind variable ,I have told about my resource which will be creating pods with number of replicas i.e “replication-controller”.
Resource — Replication controller part 2(a)
  • → The spec block is again about specification of desired working of a pod. The SELECTOR discussed above,now comes into play i.e if all labels(tags) specified in this block are same as that of pod created, then the pods will be acquired by ReplicaSet and will match the no of replicas mentioned in the spec block and if the number exceeds, then ReplicaSet will terminate that pod. (In my case replicas is set to 3, so 4 or more replicas will not be allowed to run with same labels).
TEST-1 => This is the code for pod written in YAML File, I will be creating this pod by changing the label.
TEST-2 => As you can see ,my 3 replicas, Replication controller , ReplicaSet are running and observe Labels also
TEST-3
TEST-4
TEST-5
TEST-6
TEST-7
Resource — Replication controller part 2(b)

I am a student and persuing under graduation in computer science and engineering.