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

Fix multi-node cluster not working after restarting docker #2775

Merged
merged 5 commits into from
May 25, 2022

Conversation

tnqn
Copy link
Contributor

@tnqn tnqn commented May 17, 2022

In a multi-node cluster with single controlplane node, if the
controlplane node's IP changes, kube-controller-manager and
kube-scheduler would fail to connect kube-apiserver.

This patch fixes it by replacing the server address in kubeconfig files
of kube-controller-manager and kube-scheduler with the new IP and
re-generate a certificate with the new IP for kube-apiserver.

Signed-off-by: Quan Tian [email protected]

Fixes #2759

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 17, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @tnqn. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot requested review from amwat and munnerz May 17, 2022 16:29
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 17, 2022
sed -i "s#${old_ipv4}#${curr_ipv4}#" /var/lib/kubelet/kubeadm-flags.env || true
if [[ "${old_ipv4}" != "${curr_ipv4}" ]]; then
# kubernetes manifests are only present on control-plane nodes
sed -i "s#${old_ipv4}#${curr_ipv4}#" /etc/kubernetes/manifests/*.yaml || true
Copy link
Member

@neolit123 neolit123 May 17, 2022

Choose a reason for hiding this comment

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

instead of sed-ing can we kubeadm init phase control-plane {foo} --config ... to generate a new manifest for component {foo}. by running it will try to get the node IP, and hopefully that will be the right one?

then again, sed-ing seems straightforward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could work but it would be a change irrelevant to the PR's purpose as the script has been using sed from the beginning and kubeadm.conf, kubeadm-flags.env will still need sed. It may require a few more lines to check if this is control-plane node before invoking kubeadm init phase control-plane.
Do we want to make the change in this PR?

Copy link
Member

Choose a reason for hiding this comment

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

Sed means we retain any user changes performed manually out of band except the targeted edit we're making.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for commenting, then I suppose we could keep sed

Copy link
Member

Choose a reason for hiding this comment

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

we should however, do some fixes so we replace the actual literals instead of letting the IP address be mis-interpreted as a regex, though that bug is not new to this PR.

Copy link
Member

Choose a reason for hiding this comment

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

rebased the PR (because it's based on out of date version of entrypoint script) and then fixed this, we regex escape the ip addresses now (I think ...)

@aojea
Copy link
Contributor

aojea commented May 19, 2022

/ok-to-test

1 similar comment
@aojea
Copy link
Contributor

aojea commented May 19, 2022

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 19, 2022
@tnqn tnqn force-pushed the fix-docker-restart-kubeadm branch from c63323d to f0b470b Compare May 19, 2022 10:06
@BenTheElder
Copy link
Member

Sorry, I am going to finish shipping a release to fix non-systemd hosts after the v0.13 changes before we ship any further potentially problematic changes #2767

@BenTheElder BenTheElder added this to the v0.15.0 milestone May 19, 2022
@BenTheElder BenTheElder self-assigned this May 19, 2022
@BenTheElder
Copy link
Member

This is the first thing I'd like to see in v0.15.0, assigning to see this through next.

In a multi-node cluster with single controlplane node, if the
controlplane node's IP changes, kube-controller-manager and
kube-scheduler would fail to connect kube-apiserver.

This patch fixes it by replacing the server address in kubeconfig files
of kube-controller-manager and kube-scheduler with the new IP and
re-generate a certificate with the new IP for kube-apiserver.

Signed-off-by: Quan Tian <[email protected]>
@BenTheElder BenTheElder force-pushed the fix-docker-restart-kubeadm branch from f0b470b to 7f76c51 Compare May 20, 2022 04:54
@BenTheElder BenTheElder force-pushed the fix-docker-restart-kubeadm branch from 5a1120b to 5a58dbf Compare May 20, 2022 05:11
@BenTheElder
Copy link
Member

/hold
I have not tested building a node image and then rebooting a multi-node cluster with the latest changes, even though they should be "more correct" we should test that :-)

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 20, 2022
@BenTheElder BenTheElder force-pushed the fix-docker-restart-kubeadm branch from 5a58dbf to a563fe4 Compare May 20, 2022 05:30
@BenTheElder
Copy link
Member

dropped the base image bump while we iterate more, @tnqn handing back to you.

very excited about this PR :-)

sed -i "s#${old_ipv4}#${curr_ipv4}#" /var/lib/kubelet/kubeadm-flags.env || true
if [[ "${old_ipv4}" != "${curr_ipv4}" ]]; then
# kubernetes manifests are only present on control-plane nodes
sed_ipv4_command="s#$(regex_escape_ip "${old_ipv4}")#${curr_ipv4}#g"
Copy link
Member

Choose a reason for hiding this comment

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

note that when I did the regex fix I also:

  • stopped computing this string repeatedly
  • changed it to a global replace (!) instead of just replacing the first instance

the existing sed pattern carried forward from the existing script was not good :(
it should be reasonable now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!
Reminded by it, I also added word boundary to sed pattern to avoid mismatch like

# sed "s/1\.1\.1\.2/1.1.1.3/g" <<< "1.1.1.22"
1.1.1.32

@@ -29,7 +29,12 @@ fi

grep_allow_nomatch() {
# grep exits 0 on match, 1 on no match, 2 on error
grep "$@" || [[ $? == 1 ]]
grep "$@"|| [[ $? == 1 ]]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess this is an unintended change and reverted it in 3rd patch, please let me know if this is on purpose

@tnqn
Copy link
Contributor Author

tnqn commented May 20, 2022

I have tested the change by restarting IPv4, IPv6 and dualstack clusters and they worked as expected after controlplane IP changed.

@aojea
Copy link
Contributor

aojea commented May 20, 2022

/retest

error: no builder "kind-builder" found

1. Check for files and error if replacing in them fails
2. Add word boundary to sed pattern to avoid mismatch
3. Regenerate certificate only once when both IPv4 and IPv6 addresses
   change

Signed-off-by: Quan Tian <[email protected]>
@tnqn tnqn force-pushed the fix-docker-restart-kubeadm branch from 59da8d1 to 316e116 Compare May 23, 2022 16:52
@BenTheElder
Copy link
Member

Tentatively unavailable tomorrow, top of my list to revisit when I am back.

Still the first thing I intend to merge in v0.15.0, I think this is about good to go, but I want to double check everything again 😅

Thanks again for working on this 🙏

@BenTheElder
Copy link
Member

it looks good, pushing images so we can soak all the CI

Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve
/hold cancel
thank you!!! 😄

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels May 25, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BenTheElder, tnqn

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 May 25, 2022
@k8s-ci-robot k8s-ci-robot merged commit 9563500 into kubernetes-sigs:main May 25, 2022
@tnqn tnqn deleted the fix-docker-restart-kubeadm branch May 26, 2022 03:24
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support docker restart for clusters with multiple nodes (single controlplane node)
5 participants