public static void scaleDeployment(String deploymentName, int numberOfReplicas)
      throws ApiException {
    ExtensionsV1beta1Api extensionV1Api = new ExtensionsV1beta1Api();
    extensionV1Api.setApiClient(COREV1_API.getApiClient());
    ExtensionsV1beta1DeploymentList listNamespacedDeployment =
        extensionV1Api.listNamespacedDeployment(
            DEFAULT_NAME_SPACE, null, null, null, null, null, null, null, null, Boolean.FALSE);

    List<ExtensionsV1beta1Deployment> extensionsV1beta1DeploymentItems =
        listNamespacedDeployment.getItems();
    Optional<ExtensionsV1beta1Deployment> findedDeployment =
        extensionsV1beta1DeploymentItems
            .stream()
            .filter(
                (ExtensionsV1beta1Deployment deployment) ->
                    deployment.getMetadata().getName().equals(deploymentName))
            .findFirst();
    findedDeployment.ifPresent(
        (ExtensionsV1beta1Deployment deploy) -> {
          try {
            ExtensionsV1beta1DeploymentSpec newSpec = deploy.getSpec().replicas(numberOfReplicas);
            ExtensionsV1beta1Deployment newDeploy = deploy.spec(newSpec);
            extensionV1Api.replaceNamespacedDeployment(
                deploymentName, DEFAULT_NAME_SPACE, newDeploy, null, null);
          } catch (ApiException ex) {
            LOGGER.warn("Scale the pod failed for Deployment:" + deploymentName, ex);
          }
        });
  }
public static void scaleDeployment ( String deploymentName , int numberOfReplicas ) throws ApiException { ExtensionsV1beta1Api extensionV1Api = new ExtensionsV1beta1Api ( ) ; extensionV1Api . setApiClient ( COREV1_API . getApiClient ( ) ) ; ExtensionsV1beta1DeploymentList listNamespacedDeployment = extensionV1Api . listNamespacedDeployment ( DEFAULT_NAME_SPACE , null , null , null , null , null , null , null , null , Boolean . FALSE ) ; List < ExtensionsV1beta1Deployment > extensionsV1beta1DeploymentItems = listNamespacedDeployment . getItems ( ) ; Optional < ExtensionsV1beta1Deployment > findedDeployment = extensionsV1beta1DeploymentItems . stream ( ) . filter ( ( ExtensionsV1beta1Deployment deployment ) -> deployment . getMetadata ( ) . getName ( ) . equals ( deploymentName ) ) . findFirst ( ) ; findedDeployment . ifPresent ( ( ExtensionsV1beta1Deployment deploy ) -> { try { ExtensionsV1beta1DeploymentSpec newSpec = deploy . getSpec ( ) . replicas ( numberOfReplicas ) ; ExtensionsV1beta1Deployment newDeploy = deploy . spec ( newSpec ) ; extensionV1Api . replaceNamespacedDeployment ( deploymentName , DEFAULT_NAME_SPACE , newDeploy , null , null ) ; } catch ( ApiException ex ) { LOGGER . warn ( "Scale the pod failed for Deployment:" + deploymentName , ex ) ; } } ) ; }
Scale up/down the number of pod in Deployment

@param deploymentName
@param numberOfReplicas
@throws ApiException