Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

minikube - Kubernetes pod unable to connect to rabbit mq instance running locally

I am moving my application from docker to kubernetes helm - and so far I have been successful except for setting up incoming outgoing connections.

One particular issue I am facing is that I am unable to connect to the rabbitmq instance running locally on my machine on another docker container.

app-deployment.yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jks
  labels:
    app: myapp
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: myapp
    spec:
      imagePullSecrets:
      - name: ivsecret
      containers:
      - env:
        - name: JOBQUEUE
          value: jks_jobqueue
        - name: PORT
          value: "80"
        image: repo.url
        name: jks
        ports:
        - containerPort: 80
        volumeMounts:
          - name: config-vol
            mountPath: /etc/sys0
      volumes:
        - name: config-vol
          configMap:
            name: config

      restartPolicy: Always

------------

app-service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: jks
spec:
  ports:
  - name: "80"
    port: 80
    targetPort: 80
  selector:
    app: myapp

I see errors on my container, complaining that it is not able to connect to my machine. I tried curl from inside the container:

curl 10.2.10.122:5672
curl: (7) Failed to connect to 10.20.11.11 port 5672: Connection timed out

But the same when I deploy as a docker container works fine - and I am able to connect to the rabbit mq instance running on my machine on port 5672.

Is there something I would need to do to set up a connection from the pod to my local machine?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are exposing port 80 for both, the pod and the service. Then you curl on port 5672.

Either expose port 5672 of the pod and curl it directly, or expose port 5672 of the service and keep port 80 on the pod, and curl on port 5672 of the service.

This would be a high level "sketch" of how to hit a pod:

you -curl-> service1(80:80) -> pod1(80)
you -curl-> service2(80:5672) -> pod2(5672)

So say you have two pods. One of them is serving on port 80, and the other one on port 5672. You can create two services; each of them targeting one pod. The services can be running on port 80 and map the requests to the ports 80 and 5672 of the pods.

Now you can't make one service to do the both forwarding. Needs to be one service per pod. Can be a deployment, or a group of pods, but these need to be serving on the same port.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...