Scale the replica set using Labels

6/5/2018

I could able to scale the replica set using the following

/apis/apps/v1/namespaces/{namespace}/deployments/{deployment}/scale

Is there a way that I can do scaling based on the specific label instead of namespaces and deployment.

I could find a way to get the deployments based on label

/apis/extensions/v1beta1/deployments?labelSelector={labelKey}={labelValue}

But couldn't find scaling using label.

Any help is appreciated.

-- surazzarus
kubernetes

1 Answer

6/6/2018

You can scale Deployments, ReplicaSets, ReplicaConlrollers and StatefulSets using appropriate API:

/apis/apps/v1/namespaces/{namespace}/deployments/{name}/scale
/apis/apps/v1/namespaces/{namespace}/replicationcontrollers/{name}/scale
/apis/apps/v1/namespaces/{namespace}/replicasets/{name}/scale
/apis/apps/v1/namespaces/{namespace}/statefulsets/{name}/scale

The idea is to find Deployment with required Labels using API /apis/extensions/v1beta1/deployments?labelSelector={labelKey}={labelValue}, and after that, use API /apis/apps/v1/namespaces/{namespace}/deployments/{name}/scale to scale.

You can implement this logic on ReplicaSets, ReplicaConlrollers and StatefulSets. But you need to remember, if you use Deployment, you need to scale it, not ReplicaConlroller created by it.

-- Artem Golenyaev
Source: StackOverflow