question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scaling StatefulSet filtered using label selectors

See original GitHub issue

Is your enhancement related to a problem? Please describe

I’m trying scale a StatefulSet by selecting it using its labels. For example, kubectl allows following:

$ kubectl scale statefulset -l release=yb,app.kubernetes.io/name=yb-tserver --replicas=4
statefulset.apps/yb-yugabyte-yb-tserver scaled

But when we filter StatefulSets with label selectors, the scale() method is not there.

Describe the solution you’d like

I’m thinking of something similar like this:

client
    .apps()
    .statefulSets()
    .withLabel("release", "yb")
    .withLabel(appLabel, "yb-tserver")
    .scale(4);

Describe alternatives you’ve considered

So far I have tried using list(), and then getting the first StatefulSet out of it. But when I tried to load the StatefulSet into client, the scale() method was not present. So, I had to use the metadata.name.

StatefulSet sts =
    client
	.apps()
	.statefulSets()
	.withLabel("release", "yb")
	.withLabel(appLabel, "yb-tserver")
	.list()
	.getItems()
	.get(0);

// This was not possible (should I create a separate issue for this?)
client.resource(sts).scale(4);

// I had to do this instead
client
    .apps()
    .statefulSets()
    .withName(sts.getMetadata().getName())
    .scale(4);

Additional context

When kubectl finds multiple StatefulSets filtered the label selectors, it just scales all of them.

$ kubectl scale statefulset -l release=yb --replicas=4
statefulset.apps/yb-yugabyte-yb-master scaled
statefulset.apps/yb-yugabyte-yb-tserver scaled

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bhavin192commented, Mar 29, 2022

That’s great, thanks! I have been away for a while, I will send PR for docs/example entry next week. With my PR we can close this issue.

1reaction
shawkinscommented, Mar 28, 2022

a resources method was added with #3973

client.apps().statefulSets()
  .withLabel("release", "yb")
  .withLabel(appLabel, "yb-tserver")
  .resources()
  .forEach(s -> s.scale(4));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Labels and Selectors - Kubernetes
LIST and WATCH operations may specify label selectors to filter the sets of objects returned using a query parameter.
Read more >
How to use "kubectl -l/--selector" to scale a specific pod in a ...
Follow the below command kubectl scale deployment/bla --replicas=2. Note: You cant scale pods. you can scale replicaSets/Deployments/ ...
Read more >
Using Kubectl Scale | Tutorial and Best Practices - ContainIQ
The kubectl scale command is used to change the number of running replicas inside Kubernetes deployment, replica set, replication controller, and stateful set...
Read more >
Use a StatefulSet to create a stateful application - Alibaba Cloud
Selector : Click Add to add pod labels. View Applications: Click View Applications and set the namespace and application in the dialog box...
Read more >
Filtering Kubernetes Resources using Labels, Annotations ...
You can use labels, annotations, and selectors to manage metadata attached to your Kubernetes objects. Labels and annotations define the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found