Ku­ber­netes Repli­caS­ets are a reliable and highly flexible solution for managing container ap­pli­ca­tions. You can define the number of identical pods and the con­tain­ers they contain in the YAML files.

What are Ku­ber­netes Repli­caS­ets?

Repli­caS­ets are a central resource in Ku­ber­netes that are re­spon­si­ble for managing identical pods. Their main purpose is to keep the desired number of copies of a pod constant. Repli­caS­ets con­tin­u­ous­ly monitor the state of the pods and au­to­mat­i­cal­ly initiate scaling. Depending on the con­fig­u­ra­tion, they start new pods or terminate surplus ones.

Tip

With managed Ku­ber­netes from IONOS, you get maximum flex­i­bil­i­ty in cus­tomiz­ing your Ku­ber­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 Ku­ber­netes Repli­caS­et

To operate Repli­caS­ets, you need a running Ku­ber­netes cluster, either locally on your de­vel­op­ment system (such as Minikube) or in a pro­duc­tion en­vi­ron­ment. In the Ku­ber­netes tutorial, we explain the setup in detail. Make sure that Kube­con­fig is set correctly to com­mu­ni­cate with the cluster. Then you can start con­fig­ur­ing the Repli­caS­et.

Opening a text editor

Create and open a YAML file with your favorite text editor or in­te­grat­ed de­vel­op­ment en­vi­ron­ment (IDE).

vim replicaset.yaml
shell

Con­fig­ur­ing the YAML file

Within the editor, you define the YAML con­fig­u­ra­tion for your Repli­caS­et.

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

Customize the names and images according to your ap­pli­ca­tion and save the file.

Ac­ti­vat­ing the Ku­ber­netes Repli­caS­et

Use the following command to apply the con­fig­u­ra­tion from your YAML file to the Ku­ber­netes cluster:

$kubectl create -f replicaset.yaml
shell

Checking the status of the Repli­caS­et

Check the status of the created Ku­ber­netes Repli­caS­et to make sure it has been suc­cess­ful­ly activated.

kubectl get replicasets new_replicaset
shell

You should see an output showing your new Repli­caS­et with the desired number of replicas.

NAME                  DESIRED   CURRENT   READY   AGE
new_replicaset           3         3        3     1m
shell
  • NAME: The name of the Repli­caS­et.
  • 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 Repli­caS­et 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­for­ma­tion about their status. If all pods have the status Running and the desired number of replicas has been reached, your Ku­ber­netes Repli­caS­et has been suc­cess­ful­ly 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 Repli­caS­ets

If you want to change the number of replicas in your Repli­caS­et, 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 Ku­ber­netes Repli­caS­et with the updated Repli­caS­et from your YAML file:

kubectl replace -f replicaset.yaml
shell

Al­ter­na­tive­ly, you can scale the number of replicas with kubectl scale:

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

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

Go to Main Menu