Intercept/capture incoming traffic to pods/services in Kubernetes

1/19/2018

I'm using Openshift and Kubernetes as cloud platform for my application. For test purposes I need to intercept incoming http requests to my pods. Is this possible to do that with Kubernetes client library or maybe it can be configured with yaml?

-- Jeff
kubernetes
openshift

2 Answers

1/19/2018

Simple answer is no, you can't.

One of the ways to overcome this is to exec into your container (kubectl exec -it <pod> bash), install tcpdump and run something like tcpdump -i eth0 -n.

A more reasonable way to have it solved on infra level is to use some tracing tool like Jaeger/Zipkin

-- Radek 'Goblin' Pieczonka
Source: StackOverflow

1/2/2019

You can try something like below it will work. First you need create a job. Let's say with name (tcpdumppod.yaml)

apiVersion: batch/v1
kind: Job
metadata:
  name: tcpdump-capture-job
  namespace: blue
spec:
  template:
    metadata:
      name: "tcpdumpcapture-pod"
    spec:
      hostNetwork: true
      nodeSelector:
        kubernetes.io/hostname: "ip-xx-x-x-xxx.ap-south-1.compute.internal"
      tolerations:
        - key: node-role.kubernetes.io/master
          effect: NoSchedule
      containers:
      - name: "job-container"
        image: "docker.io/centos/tools"
        command: ["/bin/bash", "-c", "--"]
        args: [ "tcpdump -i any -s0 -vv -n dst host 10.233.6.70 and port 7776 || src 10.233.64.23" ]
      restartPolicy: Never 
  backoffLimit: 3
  activeDeadlineSeconds: 460

\=> kubectl create -f tcpdumppod.yaml And check the pod logs which is created by the job when the container is running.

-- shoaib
Source: StackOverflow