Kuber­netes Rep­lica­Se­ts are a reliable and highly flexible solution for managing container ap­plic­a­tions. You can define the number of identical pods and the con­tain­ers they contain in the YAML files.

What are Kuber­netes Rep­lica­Se­ts?

Rep­lica­Se­ts are a central resource in Kuber­netes that are re­spons­ible for managing identical pods. Their main purpose is to keep the desired number of copies of a pod constant. Rep­lica­Se­ts con­tinu­ously monitor the state of the pods and auto­mat­ic­ally initiate scaling. Depending on the con­fig­ur­a­tion, they start new pods or terminate surplus ones.

Tip

With managed Kuber­netes from IONOS, you get maximum flex­ib­il­ity in cus­tom­ising your Kuber­netes resources. In the IONOS cloud in­fra­struc­ture, you can precisely configure worker nodes, from the number of CPUs to the memory size.

How to create a Kuber­netes Rep­lica­Set

To operate Rep­lica­Se­ts, you need a running Kuber­netes cluster, either locally on your de­vel­op­ment system (such as Minikube) or in a pro­duc­tion en­vir­on­ment. In the Kuber­netes tutorial, we explain the setup in detail. Make sure that Kube­con­fig is set correctly to com­mu­nic­ate with the cluster. Then you can start con­fig­ur­ing the Rep­lica­Set.

Opening a text editor

Create and open a YAML file with your favourite text editor or in­teg­rated de­vel­op­ment en­vir­on­ment (IDE).

vim replicaset.yaml
shell

Con­fig­ur­ing the YAML file

Within the editor, you define the YAML con­fig­ur­a­tion for your Rep­lica­Set.

apiVersion: apps/v1
kind: ReplicaSet
metadata:
    name: new_replicaset
spec:
    replicas: 3
    selector:
        matchLabels:
            app: app
    template:
        metadata:
            labels:
                app: app
        spec:
            containers:
            - name: container
                image: container-image:latest
yaml

Customise the names and images according to your ap­plic­a­tion and save the file.

Ac­tiv­at­ing the Kuber­netes Rep­lica­Set

Use the following command to apply the con­fig­ur­a­tion from your YAML file to the Kuber­netes cluster:

$kubectl create -f replicaset.yaml
shell

Checking the status of the Rep­lica­Set

Check the status of the created Kuber­netes Rep­lica­Set to make sure it has been suc­cess­fully activated.

kubectl get replicasets new_replicaset
shell

You should see an output showing your new Rep­lica­Set with the desired number of replicas.

NAME                  DESIRED   CURRENT   READY   AGE
new_replicaset           3         3        3     1m
shell
  • NAME: The name of the Rep­lica­Set.
  • DESIRED: The desired number of replicas as specified in the YAML file.
  • CURRENT: The current number of running replicas.
  • READY: The number of replicas that are marked as ‘READY’ and ready for traffic.
  • AGE: The time since the Rep­lica­Set was created.

Checking the status of the pods

In addition, check the status of the pods you have created.

kubectl get pods
shell

This will show you a list of the created pods with in­form­a­tion about their status. If all pods have the status Running and the desired number of replicas has been reached, your Kuber­netes Rep­lica­Set has been suc­cess­fully created and activated.

NAME                           READY       STATUS    RESTARTS    AGE
new_replicaset-xxxx        		1/1       Running        0        1m
new_replicaset-yyyy             1/1       Running        0        1m
new_replicaset-zzzz             1/1       Running        0        1m
shell

Scaling Rep­lica­Se­ts

If you want to change the number of replicas in your Rep­lica­Set, adjust your YAML file. Simply set the value of the replicas field to the desired number and save the file. Then enter the following command to replace the existing Kuber­netes Rep­lica­Set with the updated Rep­lica­Set from your YAML file:

kubectl replace -f replicaset.yaml
shell

Al­tern­at­ively, you can scale the number of replicas with kubectl scale:

kubectl scale --replicas=4-f replicaset-app.yaml
shell
IONOS Cloud Managed Kuber­netes
Container workloads in expert hands

The ideal platform for demanding, highly scalable container ap­plic­a­tions. Managed Kuber­netes works with many cloud-native solutions and includes 24/7 expert support.

Go to Main Menu