Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make nodeport ip configurable #58052

Merged
merged 9 commits into from
Feb 27, 2018

Conversation

m1093782566
Copy link
Contributor

@m1093782566 m1093782566 commented Jan 10, 2018

What this PR does / why we need it:

By default, kube-proxy accepts everything from NodePort without any filter. It can be a problem for nodes which has both public and private NICs, and people only want to provide a service in private network and avoid exposing any internal service on the public IPs.

This PR makes nodeport ip configurable.

Which issue(s) this PR fixes:
Closes: #21070

Special notes for your reviewer:

Design proposal see: kubernetes/community#1547

Issue in feature repo: kubernetes/enhancements#539

Release note:

Make NodePort IP addresses configurable

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 10, 2018
@m1093782566 m1093782566 changed the title Nodeip config [WIP]Nodeip config Jan 10, 2018
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 10, 2018
@m1093782566 m1093782566 changed the title [WIP]Nodeip config Make nodeport ip configurable Jan 16, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 16, 2018
@m1093782566
Copy link
Contributor Author

/assign @thockin @brendandburns

/unassign

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 16, 2018
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 16, 2018
@m1093782566 m1093782566 force-pushed the nodeip-config branch 3 times, most recently from 257213e to 04cd7fe Compare January 17, 2018 02:35
@vfreex
Copy link
Contributor

vfreex commented Jan 17, 2018

I love this feature.
It would be better if we can alternately specify the whitelisted NIC for incoming traffic if we don't case the IP address and want to share the config file among nodes.

@m1093782566
Copy link
Contributor Author

@vfreex

I understand, but NIC name is very tricky especially in systemd system, for example, eth0, encap9, ensap7 etc. I doubt NIC name is more portable than CIDR.

allErrs := field.ErrorList{}
LOOP:
for i := range nodePortAddresses {
switch nodePortAddresses[i] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a switch with a single case? shouldn't that be an if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

} else {
addressList := addresses.UnsortedList()
if len(addressList) == 1 && utilproxy.IsZeroCIDR(addressList[0]) {
writeLine(proxier.natRules,
Copy link
Contributor

@brendandburns brendandburns Jan 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we structure this like:

cmd := []string {
    ...
}
if len(addressList) && ... {
    cmd = append(cmd, ...)
} else {
    cmd = append(cmd, ...)
}
cmd = append(cmd, ...)
writeLine(...)

So that we don't have quite so much code duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if err != nil {
glog.Errorf("Failed to get node IP, err: %v", err)
glog.Errorf("Failed to get node ip address matching nodeport cidr")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we bail out instead of having the else?

if ... {
   glog.Errorf(...)
   return
}
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@brendandburns
Copy link
Contributor

This generally looks good to me, but should probably be approved by

@kubernetes/sig-network-api-reviews
@thockin

@m1093782566
Copy link
Contributor Author

/retest

@@ -169,6 +169,8 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
"NAT timeout for TCP connections in the CLOSE_WAIT state")
fs.BoolVar(&o.config.EnableProfiling, "profiling", o.config.EnableProfiling, "If true enables profiling via web interface on /debug/pprof handler.")
fs.StringVar(&o.config.IPVS.Scheduler, "ipvs-scheduler", o.config.IPVS.Scheduler, "The ipvs scheduler type when proxy mode is ipvs")
fs.StringSliceVar(&o.config.NodePortAddresses, "nodeport-addresses", o.config.NodePortAddresses,
Copy link
Member

@thockin thockin Feb 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a FLAG, not code. Someone using the command-line doesn't know what a slice is. You have to tell them how to use it. "A comma-delimited list of IP blocks (e.g. 10.0.0.0/8, 1.2.3.4/32) used to filter addresses local to this node. Defaults to use all local addresses".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, THANKS!

allErrs = append(allErrs, field.Invalid(fldPath, nodePortAddresses, "must be non-empty"))
break
}
if _, _, err := net.ParseCIDR(nodePortAddresses[i]); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for now. The UX is a little weird, but probably won't get that much use.

Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be fixed in followup.

isIPv6 := proxier.iptables.IsIpv6()
for address := range addresses {
// TODO(thockin, m1093782566): If/when we have dual-stack support we will want to distinguish v4 from v6 zero-CIDRs.
if utilproxy.IsZeroCIDR(address) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to also test the v6-ness of it. If I specified "10.0.0.0/8,::/0" I would not expect 192.168.1.1 to match.

break
}
// Ignore IP addresses with incorrect version
if isIPv6 && !conntrack.IsIPv6String(address) || !isIPv6 && conntrack.IsIPv6String(address) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if isIPv6 != conntrack.IsIPv6String(address)

?

NetworkInterfaces []net.Interface
// The key of map Addrs is the network interface name
Address map[string][]net.Addr
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add

var _ proxyutil.NetworkInterfacer = &FakeNetwork{}

}
// First round of iteration to pick out `0.0.0.0/0` or `::/0` for the sake of excluding non-zero IPs.
for _, cidr := range cidrs {
if IsZeroCIDR(cidr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will allow the zero-cidr more than once, Not a big deal, but odd.

@thockin
Copy link
Member

thockin commented Feb 26, 2018

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 26, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: m1093782566, thockin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 26, 2018
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@m1093782566
Copy link
Contributor Author

@ixdy

I0226 21:34:57.293] Verifying verify-bazel.sh
I0226 21:34:57.309] 
I0226 21:34:57.310] +++ Running case: verify.bazel 
I0226 21:34:57.312] +++ working dir: /go/src/k8s.io/kubernetes
I0226 21:34:57.313] +++ command: bash "hack/make-rules/../../hack/verify-bazel.sh"
W0226 21:35:10.863] # github.com/bazelbuild/bazel-gazelle/internal/merger
W0226 21:35:10.864] ../../internal/merger/fix.go:93:28: too few values in struct initializer
W0226 21:35:10.864] ../../internal/merger/merger.go:806:16: too few values in struct initializer
W0226 21:35:10.864] ../../internal/merger/merger.go:866:19: too few values in struct initializer
W0226 21:35:10.865] ../../internal/merger/merger.go:870:19: too few values in struct initializer
W0226 21:35:11.056] # github.com/bazelbuild/bazel-gazelle/internal/rules
W0226 21:35:11.056] ../../internal/rules/generator.go:183:16: too few values in struct initializer
W0226 21:35:11.057] ../../internal/rules/sort_labels.go:45:16: too few values in struct initializer
W0226 21:35:11.063] !!! [0226 21:35:11] Call tree:
W0226 21:35:11.065] !!! [0226 21:35:11]  1: ./hack/update-bazel.sh:34 kube::util::go_install_from_commit(...)
W0226 21:35:11.070] !!! [0226 21:35:11] Call tree:
W0226 21:35:11.072] !!! [0226 21:35:11]  1: ./hack/update-bazel.sh:34 kube::util::go_install_from_commit(...)
I0226 21:35:12.105] +++ exit code: 1
I0226 21:35:12.110] +++ error: 1
I0226 21:35:12.132] FAILED   verify-bazel.sh	15s

Seems verify-bazel is broken, PTAL.

@m1093782566
Copy link
Contributor Author

/retest

1 similar comment
@ixdy
Copy link
Member

ixdy commented Feb 27, 2018

/retest

@kevin-wangzefeng
Copy link
Member

adding milestone as it's for 1.10

@kevin-wangzefeng kevin-wangzefeng added this to the v1.10 milestone Feb 27, 2018
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 60430, 60115, 58052, 60355, 60116). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 42378ea into kubernetes:master Feb 27, 2018
@m1093782566
Copy link
Contributor Author

All outstanding comments will be fixed after freeze.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/ipvs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/network Categorizes an issue or PR as relevant to SIG Network. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[proxy] Listening on a specific IP for nodePort
10 participants