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
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.
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.
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.
This is working for me
kubectl scale --replicas=<expected_replica_num> deployment <deployment_label_name>
Example
# kubectl scale --replicas=3 deployment xyz
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With