Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes: how to scale my pods

Tags:

kubernetes

I'm new to Kubernetes. I try to scale my pods. First I started 3 pods:

./cluster/kubectl.sh run my-nginx --image=nginx --replicas=3 --port=80 

There were starting 3 pods. First I tried to scale up/down by using a replicationcontroller but this did not exist. It seems to be a replicaSet now.

./cluster/kubectl.sh get rs NAME                  DESIRED   CURRENT   AGE my-nginx-2494149703   3         3         9h 

I tried to change the amount of replicas described in my replicaset:

./cluster/kubectl.sh scale --replicas=5 rs/my-nginx-2494149703 replicaset "my-nginx-2494149703" scaled 

But I still see my 3 original pods

./cluster/kubectl.sh get pods NAME                        READY     STATUS    RESTARTS   AGE my-nginx-2494149703-04xrd   1/1       Running   0          9h my-nginx-2494149703-h3krk   1/1       Running   0          9h my-nginx-2494149703-hnayu   1/1       Running   0          9h 

I would expect to see 5 pods.

./cluster/kubectl.sh describe rs/my-nginx-2494149703 Name:       my-nginx-2494149703 Namespace:  default Image(s):   nginx Selector:   pod-template-hash=2494149703,run=my-nginx Labels:     pod-template-hash=2494149703         run=my-nginx Replicas:   3 current / 3 desired Pods Status:    3 Running / 0 Waiting / 0 Succeeded / 0 Failed 

Why isn't it scaling up? Do I also have to change something in the deployment?

I see something like this when I describe my rs after scaling up: (Here I try to scale from one running pod to 3 running pods). But it remains one running pod. The other 2 are started and killed immediatly

  34s       34s     1   {replicaset-controller }            Normal      SuccessfulCreate    Created pod: my-nginx-1908062973-lylsz   34s       34s     1   {replicaset-controller }            Normal      SuccessfulCreate    Created pod: my-nginx-1908062973-5rv8u   34s       34s     1   {replicaset-controller }            Normal      SuccessfulDelete    Deleted pod: my-nginx-1908062973-lylsz   34s       34s     1   {replicaset-controller }            Normal      SuccessfulDelete    Deleted pod: my-nginx-1908062973-5rv8u 
like image 216
DenCowboy Avatar asked Jul 13 '16 07:07

DenCowboy


People also ask

How do you scale up pods in Kubernetes?

You can autoscale Deployments based on CPU utilization of Pods using kubectl autoscale or from the GKE Workloads menu in the Google Cloud console. kubectl autoscale creates a HorizontalPodAutoscaler (or HPA) object that targets a specified resource (called the scale target) and scales it as needed.

Can we scale pods in Kubernetes?

Scaling overviewKubernetes also supports autoscaling of Pods, but it is outside of the scope of this tutorial. Scaling to zero is also possible, and it will terminate all Pods of the specified Deployment. Running multiple instances of an application will require a way to distribute the traffic to all of them.

How do you scale up a Kubernetes cluster?

Scaling a Kubernetes cluster is updating the cluster by adding nodes to it or removing nodes from it. When you add nodes to a Kubernetes cluster, you are scaling up the cluster, and when you remove nodes from the cluster, you are scaling down the cluster.


2 Answers

This is working for me

kubectl scale --replicas=<expected_replica_num> deployment <deployment_label_name> 

Example

# kubectl scale --replicas=3 deployment xyz 
like image 200
Harsimranjit Singh Kler Avatar answered Sep 19 '22 21:09

Harsimranjit Singh Kler


TL;DR: You need to scale your deployment instead of the replica set directly.

If you try to scale the replica set, then it will (for a very short time) have a new count of 5. But the deployment controller will see that the current count of the replica set is 5 and since it knows that it is supposed to be 3, it will reset it back to 3. By manually modifying the replica set that was created for you, you are fighting with the system controller (which is untiring and will pretty much always outlast you).

like image 29
Robert Bailey Avatar answered Sep 21 '22 21:09

Robert Bailey