How To Scale ReplicaSets in Kubernetes

This blog post will show you how to scale ReplicaSets in a Kubernetes cluster using kubectl or a configuration file.

Scaling

When running workload on any Kubernetes cluster, you might need to scale the number of pods either up or down depending on the application load.

This post follows the previous post about ReplicaSets, where we have learned how to deploy ReplicaSets in Kubernetes.

Kubectl

The easiest way to scale an existing ReplicaSets on a Kubernetes cluster is to use the Kubectl command-line and quickly scale up or down the number of pods.

The below command shows how I scale the number of pods from 3 to 4.

kubectl scale replicaset nginxset --replicas=4

Once the commands run, Kubernetes will action the request and scale the set.

Configuration

We can also update an existing configuration file and change the number of replicas shown in the code below. I can change the number from 3 to 4 and apply.

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginxreplicaset
  labels:
    versionnumber: v1
spec:
  replicas: 3

The code below will apply the configuration.

kubectl apply -f replicasets.yaml

Processing…
Success! You're on the list.

Posted

in

by