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

Master nodes bootstrapping script #1

Open
briankosw opened this issue Nov 16, 2021 · 6 comments
Open

Master nodes bootstrapping script #1

briankosw opened this issue Nov 16, 2021 · 6 comments

Comments

@briankosw
Copy link

Hi @abohmeed, I noticed that you have the file kubernetes/node_startup.tmpl that you aren't including in your Terraform setup right now. I read through the file and it seems that it's supposed to bootstrap the master and worker nodes so that there's a single master node that initializes the Kubernetes cluster (kubeadm init) and teh other master nodes intelligently join the initialized Kubernetes cluster (kubeadm join). Could you explain whether the script works as intended? And why aren't you using the script and instead resorting manual CLI commands? Thanks!

@abohmeed
Copy link
Owner

Hello @briankosw
Yes, you're correct. The file is used to auto-join master and worker nodes to the cluster. The reason why it is not included in Terraform is that I am using this repo currently to teach how the student can build a Kubernetes cluster manually using Terraform on AWS. Using the node startup script is an advanced stage that I may include in a future lecture/course.
So, yes, you can fork the repo and use the node startup script. It works with no known issues.

@briankosw
Copy link
Author

I see. That's great! Could you help me understand how the script ensures that only one of the master nodes run kubeadm init and the rest run kubeadm join? I've written a script that is similar in concept to yours, but I've been unable to convince myself that I can guarantee that only one master node initializes a cluster.

@abohmeed
Copy link
Owner

Simply, loop over all the master nodes over SSH and execute the init command there. If the server replies, exit the loop. Otherwise, continue looping. Once done, loop on the rest of the master/worker nodes and execute the join command.
On AWS, it's easy to get the master and worker nodes by using tags that Kubernetes already requires to be present.

@briankosw
Copy link
Author

I see. I guess the only problem that I can see is when more than one master node runs kubeadm init, which will break the cluster according to the official documentation. What about the following change:

  • Designate one master node (e.g. based on the tag as you mentioned above) as the one responsible for initializing the cluster
  • The other master nodes will wait until the cluster is initialized as is done in your script
  • Whenever a master node drops, it can first check that the cluster is up and join using your method in the script

What do you think about that?

@abohmeed
Copy link
Owner

I cannot see why more than one master node would run the init command at the same time. As I mentioned, you'll loop on the master nodes and run the command. The first one that reports the command has run successfully causes the loop to exit.
You run the loop sequentially and not in parallel so you try the servers one by one not all at once,

@pg3391
Copy link

pg3391 commented May 25, 2023

I created 3 tier k8 cluster using your code @abohmeed , Cluster is good, but I'm no way able to login to bastion host using the private even my public key both, can you share if there is any fix ?

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

No branches or pull requests

3 participants