Proxy Istio上的Jgroups
我正试图让Jgroups集群在Istio上工作。没有istio我可以让它工作。总之,下面的代码将尝试将2个POD放入jgroups集群。当它们在集群中时,我希望看到Proxy Istio上的Jgroups,proxy,istio,jgroups,istio-sidecar,Proxy,Istio,Jgroups,Istio Sidecar,我正试图让Jgroups集群在Istio上工作。没有istio我可以让它工作。总之,下面的代码将尝试将2个POD放入jgroups集群。当它们在集群中时,我希望看到 NEIGHBORS: hello-0-19533 hello-1-21469 但是,当我使用istio注入将相同的代码部署到命名空间中时,我从未看到过这一点。我只看到这些豆荚独立存在。我错过了什么?我需要进行哪些配置才能使其正常工作?可能吗 我知道这可能与如何通过istio代理进行通信有关 我已使用以下清单部署了i
NEIGHBORS:
hello-0-19533
hello-1-21469
但是,当我使用istio注入将相同的代码部署到命名空间中时,我从未看到过这一点。我只看到这些豆荚独立存在。我错过了什么?我需要进行哪些配置才能使其正常工作?可能吗
我知道这可能与如何通过istio代理进行通信有关
我已使用以下清单部署了istio
apiVersion: v1
kind: Service
metadata:
name: hello
labels:
app: hello
spec:
clusterIP: None
ports:
- name: tcp-ping
protocol: TCP
port: 7950
targetPort: 7950
selector:
app: hello
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: hello
spec:
serviceName: "hello"
replicas: 2
selector:
matchLabels:
app: hello
template:
metadata:
labels:
app: hello
version: v1
spec:
containers:
- name: hello
image: jgroups_stu:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 7950
- containerPort: 7951
- containerPort: 7952
我的图像有以下代码
public class main {
public static void main(String[] args) throws Exception {
System.setProperty("java.net.preferIPv4Stack" , "true");
String basePath = main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
System.out.println("PATH: ".concat(basePath));
String inputFile = basePath.concat("test.xml");
String outputFile = basePath.concat("test2.xml");
Map<String, String> env = System.getenv();
String bind_addr = env.get("HOSTNAME");
String bind_port;
if(bind_addr == null) {
bind_addr = "localhost";
}
bind_port = "7950";
if(bind_addr.contains("1")) {
bind_addr = "172.17.0.4";
}else {
bind_addr = "172.17.0.3";
}
System.out.println("HOST: ".concat(bind_addr));
updateXml(inputFile, inputFile, "bind_addr", bind_addr);
updateXml(inputFile, inputFile, "bind_port", bind_port);
updateXml(inputFile, outputFile, "initial_hosts","127.0.0.1[7950],172.17.0.3[7950],172.17.0.4[7950]");
JChannel ch = new JChannel(outputFile);
ch.connect("TestCluster");
final int SLEEP_TIME_IN_MILLIS = 1000;
while (true) {
checkNeighbors(ch);
try {
Thread.sleep(SLEEP_TIME_IN_MILLIS);
} catch (InterruptedException e) {
// Ignored
}
}
}
private static void updateXml(String inputFile, String outputFile, String replaceKey, String replaceVal) throws SAXException, IOException, ParserConfigurationException, XPathExpressionException, TransformerFactoryConfigurationError, TransformerException {
// 1- Build the doc from the XML file
org.w3c.dom.Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(new InputSource(inputFile));
// 2- Locate the node(s) with xpath
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList)xpath.evaluate("//*[contains(@".concat(replaceKey).concat(", '!Here')]"),
doc, XPathConstants.NODESET);
//System.out.println( nodes.getLength());
// 3- Make the change on the selected nodes
for (int idx = 0; idx < nodes.getLength(); idx++) {
Node value = nodes.item(idx).getAttributes().getNamedItem(replaceKey);
String val = value.getNodeValue();
value.setNodeValue(val.replaceAll("!Here", replaceVal));
}
DOMSource domSource = new DOMSource(doc);
StringWriter outWriter = new StringWriter();
// 4- Save the result to a new XML doc
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(domSource, new StreamResult(outWriter));
xformer.transform(domSource, new StreamResult(new File(outputFile)));
StringBuffer sb = outWriter.getBuffer();
String finalstring = sb.toString();
System.out.println(finalstring);
}
private static void checkNeighbors(JChannel channel) {
View view = channel.getView();
List<Address> addresses = view.getMembers();
System.out.println("NEIGHBORS:");
for (Address address : addresses) {
System.out.println(" " + address);
}
}
}
公共类主{
公共静态void main(字符串[]args)引发异常{
setProperty(“java.net.preferIPv4Stack”,“true”);
字符串basePath=main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
System.out.println(“路径:.concat(basePath));
字符串inputFile=basePath.concat(“test.xml”);
字符串outputFile=basePath.concat(“test2.xml”);
Map env=System.getenv();
字符串bind_addr=env.get(“主机名”);
字符串绑定端口;
if(bind_addr==null){
bind_addr=“localhost”;
}
绑定_port=“7950”;
如果(绑定地址包含(“1”)){
bind_addr=“172.17.0.4”;
}否则{
bind_addr=“172.17.0.3”;
}
System.out.println(“主机:.concat(绑定地址));
updateXml(输入文件,输入文件,“绑定地址”,绑定地址);
updateXml(inputFile,inputFile,“绑定\u端口”,绑定\u端口);
updateXml(inputFile,outputFile,“初始_主机”,“127.0.0.1[7950],172.17.0.3[7950],172.17.0.4[7950]”;
JChannel ch=新JChannel(outputFile);
ch.connect(“测试集群”);
最终整型睡眠时间单位为1000;
while(true){
检查邻居(ch);
试一试{
睡眠(睡眠时间单位:毫秒);
}捕捉(中断异常e){
//忽略
}
}
}
私有静态void updateXml(String inputFile、String outputFile、String replaceKey、String replaceVal)引发SAXException、IOException、ParserConfiguration异常、XPathExpressionException、TransformerFactoryConfigurationError、TransformerException{
//1-从XML文件构建文档
org.w3c.dom.Document doc=DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(新的InputSource(inputFile));
//2-使用xpath定位节点
XPath=XPathFactory.newInstance().newXPath();
NodeList节点=(NodeList)xpath.evaluate(“/*[包含(@).concat(replaceKey).concat(“,”!Here')]),
doc,XPathConstants.NODESET);
//System.out.println(nodes.getLength());
//3-在所选节点上进行更改
对于(int idx=0;idx
test.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
<TCP bind_addr="!Here"
bind_port="!Here"
recv_buf_size="${tcp.recv_buf_size:130k}"
send_buf_size="${tcp.send_buf_size:130k}"
max_bundle_size="64K"
sock_conn_timeout="300"
thread_pool.min_threads="0"
thread_pool.max_threads="20"
thread_pool.keep_alive_time="30000"/>
<TCPPING async_discovery="true"
initial_hosts="${jgroups.tcpping.initial_hosts:!Here}"
port_range="2"/>
<MERGE3 min_interval="10000"
max_interval="30000"/>
<FD_SOCK/>
<FD timeout="3000" max_tries="3" />
<VERIFY_SUSPECT timeout="1500" />
<BARRIER />
<pbcast.NAKACK2 use_mcast_xmit="false"
discard_delivered_msgs="true"/>
<UNICAST3 />
<pbcast.STABLE desired_avg_gossip="50000"
max_bytes="4M"/>
<pbcast.GMS print_local_addr="true" join_timeout="2000"
view_bundling="true"/>
<MFC max_credits="2M"
min_threshold="0.4"/>
<FRAG2 frag_size="60K" />
<!--RSVP resend_interval="2000" timeout="10000"/-->
<pbcast.STATE_TRANSFER/>
</config>