If 'nodeIP' option is provided, this IP will be used
for pod traffic communication, Otherwise we will do
network parse/lookup on the node name to fetch the IP
address and in case of multiple IP addresses, the first
non loopback IP address is used.
| ... | ... |
@@ -34,6 +34,10 @@ type NodeConfig struct {
|
| 34 | 34 |
// If you're describing a set of static nodes to the master, this value must match one of the values in the list |
| 35 | 35 |
NodeName string |
| 36 | 36 |
|
| 37 |
+ // Node may have multiple IPs, specify the IP to use for pod traffic routing |
|
| 38 |
+ // If not specified, network parse/lookup on the nodeName is performed and the first non-loopback address is used |
|
| 39 |
+ NodeIP string |
|
| 40 |
+ |
|
| 37 | 41 |
// ServingInfo describes how to start serving |
| 38 | 42 |
ServingInfo ServingInfo |
| 39 | 43 |
|
| ... | ... |
@@ -15,6 +15,10 @@ type NodeConfig struct {
|
| 15 | 15 |
// If you're describing a set of static nodes to the master, this value must match one of the values in the list |
| 16 | 16 |
NodeName string `json:"nodeName"` |
| 17 | 17 |
|
| 18 |
+ // Node may have multiple IPs, specify the IP to use for pod traffic routing |
|
| 19 |
+ // If not specified, network parse/lookup on the nodeName is performed and the first non-loopback address is used |
|
| 20 |
+ NodeIP string `json:"nodeIP"` |
|
| 21 |
+ |
|
| 18 | 22 |
// ServingInfo describes how to start serving |
| 19 | 23 |
ServingInfo ServingInfo `json:"servingInfo"` |
| 20 | 24 |
|
| ... | ... |
@@ -16,6 +16,9 @@ func ValidateNodeConfig(config *api.NodeConfig) fielderrors.ValidationErrorList |
| 16 | 16 |
if len(config.NodeName) == 0 {
|
| 17 | 17 |
allErrs = append(allErrs, fielderrors.NewFieldRequired("nodeName"))
|
| 18 | 18 |
} |
| 19 |
+ if len(config.NodeIP) > 0 {
|
|
| 20 |
+ allErrs = append(allErrs, ValidateSpecifiedIP(config.NodeIP, "nodeIP")...) |
|
| 21 |
+ } |
|
| 19 | 22 |
|
| 20 | 23 |
allErrs = append(allErrs, ValidateServingInfo(config.ServingInfo).Prefix("servingInfo")...)
|
| 21 | 24 |
if config.ServingInfo.BindNetwork == "tcp6" {
|
| ... | ... |
@@ -102,7 +102,15 @@ func BuildKubernetesNodeConfig(options configapi.NodeConfig) (*NodeConfig, error |
| 102 | 102 |
server := kapp.NewKubeletServer() |
| 103 | 103 |
server.Config = path |
| 104 | 104 |
server.RootDirectory = options.VolumeDirectory |
| 105 |
- server.HostnameOverride = options.NodeName |
|
| 105 |
+ |
|
| 106 |
+ // kubelet finds the node IP address by doing net.ParseIP(hostname) and if that fails, |
|
| 107 |
+ // it does net.LookupIP(NodeName) and picks the first non-loopback address. |
|
| 108 |
+ // Pass node IP as hostname to make kubelet use the desired IP address. |
|
| 109 |
+ if len(options.NodeIP) > 0 {
|
|
| 110 |
+ server.HostnameOverride = options.NodeIP |
|
| 111 |
+ } else {
|
|
| 112 |
+ server.HostnameOverride = options.NodeName |
|
| 113 |
+ } |
|
| 106 | 114 |
server.AllowPrivileged = true |
| 107 | 115 |
server.RegisterNode = true |
| 108 | 116 |
server.Address = kubeAddress |
| ... | ... |
@@ -139,6 +147,7 @@ func BuildKubernetesNodeConfig(options configapi.NodeConfig) (*NodeConfig, error |
| 139 | 139 |
} |
| 140 | 140 |
|
| 141 | 141 |
// provide any config overrides |
| 142 |
+ cfg.NodeName = options.NodeName |
|
| 142 | 143 |
cfg.StreamingConnectionIdleTimeout = 5 * time.Minute // TODO: should be set |
| 143 | 144 |
cfg.KubeClient = kubeClient |
| 144 | 145 |
cfg.DockerExecHandler = dockerExecHandler |
| ... | ... |
@@ -249,13 +249,13 @@ func RunSDNController(config *kubernetes.NodeConfig, nodeConfig configapi.NodeCo |
| 249 | 249 |
case flatsdn.NetworkPluginName(): |
| 250 | 250 |
ch := make(chan struct{})
|
| 251 | 251 |
config.KubeletConfig.StartUpdates = ch |
| 252 |
- go flatsdn.Node(oclient, config.Client, nodeConfig.NodeName, "", ch, nodeConfig.NetworkConfig.MTU) |
|
| 252 |
+ go flatsdn.Node(oclient, config.Client, nodeConfig.NodeName, nodeConfig.NodeIP, ch, nodeConfig.NetworkConfig.MTU) |
|
| 253 | 253 |
case multitenant.NetworkPluginName(): |
| 254 | 254 |
ch := make(chan struct{})
|
| 255 | 255 |
config.KubeletConfig.StartUpdates = ch |
| 256 | 256 |
plugin := multitenant.GetKubeNetworkPlugin() |
| 257 | 257 |
config.KubeletConfig.NetworkPlugins = append(config.KubeletConfig.NetworkPlugins, plugin) |
| 258 |
- go multitenant.Node(oclient, config.Client, nodeConfig.NodeName, "", ch, plugin, nodeConfig.NetworkConfig.MTU) |
|
| 258 |
+ go multitenant.Node(oclient, config.Client, nodeConfig.NodeName, nodeConfig.NodeIP, ch, plugin, nodeConfig.NetworkConfig.MTU) |
|
| 259 | 259 |
} |
| 260 | 260 |
} |
| 261 | 261 |
|