我该如何在Kubernetes中通过边车容器与吊舱对话? [英] How do I talk to a pod from sidecar container in Kubernetes?

查看:93
本文介绍了我该如何在Kubernetes中通过边车容器与吊舱对话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能从侧面的集装箱与豆荚交谈...任何帮助将不胜感激!

I cannot talk to a pod from side car container... any help will be appreciated!

这是我的部署

---
apiVersion: extensions/v1beta1
kind: Deployment

metadata:
   name: sidecar-deployment

spec:
replicas: 1

template:
    metadata:
       labels:
          app: sidecar
    spec:
      containers:
      - name: sidecar1
        image: sidecar
        args:
        - /sidecar
        - --port=32000
        - --path=/sidecar1
        ports:
        - containerPort: 32000
      - name: sidecar2
        image: sidecar
        args:
        - /sidecar
        - --port=32001
        - --path=/sidecar2
        ports:
        - containerPort: 32001

这是我对豆荚的服务

---
apiVersion: v1
kind: Service

metadata:
  name: sidecar-service

spec:
  ports:
  - name: http
    port: 80
    targetPort: 32001
    protocol: TCP

selector:
  app: sidecar
type: NodePort

部署入口之后,我可以连接到服务和sidecar2,因为sidecar2是通过服务公开的:

After deploying ingress, I can connect to the service and sidecar2, because sidecar2 is exposed via service:

# this works
curl -L http://ADDR/sidecar2

但是,我希望能够卷曲到侧面容器,但是我不能.

But, I was expecting to be able to curl to the side container, but I can't.

这就是我所做的.我把它放进杂物箱中.并用localhost卷曲同一位置的吊舱:

This is what I did. I ssh into the sidecar container. And curl the colocated pod with localhost:

kubectl exec -it sidecar2 -- /bin/bash
# this doesn't work
curl -L http://localhost:32000/sidecar1

有人可以帮我吗?

谢谢!

推荐答案

如果sidecar映像公开了端口(请重新检查dockefile),则必须连接curl localhost:port/sidecar

If your sidecar image exposes the port (recheck your dockefile), you must connect with curl localhost:port/sidecar

如果您在使用服务从容器内部连接时遇到问题,则可能与

If you have problem connecting from inside the container using the service it may be related to hairpin_mode.

这篇关于我该如何在Kubernetes中通过边车容器与吊舱对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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