Istio Java SDK API - 资源访问-VirtualService/Gateway/DestinationRule/ServiceEntry

2023-10-31

环境

参考上一篇文章

 

Java如何连接Istio

参考上一篇文章

 

访问Isito资源

  • VirtualService
  • Gateway
  • DestinationRule
  • ServiceEntry

 

项目源码

package com.you.micro.istiodemo.test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import me.snowdrop.istio.api.networking.v1alpha3.*;
import me.snowdrop.istio.client.IstioClient;

public class QueryIstio {

    public static final String ISTIO_NAMESPACE = "istio-system";

    public static void main(String[] args) {
        ConnectIstio connectIstio = new ConnectIstio();
        IstioClient istioClient = connectIstio.getIstioClient();

        QueryIstio queryIstio = new QueryIstio();
        queryIstio.queryServiceEntryList(istioClient);
        queryIstio.queryDestinationRuleList(istioClient);
        queryIstio.queryVirtualServiceList(istioClient);
        queryIstio.queryGateway(istioClient);

        connectIstio.closeIstioClient(istioClient);

    }

    public void queryVirtualServiceList(IstioClient istioClient) {

        ObjectMapper mapper = new ObjectMapper();
        if (istioClient == null) {
            return;
        }
        VirtualServiceList virtualServiceList = istioClient.virtualService().inNamespace(ISTIO_NAMESPACE).list();

        if (virtualServiceList == null || virtualServiceList.getItems() == null || virtualServiceList.getItems().size() == 0) {
            return;
        }
        for (int i = 0; i < virtualServiceList.getItems().size(); i++) {
            VirtualService virtualService = virtualServiceList.getItems().get(i);
            try {
                System.out.println(mapper.writeValueAsString(virtualService));
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }

    }

    public void queryGateway(IstioClient istioClient) {

        ObjectMapper mapper = new ObjectMapper();
        if (istioClient == null) {
            return;
        }
        Gateway gateway = istioClient.gateway().inNamespace(ISTIO_NAMESPACE).withName("ingressgateway").get();

        if (gateway != null) {
            try {
                System.out.println(mapper.writeValueAsString(gateway));
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }

        Gateway nullGateway = istioClient.gateway().inNamespace(ISTIO_NAMESPACE).withName("none").get();
        if (nullGateway == null) {
            System.out.println("Gateway is null");
        }

    }

    public void queryDestinationRuleList(IstioClient istioClient) {
        if (istioClient == null) {
            return;
        }
        DestinationRuleList ruleList = istioClient.destinationRule().inNamespace(ISTIO_NAMESPACE).list();
        if (ruleList == null || ruleList.getItems() == null || ruleList.getItems().size() == 0) {
            return;
        }
        ObjectMapper mapper = new ObjectMapper();
        for (int i = 0; i < ruleList.getItems().size(); i++) {
            DestinationRule destinationRule = ruleList.getItems().get(i);
            try {
                System.out.println(mapper.writeValueAsString(destinationRule));
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }
    }

    public void queryServiceEntryList(IstioClient istioClient) {
        if (istioClient == null) {
            return;
        }
//        ServiceEntryList entryList = istioClient.serviceEntry().inAnyNamespace().list();
        ServiceEntryList entryList = istioClient.serviceEntry().inNamespace("default").list();
        if (entryList == null || entryList.getItems() == null || entryList.getItems().size() == 0) {
            return;
        }
        ObjectMapper mapper = new ObjectMapper();
        try {
            System.out.println(mapper.writeValueAsString(entryList.getItems().get(0)));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

}
ServiceEntry-Json
{
	"apiVersion": "networking.istio.io/v1alpha3",
	"kind": "ServiceEntry",
	"metadata": {
		"annotations": {
			"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"networking.istio.io/v1alpha3\",\"kind\":\"ServiceEntry\",\"metadata\":{\"annotations\":{},\"name\":\"valid-service-entry\",\"namespace\":\"default\"},\"spec\":{\"endpoints\":[{\"address\":\"test.istio-system.svc.cluster.local\",\"ports\":{\"http\":8080}}],\"hosts\":[\"zh.bookinfo.com\"],\"ports\":[{\"name\":\"http\",\"number\":80,\"protocol\":\"HTTP\"}],\"resolution\":\"DNS\"}}\n"
		},
		"creationTimestamp": "2020-05-28T08:19:53Z",
		"generation": 1,
		"name": "valid-service-entry",
		"namespace": "default",
		"resourceVersion": "9848171",
		"selfLink": "/apis/networking.istio.io/v1alpha3/namespaces/default/serviceentries/valid-service-entry",
		"uid": "a27a4454-696f-4514-b44f-e71b34fe9ca5"
	},
	"spec": {
		"endpoints": [{
			"address": "test.istio-system.svc.cluster.local",
			"ports": {
				"http": 8080
			}
		}],
		"hosts": ["zh.bookinfo.com"],
		"ports": [{
			"name": "http",
			"number": 80,
			"protocol": "HTTP"
		}],
		"resolution": "DNS"
	}
}
DestinationRule-Json
{
	"apiVersion": "networking.istio.io/v1alpha3",
	"kind": "DestinationRule",
	"metadata": {
		"annotations": {
			"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"networking.istio.io/v1alpha3\",\"kind\":\"DestinationRule\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"istio-telemetry\",\"release\":\"istio\"},\"name\":\"istio-telemetry\",\"namespace\":\"istio-system\"},\"spec\":{\"host\":\"istio-telemetry.istio-system.svc.cluster.local\",\"trafficPolicy\":{\"connectionPool\":{\"http\":{\"http2MaxRequests\":10000,\"maxRequestsPerConnection\":10000}},\"portLevelSettings\":[{\"port\":{\"number\":15004},\"tls\":{\"mode\":\"ISTIO_MUTUAL\"}},{\"port\":{\"number\":9091},\"tls\":{\"mode\":\"DISABLE\"}}]}}}\n"
		},
		"creationTimestamp": "2020-04-19T22:38:38Z",
		"generation": 1,
		"labels": {
			"app": "istio-telemetry",
			"release": "istio"
		},
		"name": "istio-telemetry",
		"namespace": "istio-system",
		"resourceVersion": "3088834",
		"selfLink": "/apis/networking.istio.io/v1alpha3/namespaces/istio-system/destinationrules/istio-telemetry",
		"uid": "6a3016c5-34db-4019-b166-d658f0f732c4"
	},
	"spec": {
		"host": "istio-telemetry.istio-system.svc.cluster.local",
		"trafficPolicy": {
			"connectionPool": {
				"http": {
					"http2MaxRequests": 10000,
					"maxRequestsPerConnection": 10000
				}
			},
			"portLevelSettings": [{
				"port": {
					"number": 15004
				},
				"tls": {
					"mode": "ISTIO_MUTUAL"
				}
			}, {
				"port": {
					"number": 9091
				},
				"tls": {
					"mode": "DISABLE"
				}
			}]
		}
	}
}
VirtualService-Json
{
	"apiVersion": "networking.istio.io/v1alpha3",
	"kind": "VirtualService",
	"metadata": {
		"annotations": {
			"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"networking.istio.io/v1alpha3\",\"kind\":\"VirtualService\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"istio-egressgateway\",\"release\":\"istio\"},\"name\":\"istio-multicluster-egressgateway\",\"namespace\":\"istio-system\"},\"spec\":{\"gateways\":[\"istio-multicluster-egressgateway\"],\"hosts\":[\"*.global\"],\"tls\":[{\"match\":[{\"port\":15443,\"sniHosts\":[\"*.global\"]}],\"route\":[{\"destination\":{\"host\":\"non.existent.cluster\",\"port\":{\"number\":15443}},\"weight\":100}]}]}}\n"
		},
		"creationTimestamp": "2020-04-19T22:37:53Z",
		"generation": 1,
		"labels": {
			"app": "istio-egressgateway",
			"release": "istio"
		},
		"name": "istio-multicluster-egressgateway",
		"namespace": "istio-system",
		"resourceVersion": "3088352",
		"selfLink": "/apis/networking.istio.io/v1alpha3/namespaces/istio-system/virtualservices/istio-multicluster-egressgateway",
		"uid": "5d4c01ff-2bdd-4ca7-ad2c-baa4b6c029e2"
	},
	"spec": {
		"gateways": ["istio-multicluster-egressgateway"],
		"hosts": ["*.global"],
		"tls": [{
			"match": [{
				"port": 15443,
				"sniHosts": ["*.global"]
			}],
			"route": [{
				"destination": {
					"host": "non.existent.cluster",
					"port": {
						"number": 15443
					}
				},
				"weight": 100
			}]
		}]
	}
}

Gateway-Json

{
	"apiVersion": "networking.istio.io/v1alpha3",
	"kind": "Gateway",
	"metadata": {
		"annotations": {
			"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"networking.istio.io/v1alpha3\",\"kind\":\"Gateway\",\"metadata\":{\"annotations\":{},\"labels\":{\"release\":\"istio\"},\"name\":\"ingressgateway\",\"namespace\":\"istio-system\"},\"spec\":{\"selector\":{\"istio\":\"ingressgateway\"},\"servers\":[{\"hosts\":[\"*\"],\"port\":{\"name\":\"http\",\"number\":80,\"protocol\":\"HTTP\"}}]}}\n"
		},
		"creationTimestamp": "2020-04-19T22:38:06Z",
		"generation": 1,
		"labels": {
			"release": "istio"
		},
		"name": "ingressgateway",
		"namespace": "istio-system",
		"resourceVersion": "3088470",
		"selfLink": "/apis/networking.istio.io/v1alpha3/namespaces/istio-system/gateways/ingressgateway",
		"uid": "8baedf93-fb2e-4df9-a8f8-3326c9102593"
	},
	"spec": {
		"selector": {
			"istio": "ingressgateway"
		},
		"servers": [{
			"hosts": ["*"],
			"port": {
				"name": "http",
				"number": 80,
				"protocol": "HTTP"
			}
		}]
	}
}

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Istio Java SDK API - 资源访问-VirtualService/Gateway/DestinationRule/ServiceEntry 的相关文章

  • Guice 忽略注入构造函数参数上的 @Nullable

    我正在使用 Guice v 3 0 并且有一个值被注入到构造函数中 该值可以为 null 因此我在构造函数中使用 Nullable 来自 javax annotations 注释了该参数 public MyClass Parameter1
  • 带有 Android 支持库 v7 的 Maven Android 插件

    我使用 maven android plugin 构建我的 android 应用程序 它依赖于 android 支持库 v4 和 v7 由于我没有找到如何从developer android com下载整个sdk 因此我无法使用maven
  • 使用代理协议的 kubernetes nginx 入口最终出现损坏的标头

    我尝试使用代理协议在 google 容器上设置 nginx 入口 nodeport 以便可以将真实 IP 转发到后端服务 但最终导致标头损坏 2017 02 05 13 48 52 error 18 18 2 broken header H
  • 文本在指定长度后分割,但不要使用 grails 打断单词

    我有一个长字符串 需要将其解析为长度不超过 50 个字符的字符串数组 对我来说 棘手的部分是确保正则表达式找到 50 个字符之前的最后一个空格 以便在字符串之间进行彻底的分隔 因为我不希望单词被切断 public List
  • Logback:SizeAndTimeBasedRollingPolicy 不遵守totalSizeCap

    我正在尝试以一种方式管理我的日志记录 一旦达到总累积大小限制或达到最大历史记录限制 我最旧的存档日志文件就会被删除 当使用SizeAndTimeBasedRollingPolicy在 Logback 1 1 7 中 滚动文件追加器将继续创建
  • Spring数据中的本机查询连接

    我有课 Entity public class User Id Long id String name ManyToMany List
  • 在 MongoDB 和 Apache Solr 之间同步数据的简单方法

    我最近开始使用 MongoDB 和 Apache Solr 我使用 MongoDB 作为数据存储 并且希望 Apache Solr 为我的数据创建索引 以实现应用程序中的搜索功能 经过一些研究 我发现 基本上有两种方法可以在 MongoDB
  • 是否可以从 servlet 内部以编程方式设置请求上下文路径?

    这是一个特殊情况 我陷入了处理 企业 网络应用程序的困境 企业应用程序正在调用request getContext 并将其与另一个字符串进行比较 我发现我可以使用 getServletContext getContextPath 获取 se
  • 从休眠乐观锁定异常中恢复

    我有一个这样的方法 Transactional propagation Propagation REQUIRES NEW public void doSomeWork Entity entity dao loadEntity do some
  • 用于缓存的 Servlet 过滤器

    我正在创建一个用于缓存的 servlet 过滤器 这个想法是将响应主体缓存到memcached 响应正文由以下方式生成 结果是一个字符串 response getWriter print result 我的问题是 由于响应正文将不加修改地放
  • JAVA中遍历JSON数据

    我是 JSON 新手 我使用 HTTPUrlConnections 并在 JAVA 程序中获得一些响应 响应数据将类似于 data id 1 userId 1 name ABC modified 2014 12 04 created 201
  • Play.application() 的替代方案是什么

    我是 Play 框架的新手 我想读取conf文件夹中的一个文件 所以我用了Play application classloader getResources Data json nextElement getFile 但我知道 play P
  • IntelliJ 组织导入

    IntelliJ 是否具有类似于 Eclipse 中的组织导入功能 我拥有的是一个 Java 文件 其中多个类缺少导入 例子 package com test public class Foo public Map map public J
  • Lombok @Builder 不创建不可变对象?

    在很多网站上 我看到 lombok Builder 可以用来创建不可变的对象 https www baeldung com lombok builder singular https www baeldung com lombok buil
  • 我可以限制分布式应用程序发出的请求吗?

    我的应用程序发出 Web 服务请求 提供商处理的请求有最大速率 因此我需要限制它们 当应用程序在单个服务器上运行时 我曾经在应用程序级别执行此操作 一个对象跟踪到目前为止已发出的请求数量 并在当前请求超出允许的最大负载时等待 现在 我们正在
  • 如何在Java中对对象数组进行字段级别排序以进行等级比较?

    In Java Class StudentProgress String Name String Grade CTOR goes here main class main method StudentProgress arrayofObje
  • Hadoop NoSuchMethodError apache.commons.cli

    我在用着hadoop 2 7 2我用 IntelliJ 做了一个 MapReduce 工作 在我的工作中 我正在使用apache commons cli 1 3 1我把库放在罐子里 当我在 Hadoop 集群上使用 MapReduceJob
  • HttpClient请求设置属性问题

    我使用这个 HttpClient 库玩了一段时间 几周 我想以某种方式将属性设置为请求 不是参数而是属性 在我的 servlet 中 我想使用 Integer inte Integer request getAttribute obj 我不
  • 使用 JFreeChart 为两个系列设置不同的 y 轴

    我正在使用 JFreeChart 使用折线图绘制两个数据系列 XYSeries 复杂的因素是 其中一个数据系列的 y 值通常远高于第二个数据系列的 y 值 假设第一个系列的 y 值约为数百万数量级 而第二个数据系列的 y 值约为数百万数量级
  • 即使调整大小,如何获得屏幕的精确中间位置

    好的 这个问题有两部分 当我做一个JFrame 并在其上画一些东西 即使我将宽度设置为 400 并使其在一个项目击中它时 当然 允许项目宽度 它会反弹回来 但由于某种原因 它总是偏离屏幕约 10 个像素 有没有办法解决这个问题 或者我只需要

随机推荐

  • 带隔离变压器的DC/DC单端正激变换电路设计与Simulink仿真

    前期已经介绍了4种DC DC变换电路 这4种电路有一个共同特点 输入输出直接电气连接 之间没有做隔离措施 但是在实际应用中 由于电压等级的变换 安全 系统串并联等原因 开关电源的输入和输出之间需要进行电气隔离 在基本的非隔离DC DC变换电
  • R语言课程资料

    第一节 R语言简介 R语言简介 R 既是一种语言 R是一种解释性语言 也是一个软件由AT T贝尔实验室的S语言发展而来具有统计分析功能和强大的作图功能开源软件 目前在 R 网站上有 17500个程序包 涵盖了基础统计学 社会学 经济学 生态
  • 【ARM】在NUC977上搭建基于boa的嵌入式web服务器

    一 实验目的 搭建基于arm开发板的web服务端程序 通过网页控制开发板LED状态 二 boa简介 Boa服务器是一个小巧高效的web服务器 是一个运行于unix或linux下的 支持CGI的 适合于嵌入式系统的单任务的http服务器 源代
  • C# 调用SQL Server存储过程,传入参数,返回查询结果,更新dataGridView

    调用SQL Server存储过程 传入参数 返回查询结果 using SqlConnection conn new SqlConnection connectionString String cmdText Screen 存储过程名 Sql
  • Bible读经体会

    诸天述说 神的荣耀 穹苍传扬他的手段 诗篇19 1 花草树木在喊叫 耶和华造我的 数学从耶和华而来 自然界自然启示从耶和华而来 里面体现了耶和华的创意无限和思路周全 我们默默欣赏着观看着 今天阅读了创世纪的一点点体会 做下笔记 请勿用验证的
  • Shell--基础--01--介绍

    Shell 基础 01 介绍 1 Shell 环境 Shell 编程需要2个环境 文本编辑器 能解释执行的脚本解释器 2 Linux 的 Shell 常见种类 Bourne Shell usr bin sh或 bin sh Bourne A
  • python dataframe索引转成列_Pandas之DataFrame对象的列和索引之间的转化

    约定 import pandas as pd DataFrame对象的列和索引之间的转化 我们常常需要将DataFrame对象中的某列或某几列作为索引 或者将索引转化为对象的列 pandas提供了set index reset index
  • vue 项目中引用cdn上的静态js文件

    vue 项目中引用cdn上的静态js文件 需求 一份静态配置文件放在cdn中 文件暴露出数据列表和公共方法 读取文件的配置数据和公共方法 初始化Action列表 const cdnUrl https cdn xxx js libs vm a
  • Bat延时退出窗口

    timeout t 5
  • 【Error】ImportError: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29‘ not found

    参考文章 如何解决version GLIBCXX 3 4 29 not found的问题 1 问题 在 wsl ubuntu20 04 运行 yolov8 时 出现以下错误 ImportError lib x86 64 linux gnu
  • san.js源码解读之工具(util)篇——each函数

    一 迭代器模式 在开始解析源码之前 先来看一下 javascript 设计模式 迭代器模式 如果没有接触过该模式的小伙伴可能一脸疑惑 表示没听说过 但是这个迭代器模式 可能你已经用了很久了只是不知道它的名字罢了 比如 jquery中的 ea
  • 个位数统计 C语言

    1021 个位数统计 15 分 给定一个 k 位整数 N dk 1 10k 1 d1 101 d0 0 di 9 i 0 k 1 dk 1 gt 0 请编写程序统计每种不同的个位数字出现的次数 例如 给定 N 100311 则有 2 个 0
  • python萤火虫算法_萤火虫算法-python实现

    1 importnumpy as np2 from FAIndividual importFAIndividual3 importrandom4 importcopy5 importmatplotlib pyplot as plt6 7 8
  • FileNotFoundError: [Errno 2] No such file or directory: 'template/

    1 在运行generate list py时一直出现找不到templates header html和templates footer html的错误提示 2 后来才发现是路径问题 由于webapp是另外新建的目录 所以对yate py中w
  • Opencv使用cascade方法训练自己的LBP特征分类器的全过程

    前言 刚刚才把自己训练的分类器整出来 现在来理一下整个过程 从制作正负样本开始一直到最后产生自己的分类器 xml文件 因为毕设的要求 可能要用Opencv训练识别模型 用以识别道路积水 Opencv上自带的只有一些识别脸 眼睛等模型 所以要
  • 逻辑表达式三种化简方法

    逻辑表达式三种化简方法 目录 公式化简法 卡诺图化简法 机器化简法 一 公式法化简 是利用逻辑代数的基本公式 对函数进行消项 消因子 常用方法有 并项法 利用公式AB AB A 将两个与项合并为一个 消去其中的一个变量 吸收法 利用公式A
  • Unity WebGL Calls Rust Wasm

    Unity WebGL Calls Rust Wasm Jin Qing s Column May 2023 Reference https zenn dev ruccho articles 261136f7bdb003 In this a
  • 【通信原理】数字基带传输的线路码型

    数字基带传输的线路码型 简单介绍数字基带传输的线路码型的信号波形的特点 以及生成方法 注意观察频谱 文末附Matlab代码 以下包括双极性NRZ 单极型NRZ 双极型RZ 单极型RZ 差分码 曼切斯特码 数字双相码 密勒码 CMI码 AMI
  • STM32+二氧化碳传感器(FS00301)

    配置串口4 uart c u8 USART4 RX BUF USART REC LEN 接收缓冲 最大USART REC LEN个字节 u16 USART4 RX STA 0 接收状态标记 void uart4 init u32 bound
  • Istio Java SDK API - 资源访问-VirtualService/Gateway/DestinationRule/ServiceEntry

    环境 参考上一篇文章 Java如何连接Istio 参考上一篇文章 访问Isito资源 VirtualService Gateway DestinationRule ServiceEntry 项目源码 package com you micr