<p>Let's say I define a <code>Service</code> named <code>my-backend</code> in Kubernetes. I would like to intercept every request sent to this service, what is the proper way to do it? For example, another container under the same namespace sends a request through <a href="http://my-backend" rel="nofollow noreferrer">http://my-backend</a>. </p>

<p>I tried to use Admission Controller with a validation Webhook. However, it can intercept the CRUD operations on service resources, but it fails to intercept any connection to a specific service.</p>

<p>There is <a href="https://github.com/kubernetes/kubernetes/issues/11221" rel="nofollow noreferrer">no direct way</a> to intercept the requests to a service in Kubernetes.</p>

<p>For workaround this is what you can do-</p>

<ol>
<li><p>Create a sidecar container just to log the each incoming request. <a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/" rel="nofollow noreferrer">logging</a></p></li>
<li><p>Run <code>tcpdump -i eth0 -n</code> in your containers and filter out requests</p></li>
<li><p>Use <a href="https://www.getambassador.io/user-guide/tracing-tutorial-zipkin/" rel="nofollow noreferrer">Zipkin</a></p></li>
<li><p>Creating service on cloud providers, will have their own logging mechanism. for ex - load balancer service on aws will have its logs generated on S3. <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html" rel="nofollow noreferrer">aws elb logs</a></p></li>
</ol>
