Advertisement
Automated Provisioning & Deployment

Writing a Bash Script to Provision a Kubernetes Node on Ubuntu

k8s bash script kubeadm automation ubuntu kubernetes node setup

Stop Wasting Time on Manual Node Joins

A frustrated sysadmin staring at a glowing terminal full of red error logs, cyberpunk style, dark room, neon blue and red lighting, highly detailed --ar 16:9

Setting up a Kubernetes node by hand is a miserable experience. You miss one step, and suddenly your whole cluster throws a tantrum. Actually, it's completely unnecessary. Why run twenty separate commands when a single k8s bash script can do the heavy lifting? Let's automate this mess. We're going to build a script that takes a fresh Ubuntu box and turns it into a ready-to-join worker node in under two minutes. Zero friction. Just pure, unadulterated automation.

Advertisement

Killing Swap and Feeding the Kernel

A glowing microchip dissolving a physical metallic lock, macro photography, hyper-realistic, dark background with subtle green matrix code --ar 16:9

First things first. Kubernetes hates swap space. It will flat-out refuse to work if you leave it on. Our script needs to nuke swap immediately. A quick swapoff command does the trick for the current session, but we also need to rip it out of your fstab file so it doesn't resurrect after a reboot. Next up, the kernel. We have to load the overlay and br_netfilter modules. This is non-negotiable for pod networking. Without them, your containers are just isolated islands. Add a quick sysctl reload, and the foundation is set.

Dropping Containerd into the Mix

A futuristic robotic assembly line putting together glowing blue shipping containers, cinematic lighting, industrial sci-fi aesthetic, 8k resolution --ar 16:9

Docker is dead in the k8s world. We're using containerd. It's leaner, faster, and officially supported. Your kubeadm automation ubuntu script needs to grab the necessary prerequisites, add the official GPG key, and install the containerd package. But we aren't done yet. You have to generate the default configuration file and patch it to use systemd as the cgroup driver. If you skip this part, your node will eventually crash and burn under heavy load. A quick string replacement command in our bash script handles this silently.

Installing the Kubernetes Holy Trinity

Now for the actual core components. Kubelet, kubeadm, and kubectl. You need to pull the public signing key and add the Kubernetes apt repository. Here's the thing. Don't just blindly install the latest packages. Pin your versions. If you let the package manager grab the newest release every time the script runs, you're going to end up with version mismatches across your cluster. Pin them, lock them in place, and sleep soundly knowing your kubernetes node setup won't randomly break next Tuesday.

Firing the Script and Walking Away

That's the entire payload. Wrap those commands in an executable file and let it rip. The next time you spin up a fresh Ubuntu VM, you just pipe this script into bash. Go grab a coffee. When you get back, the machine will be perfectly primed and waiting for your join token. No typos. No forgotten steps. Just a perfectly identical configuration every single time you need to scale out your infrastructure.

Advertisement