Spring Cloud Kubernetes 本地开发环境调试
import org.springframework.cloud.kubernetes.commons.KubernetesClient;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryClient;
import org.springframework.cloud.kubernetes.commons.fabric8.Fabric8Config;
import org.springframework.cloud.kubernetes.commons.fabric8.Fabric8PollingDiscoveryClient;
import org.springframework.cloud.kubernetes.commons.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8DiscoveryClient;
import org.springframework.cloud.kubernetes.fabric8.discovery.PodSpecHashAnnotationProvider;
import org.springframework.cloud.kubernetes.fabric8.discovery.PodUtils;
import org.springframework.cloud.kubernetes.fabric8.loadbalancer.Fabric8LoadBalancerClient;
import org.springframework.cloud.kubernetes.fabric8.reactive.Fabric8ReactiveDiscoveryClient;
import org.springframework.cloud.kubernetes.reactive.client.ReactiveKubernetesClient;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
// 配置本地开发环境的Kubernetes客户端
public class LocalKubernetesClientConfig {
public KubernetesClient kubernetesClient() {
Config config = new ConfigBuilder().withMasterUrl("https://localhost:8443").build();
return new KubernetesClient(config);
}
public KubernetesDiscoveryClient kubernetesDiscoveryClient() {
KubernetesClient kubernetesClient = kubernetesClient();
return new Fabric8DiscoveryClient(kubernetesClient, new PodSpecHashAnnotationProvider(), new PodUtils());
}
public LoadBalancerClient loadBalancerClient() {
KubernetesClient kubernetesClient = kubernetesClient();
return new Fabric8LoadBalancerClient(kubernetesClient);
}
public ReactiveKubernetesClient reactiveKubernetesClient() {
KubernetesClient kubernetesClient = kubernetesClient();
return new ReactiveKubernetesClient(kubernetesClient);
}
public Fabric8PollingDiscoveryClient fabric8PollingDiscoveryClient() {
KubernetesClient kubernetesClient = kubernetesClient();
return new Fabric8PollingDiscoveryClient(kubernetesClient, new PodSpecHashAnnotationProvider(), new PodUtils());
}
public Fabric8Config fabric8Config() {
return new Fabric8Config(kubernetesClient());
}
public KubernetesDiscoveryClient kubernetesReactiveDiscoveryClient() {
ReactiveKubern
评论已关闭