0

I want to scale in a pod with a specific label, but it seems -l does not work for scaling.

For example, if I have pods bla-12345-aaaaa, bla-12345-bbbbb, and bla-12345-cccc, and I scale in to 2 replicas, I want bla-12345-aaaaa specifically to disappear.

I get this error:

kubectl scale --replicas=2 deployment/bla -l scaleIn=true
error: selectors and the all flag cannot be used when passing resource/name arguments

You can see it in the documentation:

-l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)

  • 1
    You can't "scale a pod"; all of the pods managed by a deployment are identical, and they're the lowest unit of scheduling. If you already know the deployment name, why do you want to also pass a label? – David Maze Oct 22 '19 at 10:04
  • @DavidMaze, I meant I want to scale in a specific pod in a deployment. Edited the title now – surimi sticks Oct 22 '19 at 10:35
  • Say `deployment/bla` currently has three replicas; let's call them `bla-12345-aaaaa`, `bla-12345-bbbbb`, and `bla-12345-ccccc`. What do you want the final state to be? (The three pods will pretty much definitionally have the same labels.) – David Maze Oct 22 '19 at 10:52
  • @DavidMaze, I edited the post. Can I only use labels to choose a deployment to scale? Can I not label a specific pod to remove when scaling in a deployment? – surimi sticks Oct 22 '19 at 11:09
  • All of the pods will have the same labels. – David Maze Oct 22 '19 at 13:12
  • [Kubernetes scale down specific pods](/questions/33617090/kubernetes-scale-down-specific-pods) talks about this, but in the context of ReplicaSets (and even then says it’s impossible). This is harder when Deployments manage ReplicaSets and the suggestion in the first answer won’t work. – David Maze Oct 22 '19 at 13:14

3 Answers3

3

Follow the below command

kubectl scale  deployment/bla --replicas=2

Note: You cant scale pods. you can scale replicaSets/Deployments/StatefulSets

Follow the below steps to scale deployment by label

[root@f482a0035623 work]# kubectl get deploy -l app=web   
NAME     READY   UP-TO-DATE   AVAILABLE   AGE
webapp   1/1     1            1           88d
[root@f482a0035623 work]# kubectl scale deploy -l app=web --replicas=2
deployment.extensions/webapp scaled
[root@f482a0035623 work]# kubectl get deploy -l app=web
NAME     READY   UP-TO-DATE   AVAILABLE   AGE
webapp   2/2     2            2           88d
P Ekambaram
  • 15,499
  • 7
  • 34
  • 59
2

Like David Maze said, you cannot scale pods.

You can check that by doing kubectl scale explain:

Examples:

Scale a replicaset named 'foo' to 3.

kubectl scale --replicas=3 rs/foo

Scale a resource identified by type and name specified in "foo.yaml" to 3.

kubectl scale --replicas=3 -f foo.yaml

If the deployment named mysql's current size is 2, scale mysql to 3.

kubectl scale --current-replicas=2 --replicas=3 deployment/mysql

Scale multiple replication controllers.

kubectl scale --replicas=5 rc/foo rc/bar rc/baz

Scale statefulset named 'web' to 3.

kubectl scale --replicas=3 statefulset/web

Also you can read in the documentation Horizontal Pod Autoscaler.

The Horizontal Pod Autoscaler automatically scales the number of pods in a replication controller, deployment or replica set based on observed CPU utilization (or, with custom metrics support, on some other application-provided metrics). Note that Horizontal Pod Autoscaling does not apply to objects that can’t be scaled, for example, DaemonSets.

You can target the deployment to scale in 2 ways. One is to provide a name of the deployment like so:

kubectl scale --replicas=2 deployment/bla

or targeting it with a label:

kubectl scale deploy -l scaleIn=true --replicas=2

Community
  • 1
  • 1
Discombobulate
  • 279
  • 2
  • 8
0

You can also use the following format:

kubectl scale --replicas=2 deployment -l scaleIn=true

It will scale all the deployment that match the label selector.

Kamol Hasan
  • 12,218
  • 1
  • 37
  • 46