简体   繁体   English

如何使用 Fabric8 k8s java 客户端(版本:6.0.0)删除 HorizontalPodAutoscaler

[英]How to delete HorizontalPodAutoscaler using Fabric8 k8s java client (version: 6.0.0)

Looks like there is no support to delete HorizontalPodAutoscaler using fabric8's K8S Java client ver:6.0.0.看起来不支持使用fabric8的K8S Java客户端版本:6.0.0删除HorizontalPodAutoscaler。

Although It is straightforward to create HorizontalPodAutoscaler using fabric8's K8S Java client ver:6.0.0.虽然使用 fabric8 的 K8S Java 客户端版本:6.0.0 创建 HorizontalPodAutoscaler 很简单。

Eg例如

 HorizontalPodAutoscalerStatus hpaStatus = k8sClient.resource(createHPA())
                .inNamespace(namespace)
                .createOrReplace().getStatus();
public HorizontalPodAutoscaler createHPA(){
return new HorizontalPodAutoscalerBuilder()
                .withNewMetadata()
                    .withName(applicationName)
                    .addToLabels("name", applicationName)
                .endMetadata()
                .withNewSpec()
                    .withNewScaleTargetRef()
                        .withApiVersion(hpaApiVersion)
                        .withKind("Deployment")
                        .withName(applicationName)
                    .endScaleTargetRef()
                    .withMinReplicas(minReplica)
                    .withMaxReplicas(maxReplica)
                    .addNewMetric()
                        .withType("Resource")
                        .withNewResource()
                            .withName("cpu")
                            .withNewTarget()
                                .withType("Utilization")
                                .withAverageUtilization(cpuAverageUtilization)
                            .endTarget()
                        .endResource()
                    .endMetric()
                    .addNewMetric()
                        .withType("Resource")
                        .withNewResource()
                            .withName("memory")
                            .withNewTarget() 
                                .withType("AverageValue")
                                .withAverageValue(new Quantity(memoryAverageValue))
                            .endTarget()
                        .endResource()
                    .endMetric()
                    .withNewBehavior()
                        .withNewScaleDown()
                            .addNewPolicy()
                                .withType("Pods")
                                .withValue(podScaleDownValue)
                                .withPeriodSeconds(podScaleDownPeriod)
                            .endPolicy()
                            .withStabilizationWindowSeconds(podScaledStabaliztionWindow)
                        .endScaleDown()
                    .endBehavior()
                .endSpec().build();
}

Any solution to delete HorizontalPodAutoscaler using fabric8's K8S Java client ver:6.0.0 will be appriciated.任何使用 fabric8 的 K8S Java 客户端版本:6.0.0 删除 HorizontalPodAutoscaler 的解决方案都将得到应用。

KubernetesHPAProducer.doDeleteHPA: To delete the HPA Autoscaler Pod follow this link KubernetesHPAProducer.doDeleteHPA:要删除 HPA Autoscaler Pod,请点击此链接

Below Might help you:以下可能对您有所帮助:

protected void doDeleteHPA(Exchange exchange, String operation) throws Exception {

   String hpaName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_HPA_NAME, String.class);

   String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);

   if (ObjectHelper.isEmpty(hpaName)) {

     LOG.error("Delete a specific hpa require specify a hpa name");

     throw new IllegalArgumentException("Delete a specific hpa require specify a hpa name");

   }

   if (ObjectHelper.isEmpty(namespaceName)) {

     LOG.error("Delete a specific hpa require specify a namespace name");

     throw new IllegalArgumentException("Delete a specific hpa require specify a namespace name");

   }

   boolean hpaDeleted = getEndpoint().getKubernetesClient().autoscaling().horizontalPodAutoscalers().inNamespace(namespaceName).withName(hpaName).delete();



   MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);

   exchange.getOut().setBody(hpaDeleted);

 }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用K8S Java客户端连接到Pod中的K8S API服务器 - How to connect to k8s api server within a pod using k8s java client 如何使用 fabric8 kubernetes java 客户端从部署的 pod 中读取文件? - How do I read a file from deployment's pods using fabric8 kubernetes java client? 使用Fabric8 Java客户端将Docker映像推送到远程注册表 - Push docker image to remote registry using fabric8 java client 如何使用fabric8 Java客户端API在Kubernetes中执行滚动更新和部署回滚? - How to perform Rolling update and Rollback of deployment in Kubernetes using fabric8 java client API? 如何使用 fabric8 java 客户端获取 kubernetes 服务帐户访问令牌? - How to get kubernetes service account access token using fabric8 java client? 如何使用用于Kubernetes的Fabric8 Java客户端创建NetworkPolicy - How to create a NetworkPolicy usingt he Fabric8 java client for Kubernetes 如何使用k8s-java-client在同一k8s集群上的同一服务的pod之间进行通信? - How to communicate between pods of the same service on the same k8s cluster using k8s-java-client? 使用Fabric8的Java库的Ingress Controller - Ingress Controller using Fabric8's Java library 如何使用Fabric8 Java API获取Kubernetes的nodePort? - How to get the nodePort using fabric8 java api for kubernetes? 您可以使用Java客户端API为K8S构建自定义控制器吗? - Can you build custom controller for K8S using the java client API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM