1

Anyone knows any way, or controller, plugin, anything.. without knowing upfront the number of replicas of a deployment, to scale the deployment to plus one or more replicas. Like

kubectl scale --replicas=+1 deployment/mysql

Currently, as far as I know, we need to first query the object for the current number of replicas and then we can run the command. But what if between the query and the execution of the command someone already scaled up 10 replicas and the we sort of overwrite the replicas number. I know, we could use the "current-replicas", but anyway; Anyone knows another way?

Thx!

JGG
  • 304
  • 2
  • 12
  • using `current-replicas` is the right way to prevent conflicts, this will ensure the state of deployment you assume is matching with reality. if not matching, your command would fail, indicating that the scaling is already done in between by someone else. – P.... May 26 '22 at 18:53

1 Answers1

0

I think you've mostly answered your own question here, although maybe you were hoping for something more elegant. Through kubectl, the only way is to query the current number of replicas and then issue a scale command to that value plus one. To prevent the scenario where someone scaled it before you did, you can use the --current-replicas flag to ensure the previous value is what you originally retrieved. Something like this would do it in one shell command:

REPS=$(kubectl get deployments/mysql -o jsonpath={.status.replicas}) \
   [ -z "${REPS}" ] && kubectl scale \
   --current-replicas=$REPS \
   --replicas=$(echo $REPS + 1 | bc -l) deployments/mysql
Robert Nubel
  • 7,104
  • 1
  • 18
  • 30