cannot access embedded ActiveMq within kubernetes cluster

℡╲_俬逩灬. 提交于 2020-06-29 03:53:07

问题


We are starting an embedded activeMq server in our java application. This will run in a kubernetes pod.

broker = BrokerFactory.createBroker("broker:(tcp://localhost:41415)?persistent=false");
broker.setBrokerId("ActiveMqBroker" + 1);
broker.setUseJmx(false);
broker.start();

Now we have one application which accesses it inside the same pod. This works fine.

However when another application accesses this activemq server from another pod using service name like tcp://service.hostname:41415 then it does not work.

I also tried adding a connector to service.hostname but it throws java.net.BindException: Address not available (Bind failed).

broker.addConnector("tcp://service.hostname:41415");

Any idea how to fix it?

Edit:

My pod deployment+service yaml looks like

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
  labels:
    app: activemq
spec:
  replicas: 1
  selector:
    matchLabels:
      app: activemq
  template:
    metadata:
      labels:
        app: activemq
    spec:
      containers:
      - name: activemq
        image: <myimage>
        ports:
        - containerPort: 41415

apiVersion: v1
kind: Service
metadata:
  name: service.hostname
spec:
  selector:
    app: activemq
  ports:
    - protocol: TCP
      port: 41415
      targetPort: 41415

回答1:


You have to expose the ports for that pod, so that other services can access it.

Please refer: https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/

ex.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
spec:
  selector:
    matchLabels:
      app: hello
      tier: backend
      track: stable
  replicas: 7
  template:
    metadata:
      labels:
        app: hello
        tier: backend
        track: stable
    spec:
      containers:
        - name: hello
          image: "gcr.io/google-samples/hello-go-gke:1.0"
          ports:
            - name: http
              containerPort: 80


来源:https://stackoverflow.com/questions/62313720/cannot-access-embedded-activemq-within-kubernetes-cluster

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!