From what I understand, when a POD talks to a Service the IP tables have been updated by a CNI provider (this may be specific to some but not all CNI providers). The iptables have basically provided a virtual IP that then round robins or distributes (somehow) to backend ephemeral pods. Those pods may live on the same host or another host in the cluster. At this point (again based on the CNI) conntrack is used to keep src and dst straight as it remaps the svc-ip to the dest-ip of the POD. What I'm wondering though, is if the dest pod is on the same host, I'm not certain how it is routed on the return path. I would suspect via the service still and then possibly using conntrack for the return path.
Does kubernetes use conntrack twice when a pod talks to a pod through a service where the destination pod is on the same host?
I will use Calico as an example while trying to explain this topic.
Conntrack is only required from the source pod to the service endpoints. You have to track it to send rest of flow packets to the same destination endpoint. The return path always has only one option: from the destination pod to the source pod which means that even if conntrack is used here it doesn't change anything as the return path is managed by the NAT table.
Also worth mentioning:
You can use
conntrackcommand line interface in order search, list, inspect and maintain the connection tracking subsystem of the Linux kernel.For example:
conntrack -Lwill show the connection tracking table in /proc/net/ip_conntrack format:A practical example would be when you change Calico's policy to disallow a flow that was previously allowed. Calico only needs to check its policies for the first packet in an allowed flow—between a pair of IP addresses and ports—and then conntrack automatically allows further packets in the same flow, without Calico rechecking every packet. If packets were recently exchanged on the previously allowed flow, and so there is conntrack state for that flow that has not yet expired, that conntrack state will allow further packets between the same IP addresses and ports, even after the Calico policy has been changed. To avoid that you could delete the relevant conntrack states manually with
conntrack -Dand than useconntrack -Ein order to observe the connection events with a new Calico policy.Sources:
Linux Conntrack
Connection tracking
Kube-proxy modes
Packet flow
I hope this helps.