Skip to content

jmorris/document k8s pr 77523#36

Open
MorrisLaw wants to merge 2 commits intocontributing-to-kubernetes:masterfrom
MorrisLaw:jmorris/document-k8s-pr-77523
Open

jmorris/document k8s pr 77523#36
MorrisLaw wants to merge 2 commits intocontributing-to-kubernetes:masterfrom
MorrisLaw:jmorris/document-k8s-pr-77523

Conversation

@MorrisLaw
Copy link
Contributor

WIP PR for Issue #35

This was a tough one. Will likely need a few more edits. Please review @alejandrox1 😄

@MorrisLaw MorrisLaw force-pushed the jmorris/document-k8s-pr-77523 branch from 1d92016 to 0d76d50 Compare April 5, 2020 03:28
Copy link
Collaborator

@alejandrox1 alejandrox1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review done!
And awesome writeup @MorrisLaw !

Comment on lines +15 to +19
```
"Iptables and ip6tables are used to set up, maintain, and inspect the tables of IPv4 and IPv6 packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user-defined chains.

Each chain is a list of rules which can match a set of packets. Each rule specifies what to do with a packet that matches. This is called a 'target', which may be a jump to a user-defined chain in the same table."
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we break this into more lines?
It renders into 2 long lines that you have to scroll for


In the context of `Kubernetes`, the `iptables proxier` is described as follows:
```
Proxier is an `iptables` based proxy that is used for connections between a localhost:lport and services that provide the actual backends.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localhost:lport , is that intentional?


### What are iptables?

In order to understand what the `iptables proxier` is and does, we first have to understand what `iptables` are and why they are relevant.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write a short snippet introducing the "iptables proxier" before this line?
It reads like it just came out of nowhere.


## Description

This write up is on [PR #77523](https://github.com/kubernetes/kubernetes/pull/77523) and [PR #78662](https://github.com/kubernetes/kubernetes/pull/78662). This PR re-routes traffic that originates from the local node, so that it goes to the Kubernetes service chain.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 This PR re-routes traffic that originates from the local node, so that it goes to the Kubernetes service chain.

Is superfluous given the next sentence.

Comment on lines +38 to +50
```go
// Next, redirect all src-type=LOCAL -> LB IP to the service chain for externalTrafficPolicy=Local
// This allows traffic originating from the host to be redirected to the service correctly,
// otherwise traffic to LB IPs are dropped if there are no local endpoints.
args = append(args[:0], "-A", string(svcXlbChain))
writeLine(proxier.natRules, append(args,
"-m", "comment", "--comment", fmt.Sprintf(`"masquerade LOCAL traffic for %s LB IP"`, svcNameString),
"-m", "addrtype", "--src-type", "LOCAL", "-j", string(KubeMarkMasqChain))...)
writeLine(proxier.natRules, append(args,
"-m", "comment", "--comment", fmt.Sprintf(`"route LOCAL traffic for %s LB IP to service chain"`, svcNameString),
"-m", "addrtype", "--src-type", "LOCAL", "-j", string(svcChain))...)
```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renders weird.
Could you add surrounding context?
For example,

func DoSomething(args) error {
  ...
  args = append(args[:0], "-A", string(svcXlbChain))
  ...
}

Also, enough context to be able to tell what the args (is it a slice?) are, what svcXLBChain ()is it a string) is, what the proxier.natRules (this one i know is a struct from the block below) is etc.

```go
// Proxier is an iptables based proxy for connections between a localhost:lport
// and services that provide the actual backends.
type Proxier struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be introduce this bit beforehand?
It helps make sense of the code above.

Comment on lines +70 to +75
// endpointsChanges and serviceChanges contains all changes to endpoints and
// services that happened since iptables was synced. For a single object,
// changes are accumulated, i.e. previous is state from before all of them,
// current is state after applying all of those.
endpointsChanges *proxy.EndpointChangeTracker
serviceChanges *proxy.ServiceChangeTracker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all the fields here needed?
This write up only mentions some of of them.

Comment on lines +160 to +164
```go
writeLine(proxier.natRules, append(args,
"-m", "comment", "--comment", fmt.Sprintf(`"route LOCAL traffic for %s LB IP to service chain"`, svcNameString),
"-m", "addrtype", "--src-type", "LOCAL", "-j", string(svcChain))...)
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be cool if we could translate these snippets into the actual command being run.
Kinda like "hey, if you want to reproduce it yourself by hand, this is what is being done".

Comment on lines +173 to +181
In this PR, we got a glimpse into the use of `NAT rules`, `iptables` and how the `iptabels proxier`, within Kubernetes, handles connections from local traffic, to the LB, to a service.

As a community, it is important to keep on learning and sharing the knowledge we gain from our experiences.

```
"We are only as strong as we are united, as weak as we are divided."

― J.K. Rowling, Harry Potter and the Goblet of Fire
``` No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the conclusion!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants