Skip to content

Commit b68cfbd

Browse files
authored
Merge pull request #32485 from tengqm/fix-ip-masq-agent
Fix the ip-masq-agent page
2 parents e58fca0 + 3b21d5b commit b68cfbd

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed

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

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,48 @@ content_type: task
44
---
55

66
<!-- overview -->
7-
This page shows how to configure and enable the ip-masq-agent.
8-
7+
This page shows how to configure and enable the `ip-masq-agent`.
98

109
## {{% heading "prerequisites" %}}
1110

12-
1311
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
1412

15-
16-
1713
<!-- discussion -->
1814
## IP Masquerade Agent User Guide
1915

20-
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.
16+
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.
2117

2218
### **Key Terms**
2319

24-
* **NAT (Network Address Translation)**
25-
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.
26-
* **Masquerading**
27-
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.
28-
* **CIDR (Classless Inter-Domain Routing)**
29-
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.
30-
* **Link Local**
31-
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.
20+
* **NAT (Network Address Translation)**
21+
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.
22+
* **Masquerading**
23+
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.
24+
* **CIDR (Classless Inter-Domain Routing)**
25+
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.
26+
* **Link Local**
27+
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.
3228

3329
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.
3430

3531
![masq/non-masq example](/images/docs/ip-masq.png)
3632

3733
The agent configuration file must be written in YAML or JSON syntax, and may contain three optional keys:
3834

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

4342
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:
4443

45-
```
44+
```shell
4645
iptables -t nat -L IP-MASQ-AGENT
46+
```
47+
48+
```none
4749
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
4850
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
4951
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
@@ -52,33 +54,35 @@ MASQUERADE all -- anywhere anywhere /* ip-masq-agent:
5254
5355
```
5456

55-
By default, in GCE/Google Kubernetes Engine starting with Kubernetes version 1.7.0, if network policy is enabled or you are using a cluster CIDR not in the 10.0.0.0/8 range, the ip-masq-agent will run in your cluster. If you are running in another environment, you can add the ip-masq-agent [DaemonSet](/docs/concepts/workloads/controllers/daemonset/) to your cluster:
56-
57-
57+
By default, in GCE/Google Kubernetes Engine, if network policy is enabled or
58+
you are using a cluster CIDR not in the 10.0.0.0/8 range, the `ip-masq-agent`
59+
will run in your cluster. If you are running in another environment,
60+
you can add the `ip-masq-agent` [DaemonSet](/docs/concepts/workloads/controllers/daemonset/)
61+
to your cluster.
5862

5963
<!-- steps -->
6064

6165
## Create an ip-masq-agent
6266
To create an ip-masq-agent, run the following kubectl command:
6367

64-
`
68+
```shell
6569
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/ip-masq-agent/master/ip-masq-agent.yaml
66-
`
70+
```
6771

6872
You must also apply the appropriate node label to any nodes in your cluster that you want the agent to run on.
6973

70-
`
71-
kubectl label nodes my-node beta.kubernetes.io/masq-agent-ds-ready=true
72-
`
74+
```shell
75+
kubectl label nodes my-node node.kubernetes.io/masq-agent-ds-ready=true
76+
```
7377

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

7680
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".
7781

7882
{{< note >}}
79-
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:
83+
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`:
8084

81-
```
85+
```yaml
8286
nonMasqueradeCIDRs:
8387
- 10.0.0.0/8
8488
resyncInterval: 60s
@@ -87,25 +91,28 @@ resyncInterval: 60s
8791
8892
Run the following command to add the config map to your cluster:
8993
90-
```
94+
```shell
9195
kubectl create configmap ip-masq-agent --from-file=config --namespace=kube-system
9296
```
9397

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

97-
```
101+
```shell
98102
iptables -t nat -L IP-MASQ-AGENT
103+
```
104+
105+
```none
99106
Chain IP-MASQ-AGENT (1 references)
100107
target prot opt source destination
101108
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
102109
RETURN all -- anywhere 10.0.0.0/8 /* ip-masq-agent: cluster-local
103110
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
104111
```
105112

106-
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 config map.
113+
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.
107114

108-
```
115+
```yaml
109116
nonMasqueradeCIDRs:
110117
- 10.0.0.0/8
111118
resyncInterval: 60s

0 commit comments

Comments
 (0)