Closed usernameisnull closed 5 months ago
PTAL @caigy
BROKER_NETWORK_DEV=`/sbin/route |awk '/^default/{print $NF}'`
BROKER_IP=`ip a s ${BROKER_NETWORK_DEV} |awk -F' +|/' '/ inet /{print $3}'`
echo "brokerIP1=${BROKER_IP}" >> $BROKER_CONFIG_FILE
You can try this instead, that doesn't require manual IP specification, it works for me.
BROKER_NETWORK_DEV=`/sbin/route |awk '/^default/{print $NF}'` BROKER_IP=`ip a s ${BROKER_NETWORK_DEV} |awk -F' +|/' '/ inet /{print $3}'` echo "brokerIP1=${BROKER_IP}" >> $BROKER_CONFIG_FILE
You can try this instead, that doesn't require manual IP specification, it works for me.
thank you, I will try this
PTAL @caigy
when the broker uses hostNetwork, the IP registered by the broker to the nameserver is not the podIP related #202 #159
What is the purpose of the change
when the broker uses hostNetwork, the broker's IP returned by NameServer is the IP of the k8s node where the broker is located.
This is because the broker uses the cluster ip(or other ip) instead of its own pod ip when registering.
The root cause is that when using hostnetwork, the host's network is used, including /etc/hosts. When generating the
brokerIP1
configuration project, use thehostname -i
command in theimages/broker/alpine/brokerGenConfig.sh
to obtain the ip./images/broker/alpine/brokerGenConfig.sh#L30
but in many cases this command does not correctly obtain the correct ip. for exampels:
bash-4.4# hostname -i 127.0.1.1
when use
127.0.1.1
to register, the nameserver will select the IP based on its own algorithm. Most of the time it is not the status.podIP of the pod we want: https://github.com/apache/rocketmq/blob/2c898c9b31bf195174cf1e3a626a7c61f7576381/common/src/main/java/org/apache/rocketmq/common/utils/NetworkUtil.java#L91bash-4.4# hostname -i 127.0.1.1 10.6.178.178
check the log, it seems to be successful![image](https://github.com/apache/rocketmq-operator/assets/3390414/ca077eca-da5b-4e68-982d-5890bdc8221e)
but when we used the mqadmin command to check the registered broker address, we found that this was not the case.![image](https://github.com/apache/rocketmq-operator/assets/3390414/2a127dd2-0ae0-4008-937c-a94c3fcb5f46)
Brief changelog
When setting up with hostNetwork option, we explicitly add an environment variable
HOST_NETWORK_POD_IP
on the pod. When obtainingbrokerIP1
, we obtain it from this environment variable and register it with the nameserver.Verifying this change
the log from the pod:![image](https://github.com/apache/rocketmq-operator/assets/3390414/675c3b9c-25e9-4f3e-830e-e437cdf416ce)
the podIP:![image](https://github.com/apache/rocketmq-operator/assets/3390414/015b74e6-ebaf-4516-bece-0fdfa900fbdd)
use mqadmin see the broker address:![image](https://github.com/apache/rocketmq-operator/assets/3390414/ffe169ea-ddfb-434e-8f6c-7c2e586f93b5)
Please go through this checklist to help us incorporate your contribution quickly and easily.
Notice:
It would be helpful if you could finish the following checklist (the last one is not necessary) before request the community to review your PR
.[ISSUE #123] Fix UnknownException when host config not exist
. Each commit in the pull request should have a meaningful subject line and body.make docker-build
to build docker image for operator, try your changes from Pod inside your Kubernetes cluster, not just locally. Also provide screenshots to show that the RocketMQ cluster is healthy after the changes.make manifests
to make sure the CRD files are updated.