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

Checks k8s-related port availability in PreInitChecks #846

Merged

Conversation

claudiubelu
Copy link
Contributor

@claudiubelu claudiubelu commented Nov 26, 2024

PreInitChecks is called on bootstrap or when joining another Kubernetes cluster. Kubernetes and its services open up several ports; if they're already in use, we cannot progress.

Adding these checks will make these error cases more explainable to the user, rather than a generic bootstrap / join error.

Sample error:

sudo k8s bootstrap
Bootstrapping the cluster. This may take a few seconds, please wait.
Error: Failed to bootstrap the cluster.

The error was: failed to POST /k8sd/cluster: failed to bootstrap new cluster: Failed to run post-bootstrap actions: pre-init checks failed for bootstrap node: Encountered error(s) while verifying port availability for Kubernetes services: Port 10250 (needed by: kubelet) is already in use.
Port 10249 (needed by: kube-proxy-metrics) is already in use.

@claudiubelu claudiubelu requested a review from a team as a code owner November 26, 2024 14:31
@eaudetcobello
Copy link
Contributor

Please address this comment: #815 (comment)

@claudiubelu
Copy link
Contributor Author

Please address this comment: #815 (comment)

Done

PreInitChecks is called on bootstrap or when joining another Kubernetes
cluster. Kubernetes and its services open up several ports; if they're
already in use, we cannot progress.

Adding these checks will make these error cases more explainable to the
user, rather than a generic bootstrap / join error.
Previously, we've only checked if the default Kubernetes service prots
are open. However, they can be changed, or disabled, which we did not
take into account. With this, we will.
Trying to listen on the given port will instead allow us to check
against all addresses.
@claudiubelu claudiubelu force-pushed the KU-2198/preinit-check-k8s-ports branch from a423fc8 to b97b1b2 Compare November 29, 2024 09:46
Copy link
Member

@berkayoz berkayoz left a comment

Choose a reason for hiding this comment

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

LGTM overall, left some comments

src/k8s/pkg/k8sd/types/k8s_service_configs.go Outdated Show resolved Hide resolved
src/k8s/pkg/snap/snap.go Outdated Show resolved Hide resolved
@claudiubelu claudiubelu force-pushed the KU-2198/preinit-check-k8s-ports branch from bd7307e to 2fc0484 Compare December 2, 2024 17:34
@claudiubelu claudiubelu force-pushed the KU-2198/preinit-check-k8s-ports branch from 2fc0484 to 3b34268 Compare December 3, 2024 13:18
Copy link
Contributor

@bschimke95 bschimke95 left a comment

Choose a reason for hiding this comment

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

LGTM

@bschimke95 bschimke95 merged commit 046f45f into canonical:main Dec 3, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants