Kubernetes Java客户端具有sdk函数,用于创建部署,服务和许多其他核心kubernetes函数。如何从kubernetes java客户端访问自定义资源,例如istio的服务条目,目标规则,虚拟服务?
答案 0 :(得分:2)
要连接到Istio,可以使用项目 istio-java-api 。该项目使用与Fabric8的kubernetes模型相同的方法。 下面的示例显示了如何构建和创建VirtualService:
import me.snowdrop.istio.api.networking.v1alpha3.ExactMatchType;
import me.snowdrop.istio.api.networking.v1alpha3.VirtualService;
import me.snowdrop.istio.api.networking.v1alpha3.VirtualServiceBuilder;
import me.snowdrop.istio.client.DefaultIstioClient;
import me.snowdrop.istio.client.IstioClient;
Config config = new ConfigBuilder().withMasterUrl(masterURL).build();
IstioClient istioClient = new DefaultIstioClient(config);
VirtualService virtualService = new VirtualServiceBuilder()
.withApiVersion("networking.istio.io/v1alpha3")
.withNewMetadata()
.withName("details")
.endMetadata()
.withNewSpec()
.withHosts("*")
.withGateways("system-gateway")
.addNewHttp()
.addNewRoute()
.withNewDestination()
.withHost("service-example")
.withNewPort()
.withNewNumberPort(9900)
.endPort()
.endDestination()
.endRoute()
.endHttp()
.endSpec()
.build();
istioClient.virtualService().create(virtualService);