How do I talk to a pod from sidecar container in Kubernetes?
Asked Answered
D

1

6

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

Here's my deployment

---
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

And here's my service to the pod

---
apiVersion: v1
kind: Service

metadata:
  name: sidecar-service

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

selector:
  app: sidecar
type: NodePort

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.

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

Can somebody help me on this?

Thanks!

Deledda answered 2/9, 2018 at 0:44 Comment(1)
I guess sidecar1 is not listening at localhost, try curl -L http://pod-id:32000/sidecar1Arce
G
5

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.

Goatsucker answered 2/9, 2018 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.