You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/tasks/administer-cluster/ip-masq-agent.md
+40-33Lines changed: 40 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,46 +4,48 @@ content_type: task
4
4
---
5
5
6
6
<!-- 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`.
9
8
10
9
## {{% heading "prerequisites" %}}
11
10
12
-
13
11
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
14
12
15
-
16
-
17
13
<!-- discussion -->
18
14
## IP Masquerade Agent User Guide
19
15
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.
21
17
22
18
### **Key Terms**
23
19
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.
32
28
33
29
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.
The agent configuration file must be written in YAML or JSON syntax, and may contain three optional keys:
38
34
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.
42
41
43
42
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:
44
43
45
-
```
44
+
```shell
46
45
iptables -t nat -L IP-MASQ-AGENT
46
+
```
47
+
48
+
```none
47
49
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
48
50
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
49
51
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
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.
58
62
59
63
<!-- steps -->
60
64
61
65
## Create an ip-masq-agent
62
66
To create an ip-masq-agent, run the following kubectl command:
More information can be found in the ip-masq-agent documentation [here](https://github.com/kubernetes-sigs/ip-masq-agent)
75
79
76
80
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".
77
81
78
82
{{< 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`:
80
84
81
-
```
85
+
```yaml
82
86
nonMasqueradeCIDRs:
83
87
- 10.0.0.0/8
84
88
resyncInterval: 60s
@@ -87,25 +91,28 @@ resyncInterval: 60s
87
91
88
92
Run the following command to add the config map to your cluster:
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.
95
99
After the resync interval has expired, you should see the iptables rules reflect your changes:
96
100
97
-
```
101
+
```shell
98
102
iptables -t nat -L IP-MASQ-AGENT
103
+
```
104
+
105
+
```none
99
106
Chain IP-MASQ-AGENT (1 references)
100
107
target prot opt source destination
101
108
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
102
109
RETURN all -- anywhere 10.0.0.0/8 /* ip-masq-agent: cluster-local
103
110
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
104
111
```
105
112
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.
0 commit comments