无法访问kubernetes集群中的嵌入式ActiveMq [英] cannot access embedded ActiveMq within kubernetes cluster

查看:90
本文介绍了无法访问kubernetes集群中的嵌入式ActiveMq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在Java应用程序中启动嵌入式activeMq服务器.这将在kubernetes容器中运行.

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();

现在,我们有一个应用程序可以在同一个Pod中访问它.这很好.

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

但是,当另一个应用程序使用服务名称(例如tcp://service.hostname:41415)从另一个Pod访问此activemq服务器时,它将无法正常工作.

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

我还尝试向service.hostname添加连接器,但会抛出java.net.BindException: Address not available (Bind failed).

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");

有什么想法要解决吗?

我的Pod部署+服务Yaml看起来像

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

推荐答案

您必须公开该Pod的端口,以便其他服务可以访问它.

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

请参考: https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/

例如.

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

这篇关于无法访问kubernetes集群中的嵌入式ActiveMq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆