Tomoko-hjf opened a new issue, #274: URL: https://github.com/apache/dubbo-spi-extensions/issues/274
# 本地连接`Istio`控制面开发环境搭建 为了更加方便地在本地进行`dubbo-xds`相关功能的开发调试,我们需要一个提供`资源注册分发`功能的控制面。本文旨在搭建一个`Istio`控制面,本地直接连接`Istio`控制面,方便开发调试。 关于远程调试可以参考这篇文章 https://cn.dubbo.apache.org/zh-cn/overview/mannual/java-sdk/reference-manual/mesh/mesh/ ## 搭建kubenets集群 本步骤目的在于搭建`kubenets`集群,如果已有`kubebets`集群可跳过此步骤。 建议采用`Docker Desktop`来搭建`kubenets`集群,`Docker Desktop`内置简单的`kubebets`集群并提供可视化界面,使用非常方便。 下面演示`Windows`如何安装,`Mac`及其他系统可参照官网 https://docs.docker.com/desktop/install/mac-install/ 安装。 `Windows`需要借助`wsl`服务来运行`Docker Desktop`。首先需要在控制面板启动`wsl`功能。  启动后建议终端执行命令`wsl --update`升级`wsl`服务。 安装好后打开`Docker Desktop`,建议第一次打开时注册账号登录,否则容易卡在初始化界面。 在设置中开启`kubenets`集群,应用并重启。  ## 搭建istio环境 ### 安装Istio `Istio`安装文档(https://istio.io/latest/docs/setup/getting-started/) > 注:安装`Istio`的时候需要开启`first-party-jwt`支持(使用`istioctl`工具安装的时候加上`–set values.global.jwtPolicy=first-party-jwt`参数),否则将导致客户端认证失败的问题。 附安装命令参考: ```shell # 下载安装包,也可以从https://github.com/istio/istio/releases/tag/1.20.1手动下载 curl -L https://istio.io/downloadIstio | sh - # 进入到bin目录 cd istio-1.xx.x/bin # 安装istio istioctl install --set profile=demo --set values.global.jwtPolicy=first-party-jwt -y ``` ### 开放istio端口 `istiod`是`Istio`控制面所在的`pod`,可以通过端口转发实现本地访问集群中的控制面`istiod`。 首先通过命令`kubectl get pods -n istio-system`查看`istiod`所在的`pod`名称。  然后使用命令`kubectl port-forward pod名称 15010:15010 -n istio-system`转发端口`15010`。`pod`名称为`istiod`所在的`pod`名称,这样就可以通过本地`15010`端口访问`istio`的控制面。 ## 本地调试 ### 下载dubbo-spi-extensions代码 https://github.com/apache/dubbo-spi-extensions ### 修改源码 与`istiod`建立连接时需要从`pod`读取认证文件,所以我们需要修改源码`IstioConstant`类的`KUBERNETES_SA_PATH`变量,将其改成本地存在的路径,例如`E:/k8s/token`。并在该路径下新建`token`文件,不带任何后缀,里面内容可以为空。  ### 测试连接 接下来可以在控制台通过`kubectl apply -f xxx.yml`命令部署资源,下面是一个资源示例: ```yml apiVersion: v1 kind: Service metadata: name: details labels: app: details service: details spec: ports: - port: 9080 name: http selector: app: details --- apiVersion: apps/v1 kind: Deployment metadata: name: details-v1 labels: app: details version: v1 spec: replicas: 1 selector: matchLabels: app: details version: v1 template: metadata: labels: app: details version: v1 spec: serviceAccountName: bookinfo-details containers: - name: details image: docker.io/istio/examples-bookinfo-details-v1:1.18.0 imagePullPolicy: IfNotPresent ports: - containerPort: 9080 ``` 在集群中部署资源后,可以在源码`XdsRouteTest`类下新建测试用例访问`控制面`获取资源。 该单测通过访问本机`15010`端口连接控制面,注意`URL`的后缀`secure=plaintext`,表示不加密。 ```java @Test public void testXdsRouterInitial() { BitList<Invoker<Object>> invokers = new BitList<>(Arrays.asList(createInvoker(""), createInvoker("app1"))); URL url = URL.valueOf("test://localhost:15010/?secure=plaintext"); PilotExchanger.initialize(url); XdsRouter<Object> xdsRouter = new XdsRouter<>(url, rdsRouteRuleManager, edsEndpointManager, true); xdsRouter.notify(invokers); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org