Kubernetes Java客户端具有sdk函数来创建部署,服务和许多其他核心kubernetes函数。如何从kubernetes Java客户端访问自定义资源,例如istio的服务条目,目标规则,虚拟服务等资源?
最佳答案
要连接到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);