Skip to content

Commit 0fd404e

Browse files
authored
Merge pull request #41535 from Shubham82/wrap_IP-Masquerade-Agent
Improvement: Tweak line wrapping for the ip-masq-agent task page.
2 parents b9bb302 + 09fcbf5 commit 0fd404e

File tree

1 file changed

+56
-15
lines changed

1 file changed

+56
-15
lines changed

content/en/docs/tasks/administer-cluster/ip-masq-agent.md

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,69 @@ This page shows how to configure and enable the `ip-masq-agent`.
1414
<!-- discussion -->
1515
## IP Masquerade Agent User Guide
1616

17-
The `ip-masq-agent` configures iptables rules to hide a pod's IP address behind the cluster node's IP address. This is typically done when sending traffic to destinations outside the cluster's pod [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) range.
17+
The `ip-masq-agent` configures iptables rules to hide a pod's IP address behind the cluster
18+
node's IP address. This is typically done when sending traffic to destinations outside the
19+
cluster's pod [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) range.
1820

1921
### **Key Terms**
2022

2123
* **NAT (Network Address Translation)**
22-
Is a method of remapping one IP address to another by modifying either the source and/or destination address information in the IP header. Typically performed by a device doing IP routing.
24+
Is a method of remapping one IP address to another by modifying either the source and/or
25+
destination address information in the IP header. Typically performed by a device doing IP routing.
2326
* **Masquerading**
24-
A form of NAT that is typically used to perform a many to one address translation, where multiple source IP addresses are masked behind a single address, which is typically the device doing the IP routing. In Kubernetes this is the Node's IP address.
27+
A form of NAT that is typically used to perform a many to one address translation, where
28+
multiple source IP addresses are masked behind a single address, which is typically the
29+
device doing the IP routing. In Kubernetes this is the Node's IP address.
2530
* **CIDR (Classless Inter-Domain Routing)**
26-
Based on the variable-length subnet masking, allows specifying arbitrary-length prefixes. CIDR introduced a new method of representation for IP addresses, now commonly known as **CIDR notation**, in which an address or routing prefix is written with a suffix indicating the number of bits of the prefix, such as 192.168.2.0/24.
31+
Based on the variable-length subnet masking, allows specifying arbitrary-length prefixes.
32+
CIDR introduced a new method of representation for IP addresses, now commonly known as
33+
**CIDR notation**, in which an address or routing prefix is written with a suffix indicating
34+
the number of bits of the prefix, such as 192.168.2.0/24.
2735
* **Link Local**
28-
A link-local address is a network address that is valid only for communications within the network segment or the broadcast domain that the host is connected to. Link-local addresses for IPv4 are defined in the address block 169.254.0.0/16 in CIDR notation.
29-
30-
The ip-masq-agent configures iptables rules to handle masquerading node/pod IP addresses when sending traffic to destinations outside the cluster node's IP and the Cluster IP range. This essentially hides pod IP addresses behind the cluster node's IP address. In some environments, traffic to "external" addresses must come from a known machine address. For example, in Google Cloud, any traffic to the internet must come from a VM's IP. When containers are used, as in Google Kubernetes Engine, the Pod IP will be rejected for egress. To avoid this, we must hide the Pod IP behind the VM's own IP address - generally known as "masquerade". By default, the agent is configured to treat the three private IP ranges specified by [RFC 1918](https://tools.ietf.org/html/rfc1918) as non-masquerade [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing). These ranges are 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. The agent will also treat link-local (169.254.0.0/16) as a non-masquerade CIDR by default. The agent is configured to reload its configuration from the location */etc/config/ip-masq-agent* every 60 seconds, which is also configurable.
36+
A link-local address is a network address that is valid only for communications within the
37+
network segment or the broadcast domain that the host is connected to. Link-local addresses
38+
for IPv4 are defined in the address block 169.254.0.0/16 in CIDR notation.
39+
40+
The ip-masq-agent configures iptables rules to handle masquerading node/pod IP addresses when
41+
sending traffic to destinations outside the cluster node's IP and the Cluster IP range. This
42+
essentially hides pod IP addresses behind the cluster node's IP address. In some environments,
43+
traffic to "external" addresses must come from a known machine address. For example, in Google
44+
Cloud, any traffic to the internet must come from a VM's IP. When containers are used, as in
45+
Google Kubernetes Engine, the Pod IP will be rejected for egress. To avoid this, we must hide
46+
the Pod IP behind the VM's own IP address - generally known as "masquerade". By default, the
47+
agent is configured to treat the three private IP ranges specified by
48+
[RFC 1918](https://tools.ietf.org/html/rfc1918) as non-masquerade
49+
[CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing).
50+
These ranges are `10.0.0.0/8`, `172.16.0.0/12`, and `192.168.0.0 16`.
51+
The agent will also treat link-local (169.254.0.0/16) as a non-masquerade CIDR by default.
52+
The agent is configured to reload its configuration from the location
53+
*/etc/config/ip-masq-agent* every 60 seconds, which is also configurable.
3154

3255
![masq/non-masq example](/images/docs/ip-masq.png)
3356

34-
The agent configuration file must be written in YAML or JSON syntax, and may contain three optional keys:
57+
The agent configuration file must be written in YAML or JSON syntax, and may contain three
58+
optional keys:
3559

3660
* `nonMasqueradeCIDRs`: A list of strings in
37-
[CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) notation that specify the non-masquerade ranges.
61+
[CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) notation that specify
62+
the non-masquerade ranges.
3863
* `masqLinkLocal`: A Boolean (true/false) which indicates whether to masquerade traffic to the
3964
link local prefix `169.254.0.0/16`. False by default.
4065
* `resyncInterval`: A time interval at which the agent attempts to reload config from disk.
4166
For example: '30s', where 's' means seconds, 'ms' means milliseconds.
4267

43-
Traffic to 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16) ranges will NOT be masqueraded. Any other traffic (assumed to be internet) will be masqueraded. An example of a local destination from a pod could be its Node's IP address as well as another node's address or one of the IP addresses in Cluster's IP range. Any other traffic will be masqueraded by default. The below entries show the default set of rules that are applied by the ip-masq-agent:
68+
Traffic to 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 ranges will NOT be masqueraded. Any
69+
other traffic (assumed to be internet) will be masqueraded. An example of a local destination
70+
from a pod could be its Node's IP address as well as another node's address or one of the IP
71+
addresses in Cluster's IP range. Any other traffic will be masqueraded by default. The
72+
below entries show the default set of rules that are applied by the ip-masq-agent:
4473

4574
```shell
4675
iptables -t nat -L IP-MASQ-AGENT
4776
```
4877

4978
```none
79+
target prot opt source destination
5080
RETURN all -- anywhere 169.254.0.0/16 /* ip-masq-agent: cluster-local traffic should not be subject to MASQUERADE */ ADDRTYPE match dst-type !LOCAL
5181
RETURN all -- anywhere 10.0.0.0/8 /* ip-masq-agent: cluster-local traffic should not be subject to MASQUERADE */ ADDRTYPE match dst-type !LOCAL
5282
RETURN all -- anywhere 172.16.0.0/12 /* ip-masq-agent: cluster-local traffic should not be subject to MASQUERADE */ ADDRTYPE match dst-type !LOCAL
@@ -70,18 +100,26 @@ To create an ip-masq-agent, run the following kubectl command:
70100
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/ip-masq-agent/master/ip-masq-agent.yaml
71101
```
72102

73-
You must also apply the appropriate node label to any nodes in your cluster that you want the agent to run on.
103+
You must also apply the appropriate node label to any nodes in your cluster that you want the
104+
agent to run on.
74105

75106
```shell
76107
kubectl label nodes my-node node.kubernetes.io/masq-agent-ds-ready=true
77108
```
78109

79110
More information can be found in the ip-masq-agent documentation [here](https://github.com/kubernetes-sigs/ip-masq-agent)
80111

81-
In most cases, the default set of rules should be sufficient; however, if this is not the case for your cluster, you can create and apply a [ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/) to customize the IP ranges that are affected. For example, to allow only 10.0.0.0/8 to be considered by the ip-masq-agent, you can create the following [ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/) in a file called "config".
112+
In most cases, the default set of rules should be sufficient; however, if this is not the case
113+
for your cluster, you can create and apply a
114+
[ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/) to customize the IP
115+
ranges that are affected. For example, to allow
116+
only 10.0.0.0/8 to be considered by the ip-masq-agent, you can create the following
117+
[ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/) in a file called
118+
"config".
82119

83120
{{< note >}}
84-
It is important that the file is called config since, by default, that will be used as the key for lookup by the `ip-masq-agent`:
121+
It is important that the file is called config since, by default, that will be used as the key
122+
for lookup by the `ip-masq-agent`:
85123

86124
```yaml
87125
nonMasqueradeCIDRs:
@@ -96,7 +134,8 @@ Run the following command to add the config map to your cluster:
96134
kubectl create configmap ip-masq-agent --from-file=config --namespace=kube-system
97135
```
98136

99-
This will update a file located at `/etc/config/ip-masq-agent` which is periodically checked every `resyncInterval` and applied to the cluster node.
137+
This will update a file located at `/etc/config/ip-masq-agent` which is periodically checked
138+
every `resyncInterval` and applied to the cluster node.
100139
After the resync interval has expired, you should see the iptables rules reflect your changes:
101140

102141
```shell
@@ -111,7 +150,9 @@ RETURN all -- anywhere 10.0.0.0/8 /* ip-masq-agent:
111150
MASQUERADE all -- anywhere anywhere /* ip-masq-agent: outbound traffic should be subject to MASQUERADE (this match must come after cluster-local CIDR matches) */ ADDRTYPE match dst-type !LOCAL
112151
```
113152

114-
By default, the link local range (169.254.0.0/16) is also handled by the ip-masq agent, which sets up the appropriate iptables rules. To have the ip-masq-agent ignore link local, you can set `masqLinkLocal` to true in the ConfigMap.
153+
By default, the link local range (169.254.0.0/16) is also handled by the ip-masq agent, which
154+
sets up the appropriate iptables rules. To have the ip-masq-agent ignore link local, you can
155+
set `masqLinkLocal` to true in the ConfigMap.
115156

116157
```yaml
117158
nonMasqueradeCIDRs:

0 commit comments

Comments
 (0)