mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Add nodepoprt chain and link it in, add unused MASQ rule
This commit is contained in:
parent
60e17a54e7
commit
d14c98f6cc
@ -48,12 +48,16 @@ import (
|
|||||||
// features are backported in various distros and this could get pretty hairy.
|
// features are backported in various distros and this could get pretty hairy.
|
||||||
// However iptables-1.4.0 was released 2007-Dec-22 and appears to have every feature we use,
|
// However iptables-1.4.0 was released 2007-Dec-22 and appears to have every feature we use,
|
||||||
// so this seems prefectly reasonable for now.
|
// so this seems prefectly reasonable for now.
|
||||||
const (
|
const IPTABLES_MIN_VERSION string = "1.4.0"
|
||||||
IPTABLES_MIN_VERSION string = "1.4.0"
|
|
||||||
)
|
|
||||||
|
|
||||||
// the services chain
|
// the services chain
|
||||||
var iptablesServicesChain utiliptables.Chain = "KUBE-SERVICES"
|
const iptablesServicesChain utiliptables.Chain = "KUBE-SERVICES"
|
||||||
|
|
||||||
|
// the nodeports chain
|
||||||
|
const iptablesNodePortsChain utiliptables.Chain = "KUBE-NODEPORTS"
|
||||||
|
|
||||||
|
// the mark we apply to traffic needing SNAT
|
||||||
|
const iptablesMasqueradeMark = "0x4d415351"
|
||||||
|
|
||||||
// ShouldUseIptablesProxier returns true if we should use the iptables Proxier instead of
|
// ShouldUseIptablesProxier returns true if we should use the iptables Proxier instead of
|
||||||
// the userspace Proxier.
|
// the userspace Proxier.
|
||||||
@ -411,16 +415,37 @@ func (proxier *Proxier) syncProxyRules() error {
|
|||||||
}
|
}
|
||||||
glog.V(4).Infof("Syncing iptables rules.")
|
glog.V(4).Infof("Syncing iptables rules.")
|
||||||
|
|
||||||
// ensure main chain and rule connecting to output
|
// Ensure main chains and rules are installed.
|
||||||
args := []string{"-j", string(iptablesServicesChain)}
|
inputChains := []utiliptables.Chain{utiliptables.ChainOutput, utiliptables.ChainPrerouting}
|
||||||
if _, err := proxier.iptables.EnsureChain(utiliptables.TableNAT, iptablesServicesChain); err != nil {
|
// Link the services chain.
|
||||||
return err
|
for _, chain := range inputChains {
|
||||||
|
if _, err := proxier.iptables.EnsureChain(utiliptables.TableNAT, iptablesServicesChain); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
comment := "kubernetes service portals; must be before nodeports"
|
||||||
|
args := []string{"-m", "comment", "--comment", comment, "-j", string(iptablesServicesChain)}
|
||||||
|
if _, err := proxier.iptables.EnsureRule(utiliptables.Prepend, utiliptables.TableNAT, chain, args...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if _, err := proxier.iptables.EnsureRule(utiliptables.Prepend, utiliptables.TableNAT, utiliptables.ChainOutput, args...); err != nil {
|
// Link the nodeports chain.
|
||||||
return err
|
for _, chain := range inputChains {
|
||||||
|
if _, err := proxier.iptables.EnsureChain(utiliptables.TableNAT, iptablesNodePortsChain); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
comment := "kubernetes service nodeports; must be after portals"
|
||||||
|
args := []string{"-m", "comment", "--comment", comment, "-m", "addrtype", "--dst-type", "LOCAL", "-j", string(iptablesNodePortsChain)}
|
||||||
|
if _, err := proxier.iptables.EnsureRule(utiliptables.Append, utiliptables.TableNAT, chain, args...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if _, err := proxier.iptables.EnsureRule(utiliptables.Prepend, utiliptables.TableNAT, utiliptables.ChainPrerouting, args...); err != nil {
|
// Link the output rules.
|
||||||
return err
|
{
|
||||||
|
comment := "kubernetes service traffic requiring SNAT"
|
||||||
|
args := []string{"-m", "comment", "--comment", comment, "-m", "mark", "--mark", iptablesMasqueradeMark, "-j", "MASQUERADE"}
|
||||||
|
if _, err := proxier.iptables.EnsureRule(utiliptables.Append, utiliptables.TableNAT, utiliptables.ChainPostrouting, args...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get iptables-save output so we can check for existing chains and rules.
|
// Get iptables-save output so we can check for existing chains and rules.
|
||||||
|
Loading…
Reference in New Issue
Block a user