Auto joining newly created VM/Servers as kubernetes node to master

10/23/2021

Hi I am working on Google Cloud platform where I am not using GKE. Rather I am creating k8s cluster manually. Following is my setup, Total 11 server 1. Out of these 5 servers would be static servers and don't need any scaling 2. remaining 5 server would need up scaling if CPU or RAM consumption goes beyond certain limit. i.e. I will spin only 3 servers initially and if CPU/RAM threshold is crossed then I will spin 2 more using Google Cloud Load balancer. 3. 1 k8s Master server

To implement this load balancer I have already created one Custom Image on which I have installed docker and kubernetes. Using this I have create one instance template and then instance group.

Now the problem statement is , Although I have created image with everything installed , When I am creating a instance group in which 3 VM are being created , these VMs does not automatically connect to my k8s master. Is there any way to automatically connect newly created VM as a node to k8s master so that I do not have run join command manually on each server ?

Thanks for the help in advance.

-- TheAkashKamble
google-cloud-platform
kubernetes
kubernetes-pod

1 Answer

10/26/2021

so that I do not have run join command manually on each server

I am assuming that you can successfully run the join command to join the newly created VMs to the Kubernetes master manually. <br> If that is the case, you can use the startup-script feature in the Google Compute Engine. <br> Here is the documentation: <br> https://cloud.google.com/compute/docs/instances/startup-scripts <br> https://cloud.google.com/compute/docs/instances/startup-scripts/linux#passing-directly <br> <br> In short, startup-script is the feature from Google Compute Engine to automatically run our customized script during start-up.

And, the script could look something like this:

#! /bin/bash
kubeadm join .......
-- Hartono Wen
Source: StackOverflow