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

Change default --cert-dir for kubelet to a non-transient location #53317

Merged
merged 1 commit into from
Oct 4, 2017

Conversation

liggitt
Copy link
Member

@liggitt liggitt commented Oct 2, 2017

The default kubelet --cert-dir location is /var/run/kubernetes, which is automatically erased on reboot on many platforms. As of 1.8.0, kubelet TLS bootstrapping and cert rotation now persist files in --cert-dir, this should default to a non-transient location. Default it to the pki subfolder of the default --root-dir Fixes #53288

Additionally, since kubeadm expects a running (albeit crashlooping) kubelet prior to running kubeadm init or kubeadm join, and was using the default --root-dir of /var/lib/kubelet, it should not expect that folder to be empty as a pre-init check. Fixes #53356

kubelet `--cert-dir` now defaults to `/var/lib/kubelet/pki`, in order to ensure bootstrapped and rotated certificates persist beyond a reboot. resolves an issue in kubeadm with false-positive `/var/lib/kubelet is not empty` message during pre-flight checks

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 2, 2017
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 2, 2017
@liggitt liggitt assigned luxas and jcbsmpsn and unassigned vishh Oct 2, 2017
@liggitt liggitt added area/kubelet kind/bug Categorizes issue or PR as related to a bug. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/node Categorizes an issue or PR as relevant to SIG Node. cherrypick-candidate labels Oct 2, 2017
@liggitt liggitt added this to the v1.8 milestone Oct 2, 2017
@jcbsmpsn
Copy link
Contributor

jcbsmpsn commented Oct 2, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 2, 2017
@liggitt
Copy link
Member Author

liggitt commented Oct 2, 2017

/assign @derekwaynecarr @dchen1107
for approval of kubelet --cert-dir flag default value change

@liggitt
Copy link
Member Author

liggitt commented Oct 3, 2017

/test pull-kubernetes-e2e-kubeadm-gce

@liggitt liggitt force-pushed the fix-kubelet-cert-dir branch from 1a953eb to 540516b Compare October 3, 2017 06:26
@liggitt liggitt force-pushed the fix-kubelet-cert-dir branch from 540516b to 8c25265 Compare October 3, 2017 06:26
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 3, 2017
@liggitt
Copy link
Member Author

liggitt commented Oct 3, 2017

@kubernetes/sig-cluster-lifecycle-bugs @luxas PTAL at the kubeadm pre-init check change

@liggitt liggitt added the priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. label Oct 3, 2017
@derekwaynecarr
Copy link
Member

/approve

@liggitt
Copy link
Member Author

liggitt commented Oct 3, 2017

/assign @mikedanese @luxas
for approval of kubeadm pre-init check change

@@ -650,7 +650,6 @@ func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
PortOpenCheck{port: 10252},
HTTPProxyCheck{Proto: "https", Host: cfg.API.AdvertiseAddress, Port: int(cfg.API.BindPort)},
DirAvailableCheck{Path: filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.ManifestsSubDirName)},
DirAvailableCheck{Path: "/var/lib/kubelet"},
Copy link
Member

Choose a reason for hiding this comment

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

I think it will be a lot better if DirAvailableCheck will be enhanced to do filepath.Walk() and see if there are files present. It should fail check only if directory contains files, but should tolerate if there are empty sub-dirs.

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 should fail check only if directory contains files, but should tolerate if there are empty sub-dirs.

not really... the kubelet is running in the background, so kubeadm should not expect its runtime dir to be empty.

Copy link
Member

Choose a reason for hiding this comment

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

Preflight checks are executed at the time when kubelet has no valid configuration, so should not be really running. And even if it running, it should be nothing in /var/lib/kubelet/pods, which might mean leftovers from previous configurations if kubeadm reset was not properly executed.

As alternative, we can add check that /var/lib/kubelet/pods and /var/lib/kubelet/pki are empty.

Copy link
Member Author

@liggitt liggitt Oct 3, 2017

Choose a reason for hiding this comment

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

@luxas asked that rather than remove these, I change these to check the /var/lib/kubelet/pods subfolder specifically

Copy link
Member Author

@liggitt liggitt Oct 3, 2017

Choose a reason for hiding this comment

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

@luxas asked that rather than remove these, I change these to check the /var/lib/kubelet/pods subfolder specifically

actually, I don't think that's a good idea... the kubelet owns the runtime dir. kubeadm can check the paths kubeadm writes to (pod manifests, etc), but shouldn't make assumptions about what the kubelet writes to its runtime dir. I think this is good as-is.

Copy link
Member

Choose a reason for hiding this comment

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

What would happen on nodes, where there are no static manifests, but kublet was not properly reset and still running some pods and having certs from previous node setup ?

Copy link
Member Author

Choose a reason for hiding this comment

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

As alternative, we can add check that /var/lib/kubelet/pods and /var/lib/kubelet/pki are empty.

/var/lib/kubelet/pki will not be empty if the kubelet is crashlooping in the background... it generates serving certificates there

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok for now to remove that directory check, as files are generated by crashlooping kubelet. In 1.9 I think we need to have separate issue that would be handling kubelet start/stop in better way in init/join commands. Right now it seems that kubeadm has even more issues, like kubelet will not be started if user did kubeadm reset then kubeadm join --skip-preflight-checks.

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.

/lgtm but @luxas for approve.

@mikedanese
Copy link
Member

/approve

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 3, 2017
@mikedanese
Copy link
Member

/hold for lucas

@liggitt
Copy link
Member Author

liggitt commented Oct 3, 2017

discussed with @luxas on slack about his suggestion to narrow the preflight check to /var/lib/kubelet/pods.

I think that introspecting the kubelet's runtime dir in a preflight is a fragile check for kubeadm to make and will lead to similar broken assumptions in the future. Would like feedback on that from representatives from sig-node (@derekwaynecarr) and sig-cluster-lifecycle (@mikedanese / @timothysc).

If the consensus is to remove the check, @luxas said he is fine with that.

If the consensus is to continue introspecting the runtime dir and just narrow the check, I can make that change as well.

We await your feedback.

@mikedanese
Copy link
Member

mikedanese commented Oct 3, 2017

I agree that broad preflight checks like this are bound to break. Kubelet fs layout is not a stable API and there are many reasons this directory wouldn't be empty. If we want to prevent kubeadm from installing over an already init'd node we should write a file that is deleted during kubeadm reset. If we want to check that the kubelet is installed, we should make sure that a kubelet process is running.

@jbeda
Copy link
Contributor

jbeda commented Oct 3, 2017

It is hard to check if the kubelet is running right now as it crash loops.

For 1.9 to really address this we'd have to have more formal communications between the kubelet and kubeadm. That comes with Kubelet Dynamic Config. We should also have a way to reliably "clean" the kubelet config to reset it on reinstall or when things are busted. If we can't just delete a directory then there should be some other mechanism to do that.

It feels like we need a design doc on the ideal work flow for kubelet/kubeadm for 1.9 that is shared across SIG-cluster-lifecycle and SIG-node to help avoid these types of issues in the future.

@liggitt
Copy link
Member Author

liggitt commented Oct 4, 2017

Talked with @derekwaynecarr as well and he agreed it didn't make sense for kubeadm to introspect the runtime dir. Sounds like there is consensus to remove this preflight check.

@mikedanese:
If we want to prevent kubeadm from installing over an already init'd node we should write a file that is deleted during kubeadm reset

That's already done... kubeadm init and kubeadm join preflights both fail if the pod manifest dir contains existing manifests. That's populated on init/join, and cleaned up on reset.

@jbeda:
We should also have a way to reliably "clean" the kubelet config to reset it on reinstall or when things are busted. If we can't just delete a directory then there should be some other mechanism to do that.

kubeadm reset shuts down the kubelet service and removes the /var/lib/kubelet dir, which works fine. Removing the --root-dir given to the kubelet as part of cleanup/reset seems fine. Assumptions about the internal structure of it was the issue.

@jbeda:
For 1.9 to really address this we'd have to have more formal communications between the kubelet and kubeadm. That comes with Kubelet Dynamic Config.
...
It feels like we need a design doc on the ideal work flow for kubelet/kubeadm for 1.9 that is shared across SIG-cluster-lifecycle and SIG-node

The "API" boundary here should be the config the kubelet exposes (via flags, as today, or via config objects/files, as in dynamic config)

@mikedanese
Copy link
Member

/unhold

@mikedanese
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 4, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: derekwaynecarr, jcbsmpsn, liggitt, mikedanese, timothysc

Associated issue: 53288

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

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

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

@k8s-github-robot k8s-github-robot merged commit 0690b79 into kubernetes:master Oct 4, 2017
@liggitt liggitt deleted the fix-kubelet-cert-dir branch October 4, 2017 17:48
k8s-github-robot pushed a commit that referenced this pull request Oct 6, 2017
…7-upstream-release-1.8

Automatic merge from submit-queue.

Automated cherry pick of #53317

Cherry pick of #53317 on release-1.8.

#53317: Change default --cert-dir for kubelet to a non-transient
@k8s-cherrypick-bot
Copy link

Commit found in the "release-1.8" branch appears to be this PR. Removing the "cherrypick-candidate" label. If this is an error find help to get your PR picked.

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/kubelet 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. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/node Categorizes an issue or PR as relevant to SIG Node. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet