Lets learn "About kube proxy in iptables mode"
In this tutorial, we'll learn about the Kube-proxy in iptables mode. Basically, we'll see how Kube-proxy create iptables that help in load balancing and service discovery. If you are not familiar with Linux IPTables I would recommend to check out my tutorial on IPTables here first and then come back to read this tutorial.
Kube-proxy
Kube-proxy added IPTables
>> iptables -t nat -L
Chain KUBE-SERVICES (2 references)
target prot opt source destination
KUBE-MARK-MASQ tcp -- !100.96.0.0/17 100.96.128.2 /* kube-system/FOO:foo cluster IP */ tcp dpt:9153
KUBE-SVC-QKJQYQZXY3DRLPVB tcp -- anywhere 100.96.128.2 /* kube-system/FOO:foo cluster IP */ tcp dpt:9153
KUBE-NODEPORTS all -- anywhere anywhere /* kubernetes service nodeports; NOTE: this must be the last rule in this chain */ ADDRTYPE match dst-type LOCAL
Chain KUBE-SVC-QKJQYQZXY3DRLPVB (1 references)
target prot opt source destination
KUBE-SEP-3UIFCWUMBYEVXRYP all -- anywhere anywhere statistic mode random probability 0.33333333349
KUBE-SEP-QSKKIZFW3PNDWYKJ all -- anywhere anywhere statistic mode random probability 0.50000000000
KUBE-SEP-PIHAV4BKXEANYKSM all -- anywhere anywhere
- As we know that IPTables rules are processed in order, Since there are three options when the control reaches the first rule since there are three options to chose the probability of choosing the first rule is 1/3 = 0.3333
- When the control reaches the second rule, the choices remaining are 2, hence probability of choosing the second rule is 1/2 = 0.5000
- And finally, when the control reaches 3rd rule, there are no more choices left so that is the only option. So the probability of choosing that at that point is 1.
Chain KUBE-SEP-3UIFCWUMBYEVXRYP (1 references)
target prot opt source destination
KUBE-MARK-MASQ all -- 100.96.0.2 anywhere
DNAT udp -- anywhere anywhere udp to:100.96.0.2:9153
Chain KUBE-SEP-QSKKIZFW3PNDWYKJ (1 references)
target prot opt source destination
KUBE-MARK-MASQ all -- 100.96.32.2 anywhere
DNAT udp -- anywhere anywhere udp to:100.32.64.2:9153
Chain KUBE-SEP-PIHAV4BKXEANYKSM (1 references)
target prot opt source destination
KUBE-MARK-MASQ all -- 100.96.64.2 anywhere
DNAT udp -- anywhere anywhere udp to:100.96.64.2:9153
finally, you must have understood each of the three chains contains a rule to redirect traffic to one of the pods.
Comments
Post a Comment