zoukankan      html  css  js  c++  java
  • kubernets-java 动态修改deployment 的replicas

       /**
         * Scale up/down the number of pod in Deployment
         *
         * @param deploymentName
         * @param numberOfReplicas
         * @throws ApiException
         */
        public static void scaleDeployment(String deploymentName, int numberOfReplicas)
                throws ApiException {
            AppsV1Api appsV1Api = new AppsV1Api();
            appsV1Api.setApiClient(COREV1_API.getApiClient());
            // 获取V1DeploymentList
            V1DeploymentList listNamespacedDeployment =
                    appsV1Api.listNamespacedDeployment(
                            DEFAULT_NAME_SPACE, null, null, null, null, null, null, null, null, Boolean.FALSE);
    
            List<V1Deployment> appsV1DeploymentItems = listNamespacedDeployment.getItems();
    
    
            Optional<V1Deployment> findedDeployment =
                    appsV1DeploymentItems.stream()
                            .filter(
                                    (V1Deployment deployment) ->
                                            deployment.getMetadata().getName().equals(deploymentName))
                            .findFirst();
    
            findedDeployment.ifPresent(
                    (V1Deployment deploy) -> {
                        try {
                            V1DeploymentSpec newSpec = deploy.getSpec().replicas(numberOfReplicas);
                            V1Deployment newDeploy = deploy.spec(newSpec);
                            appsV1Api.replaceNamespacedDeployment(
                                    deploymentName, DEFAULT_NAME_SPACE, newDeploy, null, null, null);
                        } catch (ApiException ex) {
                            LOGGER.warn("Scale the pod failed for Deployment:" + deploymentName, ex);
                        }
                    });
        }
  • 相关阅读:
    线程池及其原理和使用
    多线程通信Queue
    Condition实现线程通信
    守护线程和锁
    习题 7:更多的打印
    习题 6:字符串和文本
    习题 5:更多的变量和打印
    习题 4:变量和命名
    习题 3:数字和数学计算
    习题 2:注解和#号
  • 原文地址:https://www.cnblogs.com/shix0909/p/13523279.html
Copyright © 2011-2022 走看看