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 的相关文章

随机推荐

  • 带隔离变压器的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