Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b31874fe
Commit
b31874fe
authored
Aug 16, 2016
by
Minhan Xia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixes and nits
parent
1acaa1db
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
21 deletions
+20
-21
kubelet_network.go
pkg/kubelet/kubelet_network.go
+1
-1
proxier.go
pkg/proxy/iptables/proxier.go
+19
-20
No files found.
pkg/kubelet/kubelet_network.go
View file @
b31874fe
...
@@ -43,7 +43,7 @@ const (
...
@@ -43,7 +43,7 @@ const (
// kubernetes postrouting rules
// kubernetes postrouting rules
KubePostroutingChain
utiliptables
.
Chain
=
"KUBE-POSTROUTING"
KubePostroutingChain
utiliptables
.
Chain
=
"KUBE-POSTROUTING"
// kubernetes
postrouting
rules
// kubernetes
firewall
rules
KubeFirewallChain
utiliptables
.
Chain
=
"KUBE-FIREWALL"
KubeFirewallChain
utiliptables
.
Chain
=
"KUBE-FIREWALL"
)
)
...
...
pkg/proxy/iptables/proxier.go
View file @
b31874fe
...
@@ -581,11 +581,11 @@ func servicePortChainName(s proxy.ServicePortName, protocol string) utiliptables
...
@@ -581,11 +581,11 @@ func servicePortChainName(s proxy.ServicePortName, protocol string) utiliptables
return
utiliptables
.
Chain
(
"KUBE-SVC-"
+
portProtoHash
(
s
,
protocol
))
return
utiliptables
.
Chain
(
"KUBE-SVC-"
+
portProtoHash
(
s
,
protocol
))
}
}
//
servicePort
ChainName takes the ServicePortName for a service and
//
externalLoadBalancer
ChainName takes the ServicePortName for a service and
// returns the associated iptables chain. This is computed by hashing (sha256)
// returns the associated iptables chain. This is computed by hashing (sha256)
// then encoding to base32 and truncating with the prefix "KUBE-
FW
-".
// then encoding to base32 and truncating with the prefix "KUBE-
XLB
-".
func
serviceFirewall
ChainName
(
s
proxy
.
ServicePortName
,
protocol
string
)
utiliptables
.
Chain
{
func
externalLoadBalancer
ChainName
(
s
proxy
.
ServicePortName
,
protocol
string
)
utiliptables
.
Chain
{
return
utiliptables
.
Chain
(
"KUBE-
FW
-"
+
portProtoHash
(
s
,
protocol
))
return
utiliptables
.
Chain
(
"KUBE-
XLB
-"
+
portProtoHash
(
s
,
protocol
))
}
}
// This is the same as servicePortChainName but with the endpoint included.
// This is the same as servicePortChainName but with the endpoint included.
...
@@ -872,33 +872,32 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -872,33 +872,32 @@ func (proxier *Proxier) syncProxyRules() {
// Capture load-balancer ingress.
// Capture load-balancer ingress.
for
_
,
ingress
:=
range
svcInfo
.
loadBalancerStatus
.
Ingress
{
for
_
,
ingress
:=
range
svcInfo
.
loadBalancerStatus
.
Ingress
{
if
ingress
.
IP
!=
""
{
if
ingress
.
IP
!=
""
{
args
:=
[]
string
{
// create service external loadbalancer chain
"-A"
,
string
(
kubeServicesChain
),
xlbChain
:=
externalLoadBalancerChainName
(
svcName
,
protocol
)
"-m"
,
"comment"
,
"--comment"
,
fmt
.
Sprintf
(
`"%s loadbalancer IP"`
,
svcName
.
String
()),
if
chain
,
ok
:=
existingNATChains
[
xlbChain
];
ok
{
"-m"
,
protocol
,
"-p"
,
protocol
,
"-d"
,
fmt
.
Sprintf
(
"%s/32"
,
ingress
.
IP
),
"--dport"
,
fmt
.
Sprintf
(
"%d"
,
svcInfo
.
port
),
}
// create service firewall chain
fwChain
:=
serviceFirewallChainName
(
svcName
,
protocol
)
if
chain
,
ok
:=
existingNATChains
[
fwChain
];
ok
{
writeLine
(
natChains
,
chain
)
writeLine
(
natChains
,
chain
)
}
else
{
}
else
{
writeLine
(
natChains
,
utiliptables
.
MakeChainLine
(
fw
Chain
))
writeLine
(
natChains
,
utiliptables
.
MakeChainLine
(
xlb
Chain
))
}
}
// jump to service firewall chain
activeNATChains
[
xlbChain
]
=
true
// The service firewall rules are created based on ServiceSpec.loadBalancerSourceRanges field.
// The service firewall rules are created based on ServiceSpec.loadBalancerSourceRanges field.
// This currently works for loadbalancers that preserves source ips.
// This currently works for loadbalancers that preserves source ips.
// For loadbalancers which direct traffic to service NodePort, the firewall rules will not apply.
// For loadbalancers which direct traffic to service NodePort, the firewall rules will not apply.
writeLine
(
natRules
,
append
(
args
,
"-j"
,
string
(
fwChain
))
...
)
args
=
[]
string
{
args
:
=
[]
string
{
"-A"
,
string
(
fw
Chain
),
"-A"
,
string
(
kubeServices
Chain
),
"-m"
,
"comment"
,
"--comment"
,
fmt
.
Sprintf
(
`"%s loadbalancer IP"`
,
svcName
.
String
()),
"-m"
,
"comment"
,
"--comment"
,
fmt
.
Sprintf
(
`"%s loadbalancer IP"`
,
svcName
.
String
()),
"-m"
,
protocol
,
"-p"
,
protocol
,
"-m"
,
protocol
,
"-p"
,
protocol
,
"-d"
,
fmt
.
Sprintf
(
"%s/32"
,
ingress
.
IP
),
"-d"
,
fmt
.
Sprintf
(
"%s/32"
,
ingress
.
IP
),
"--dport"
,
fmt
.
Sprintf
(
"%d"
,
svcInfo
.
port
),
"--dport"
,
fmt
.
Sprintf
(
"%d"
,
svcInfo
.
port
),
}
}
// jump to service firewall chain
writeLine
(
natRules
,
append
(
args
,
"-j"
,
string
(
xlbChain
))
...
)
args
=
[]
string
{
"-A"
,
string
(
xlbChain
),
"-m"
,
"comment"
,
"--comment"
,
fmt
.
Sprintf
(
`"%s loadbalancer IP"`
,
svcName
.
String
()),
}
// We have to SNAT packets from external IPs.
// We have to SNAT packets from external IPs.
writeLine
(
natRules
,
append
(
args
,
"-j"
,
string
(
KubeMarkMasqChain
))
...
)
writeLine
(
natRules
,
append
(
args
,
"-j"
,
string
(
KubeMarkMasqChain
))
...
)
...
@@ -1056,7 +1055,7 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1056,7 +1055,7 @@ func (proxier *Proxier) syncProxyRules() {
for
chain
:=
range
existingNATChains
{
for
chain
:=
range
existingNATChains
{
if
!
activeNATChains
[
chain
]
{
if
!
activeNATChains
[
chain
]
{
chainString
:=
string
(
chain
)
chainString
:=
string
(
chain
)
if
!
strings
.
HasPrefix
(
chainString
,
"KUBE-SVC-"
)
&&
!
strings
.
HasPrefix
(
chainString
,
"KUBE-SEP-"
)
{
if
!
strings
.
HasPrefix
(
chainString
,
"KUBE-SVC-"
)
&&
!
strings
.
HasPrefix
(
chainString
,
"KUBE-SEP-"
)
&&
!
strings
.
HasPrefix
(
chainString
,
"KUBE-XLB-"
)
{
// Ignore chains that aren't ours.
// Ignore chains that aren't ours.
continue
continue
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment