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

kubeadm: When etcd is listening on all interfaces, set the etcd probe to use loopback #64670

Conversation

stealthybox
Copy link
Member

@stealthybox stealthybox commented Jun 3, 2018

What this PR does / why we need it:
When constructing the etcd liveness probe, if the user passes an IPv4 or IPv6 address,
we set the etcdctl liveness probe to use the respective IPv4 or IPv6 loopback address for --endpoints.

The etcd probe is now always formatted with the https:// protocol and square brackets around the IP (required for IPv6 / compatible with IPv4).

::1 is now also included in the etcd serving cert SAN by default.

/kind bug
/area kubeadm
/area etcd
/priority important-soon

/sig cluster-lifecycle
/assign @fabriziopandini

Which issue(s) this PR fixes
Fixes kubernetes/kubeadm#882

Special notes for your reviewer:

root@vagrant:~# /vagrant/bin/882_kubeadm init --config /dev/stdin << EOF |& tail -n5
etcd:
  extraArgs:
    listen-client-urls: https://[::]:2379
EOF
I0603 19:52:15.666594   24743 tlsbootstrap.go:50] [bootstraptoken] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
I0603 19:52:15.671424   24743 tlsbootstrap.go:72] [bootstraptoken] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
I0603 19:52:15.674607   24743 tlsbootstrap.go:95] [bootstraptoken] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
I0603 19:52:15.677551   24743 clusterinfo.go:43] [bootstraptoken] creating the "cluster-info" ConfigMap in the "kube-public" namespace
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
root@vagrant:~# cat /etc/kubernetes/manifests/etcd.yaml |grep -C4 listen
spec:
  containers:
  - command:
    - etcd
    - --listen-client-urls=https://[::]:2379
    - --advertise-client-urls=https://127.0.0.1:2379
    - --cert-file=/etc/kubernetes/pki/etcd/server.crt
    - --client-cert-auth=true
    - --data-dir=/var/lib/etcd
root@vagrant:~# cat /etc/kubernetes/manifests/etcd.yaml |grep -C4 etcdctl
      exec:
        command:
        - /bin/sh
        - -ec
        - ETCDCTL_API=3 etcdctl --endpoints=https://[::1]:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt
          --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt --key=/etc/kubernetes/pki/etcd/healthcheck-client.key
          get foo
      failureThreshold: 8
      initialDelaySeconds: 15

Release note:

kubeadm now configures the etcd liveness probe correctly when etcd is listening on all interfaces

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/kubeadm area/etcd priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 3, 2018
@k8s-ci-robot k8s-ci-robot requested review from kad and luxas June 3, 2018 20:03
@dixudx
Copy link
Member

dixudx commented Jun 4, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 4, 2018
@@ -254,6 +254,12 @@ func GetProbeAddress(cfg *kubeadmapi.MasterConfiguration, componentName string)
}
// Return the IP if the URL contains an address instead of a name.
if ip := net.ParseIP(parsedURL.Hostname()); ip != nil {
// etcdctl doesn't support auto-converting zero addresses into loopback addresses
if ip.Equal(net.IPv4zero) || ip.Equal(net.IPv6zero) {
return "127.0.0.1"
Copy link
Member

Choose a reason for hiding this comment

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

if we are in IPv6 configuration, better to use IPv6 loopback.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is intentional.
IPv6 endpoints don't work /w etcdctl.
I couldn't find an upstream bug -- perhaps we should file one.

Copy link
Member Author

Choose a reason for hiding this comment

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

this is commented in the line below

Copy link
Member

Choose a reason for hiding this comment

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

So, I tested this locally and using ::1 appears to work for etcdctl v3.1.12.

When testing, I had originally just modified the etcd manifest for a kubectl-based install, but neglected to update the certificate to add the ipv6 loopback address and was seeing this error: Error: grpc: timed out when dialing. Once I updated the etcd server certificate to include ::1 I was able to use etcdctl with --endpoints https://[::1]:2379 without an issue.

Copy link
Member

Choose a reason for hiding this comment

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

@stealthybox We should probably update GetEtcdAltNames() in pki_helpers.go to add the ipv6 loopback address by default as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

@detiber Ah, that's totally the issue
I really struggled to determine what was wrong since it seems they removed the --debug flag

I'll fix this

Copy link
Member

Choose a reason for hiding this comment

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

@stealthybox I ended up figuring it out by using etcdctl v3.2.x and using the --debug flag 🤣

- --data-dir=/var/lib/etcd
- --peer-key-file=/etc/kubernetes/pki/etcd/peer.key
- --peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt
- --listen-client-urls=https://[::0:0]:2379
Copy link
Member

Choose a reason for hiding this comment

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

https://[::]:2379

Copy link
Member Author

Choose a reason for hiding this comment

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

This is also intentional.
It forces us to use net.ParseIP() because these are all equivalent:

0:0:0:0:0:0:0:0
::0:0:0:0:0
::0:0
::0
::

Copy link
Member

Choose a reason for hiding this comment

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

I understand that those are equivalent, but what is the reason behind that particular notation ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It prevents code that just does a string match on :: or ::0 instead of parsing the IP and doing real equivalence.

If you'd like I can expand the test cases, but I figured that if I just add one, I should pick an edge case.

Copy link
Member

@luxas luxas left a comment

Choose a reason for hiding this comment

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

Please fix @kad's comments

@timothysc timothysc added this to the v1.11 milestone Jun 4, 2018
@timothysc timothysc added status/approved-for-milestone and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jun 4, 2018
Copy link
Member

@timothysc timothysc left a comment

Choose a reason for hiding this comment

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

/approve

Please fix comment and @detiber - please weigh in too for lgtm.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 4, 2018
@stealthybox
Copy link
Member Author

Thanks for the review @kad 👍 -- weighed in on the comments.
Please lmk if we need to clarify more in the code.

@detiber
Copy link
Member

detiber commented Jun 4, 2018

lgtm, but would like to see the use of the ipv6 loopback in the healthcheck when the ipv6 unspecified address is provided.

@timothysc timothysc added priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. and removed priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels Jun 4, 2018
@k8s-ci-robot k8s-ci-robot added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Jun 4, 2018
@dims
Copy link
Member

dims commented Jun 4, 2018

/priority important-soon

Is this priority ok? please alter if you disagree (need one for the bot)

@jberkus
Copy link

jberkus commented Jun 5, 2018

Also needs a kind/ label

/kind bug

@cjwagner
Copy link
Member

cjwagner commented Jun 5, 2018

There are multiple priority labels on this PR. The milestone maintainer is expecting exactly 1.

@timothysc timothysc removed the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Jun 5, 2018
@stealthybox stealthybox changed the title kubeadm: When etcd is listening on all interfaces, set the etcd probe to use the ipv4 loopback kubeadm: When etcd is listening on all interfaces, set the etcd probe to use loopback Jun 6, 2018
@k8s-ci-robot k8s-ci-robot added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Jun 6, 2018
@stealthybox stealthybox force-pushed the feature/kubeadm_882-etcd-zero-probe branch from 83d80c6 to 166b5b9 Compare June 6, 2018 00:31
@stealthybox stealthybox force-pushed the feature/kubeadm_882-etcd-zero-probe branch from 166b5b9 to 76c04b9 Compare June 6, 2018 00:34
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 6, 2018
@stealthybox
Copy link
Member Author

@kad @detiber @dixudx

  • added ::1 to the server SAN
  • now returning ::1 in the ipv6 unspecified case
  • formatted the probes to always use https://[%s]:%d for ipv6 compatibility
  • added more tests to cover the v6 parsing cases

PTAL tyvm

@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request Labels Incomplete

@dixudx @fabriziopandini @stealthybox

Action required: This pull request requires label changes.

priority: Must specify exactly one of priority/critical-urgent, priority/important-longterm or priority/important-soon.

Help

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

@dixudx dixudx left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dixudx, stealthybox, timothysc

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

@dixudx
Copy link
Member

dixudx commented Jun 6, 2018

/retest

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit d3a797a into kubernetes:master Jun 6, 2018
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/etcd area/kubeadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. milestone/incomplete-labels priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

etcd health probe does not support server --listen-client-urls=https://0.0.0.0:2379