Adding a worker to a K8S cluster
- Vertical or horizontal scalability: advantages and dependencies.
- Installing Rocky Linux on a physical server.
- Handling prerequisites with Ansible.
- Adding the node to the cluster, even if it differs from existing configurations.
Introduction
The advantage of a solution like Kubernetes is that it can be easily scaled according to two models:
- Vertical: we maintain the number of worker nodes, but increase their capacity: adding RAM, CPU, etc. This scalability is even simpler in a virtual environment, where nodes in the form of VMs can have their characteristics updated quickly based on available resources on the underlying hypervisor.
- Horizontal: we increase the number of worker nodes to add capacity to the cluster by deploying new servers.
The first case is often simpler to implement, but the more you increase the capabilities of a worker, the more you increase the cluster's dependence on it. If a node with a large amount of resources were to fail, it would inevitably impact more applications because it is capable of running more of them.
In the case of horizontal scalability, we increase the complexity of the cluster, but distribute the resources more evenly.
Adding a worker-type node under K8S is very simple, provided that a server, physical or virtual, has sufficient prerequisites; adding it to an existing cluster takes only a few minutes.
This article aims to provide an example of adding a worker, but also highlights Kubernetes' ability to mix servers of different types and configurations.
Besides scalability needs, you may need to dedicate nodes to specific application profiles. Thanks to node tagging and the possible instructions around K8S objects, you can segment your cluster by type of use.
You can configure certain nodes to run specific assets that require characteristics that cannot be found on other servers in the cluster.
In my case, I will expand my Kubernetes cluster presented in my cookbook and based on my lab infrastructure, by adding a physical node.
I am reusing much of what I already explained in various steps of setting up a K8S cluster. I strongly encourage you to read the part covering the deployment of the configuration with Ansible, as I will reuse this logic to prepare my new server.
Normally, I use VMs running PhotonOS. However, I would like to have a more powerful worker node to run applications that may require significant resources. Fortunately, I found an old mini PC from an obscure Chinese brand (XCY) in the back of my closet that I had somewhat upgraded with a larger hard drive and more memory.
Despite being from 2020, with a 4-core CPU (i5-8259U), 32GB of RAM, and a 512GB SSD, it has the potential to be given a new lease on life within my cluster.
To avoid the "multi-brand" aspect of Kubernetes, I will not deploy PhotonOS, but rather Rocky Linux 9.4. This is a much more standard operating system, resulting from the changes made by Red Hat around CentOS, which led the original creator of CentOS to develop this Rocky Linux. The goal is to continue offering an operating system compatible with RHEL (Red Hat Enterprise Linux) binaries while being 100% free and open-source.
This is a very good choice for professional use, with a large community and excellent stability.
The idea is also to include it in my Ansible playbooks, so that I can deploy the K8S prerequisites in the same way as for my VMs running PhotonOS.

Click the image to enlarge.
Installing Rocky Linux
I will not detail the installation of Rocky Linux. The system is installed from an ISO image copied to a USB drive and has an assisted installer similar to what you find in the Red Hat family of operating systems.
I started with the minimal ISO. I simply configured an IP address on my LAN, a hostname prdk8snod001 (with the suffix .coolcorp.priv for the full name), a user account, and left the default partitioning options.
Integration with Ansible
Once started and accessible via SSH, I applied the same basic settings as my PhotonOS template to make it accessible to my Ansible instance deployed on my workstation via WSL.
- Creation of a user account ansible-windows (using the same name as the account I use on my Ansible instance).
- Switch to the profile of this user for:
- Create a public/private key pair using the ssh-keygen command
- Register the public key of my Ansible user in the ~/.ssh/authorized_keys file, which is used to connect to my servers.
- Switch back to root user to create a sudo file that allows the ansible-windows account to execute root commands without requiring a password.

Click the image to enlarge.

Click the image to enlarge.
The logic is that from my workstation, I can run Ansible so that it connects via SSH to the server and can execute all the actions required by my playbooks. Feel free to refer to this article and this article for more details.
Since the server is not a VM, I will not be able to use the dynamic Ansible inventory logic based on querying my vCenter and the tags attached to the VMs (more details here).
I will simply use a static Ansible inventory in the form of a flat.inventory.yaml file. Within this file, I associate a group prdk8s with my host prdk8snod001.coolcorp.priv.
prdk8s:
hosts:
prdk8snod001.coolcorp.priv:
In this way, any role that I apply to the prdk8s group can be executed on my physical server prdk8snod001.

Click the image to enlarge.
Handling prerequisites (with Ansible)
Now that the physical node is accessible and controllable via Ansible, I will adapt my YAML files used in my Kubernetes deployment playbook to the specifics of my new worker, particularly Rocky Linux.
I will not re-explain the structure of my Ansible role role_k8s_deploy; it is detailed in this article.
I could modify it to add instructions specific to this new physical server. However, for greater convenience, I will instead clone it to create a new role role_k8s_physical_deploy to isolate the deployment of a physical node.
This is not necessarily the best way to do it. Ideally, in Ansible, you try to share as many instructions as possible and work with exceptions and conditions to be able to handle everything that could be related within the same role.
But in my case, for simplicity, I will simply reuse the configuration of my physical server in a specific role.
I will not go into detail about all the YAML files used. In general, they are identical to those used for PhotonOS, and you can find a description here.
Here is the breakdown of the role's structure:

Click the image to enlarge.

Click the image to enlarge.
In terms of packages to be installed as prerequisites, I need to modify the list slightly compared to PhotonOS to achieve the listing that I define in my var_k8s_packages_worker variable, which is contained in my main file in my defaults directory.
#Liste des paquets à déployer sur les nodes
var_k8s_packages_worker:
- kubeadm-{{ var_kub_version }}
- nfs-utils
- wget
- tar
- kubelet-{{ var_kub_version }}
- runc
(The kubeadm and kubelet packages are sourced from the official Kubernetes repositories, not the OS's default repositories. These repositories are configured during the execution of the tasks described in 01-repos.yml. Since PhotonOS and Rocky Linux both use the same package format, I didn't have to revise this part. More details are available here.)
Above all, it is the addition of runc that matters, runc being the lowest-level runtime used for containerization. Feel free to look at the second diagram here for more details.
Rocky Linux uses dnf as its package manager, so I need to change my 02-prerequis.yaml file from using the tdnf module to using dnf.
#installation des packages sur les workers (liste des paquets défini dans "main.yml" du dossier "defaults")
- name: Install basic packages for worker
become: yes
dnf:
update_cache: yes
name: "{{ var_k8s_packages_worker }}"
state: present
when: inventory_hostname.startswith('prdk8snod')
tags: role_k8s_deploy.prerequis.packages_worker
Also in this same file, I need to revise how I disable swap. Currently, K8S doesn't work well with swap, so it needs to be removed, and for my Rocky Linux installation, this requires commenting out its usage in the OS's fstab file.
- name: Permanently disable swap in /etc/fstab
become: yes
replace:
path: /etc/fstab
regexp: '^([^#].* swap .*)$'
replace: '# \1'
Still in this 02-prerequis.yaml file, I had to add the use of a template kubeadm-flags.env.j2, which contains the following content:
KUBELET_KUBEADM_ARGS="--container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.k8s.io/pause:3.9 --resolv-conf=/etc/resolv.conf"
The file must be renamed to kubeadm-flags.env and placed in /var/lib/kubelet/kubeadm-flags.env when calling Ansible. It is intended to be used by the Kubelet agent.
During my initial tests, I discovered that simply setting a parameter for kubeadm during cluster initialization in this file was not sufficient to allow the agent to start.
It is especially this option --resolv-conf=/etc/resolv.conf that needs to be added.
Next, Rocky Linux uses firewalld instead of iptables, as does PhotonOS. Therefore, I had to revise my 03-firewalld.yaml file to switch from the Ansible iptables module to the firewalld module. Since the ports and protocols used remain the same, I didn't have to review the details of port opening (just a syntax correction for port ranges, related to switching from the iptables module to firewalld).

Click the image to enlarge.
(For more details on the ports to open, you can consult this article.)
I don't need to touch the rest: it is still containerd that will be deployed from the binaries fetched directly from the website. I just need to simplify the YAML files as much as possible to remove everything that is irrelevant for a physical worker.
I remove everything related to vSphere, any prerequisites associated with a control plane node, or HAProxy.
You can find the complete role in my GitHub repository.
Now I just need to associate my static inventory and my role role_k8s_physical_deploy using the global playbook playbook_deploy_k8s_physical.yml:
---
- name: Deploy K8S Physical
hosts: prdk8s
roles:
- role_k8s_physical_deploy
Then, I run the playbook with the command ansible-playbook playbooks/playbook_deploy_k8s_physical.yml to process my physical server and configure all the necessary prerequisites under Rocky Linux to support the execution of a K8S worker node.

Click the image to enlarge.
Adding the node
Now I can finally start the operation of adding the node as such.
To do this, I connect as root on my first control plane.
I execute the command kubeadm token create --print-join-command.
This generates the instruction to be typed on my new worker so that it can join the cluster.

Click the image to enlarge.
In particular, you will find the token that allows the node to register with the K8S API. Be careful, this token is only valid for 20 minutes, so you need to use it quickly on the physical node.
I switch to root on this node and copy the line retrieved above.

Click the image to enlarge.
Kubeadm will take care of the rest, and after a few minutes, the node is added to the cluster.
You can verify this by typing the command kubectl get node from its working environment.
It is possible that the node appears as not ready for a while, because it is necessary for a certain number of components in the cluster to start and configure themselves to take into account this new node. This is the case, for example, with the CNI (Container Network Interface) Cilium (more details here).

Click the image to enlarge.
By the way, be careful about open ports; my Kubernetes cluster mixes nodes on a LAN and in a DMZ, so I had to update my firewall rules to allow the traffic necessary for the internal Cilium network established between the different servers in the cluster.

Click the image to enlarge.
Adjusting third-party components
Since this node is physical, some components do not need to run on it. This is especially true for the CSI (Container Storage Interface) vSphere driver (more details here).
By default, the driver attempts to initialize on every new node, but in this case, it will fail because it is not a VM.

Click the image to enlarge.
Therefore, we need to modify the deployment associated with the vSphere CSI so that it ignores a physical node.
But before that, we need to label and taint our new node to make it easily identifiable within the cluster.
To do this, I first apply the same network label as for my other nodes on the LAN, since it is in the same network zone. However, I also apply a new type label, setting it to physical, and a new label node-role.kubernetes.io/worker-lan-physical=.
We can observe the impact of the label if we recall the command kubectl get node.
I also apply a taint to my node using the following command:
kubectl taint nodes prdk8snod001 node-role.kubernetes.io/worker-lan-physical=:NoSchedule

Click the image to enlarge.

Click the image to enlarge.
As a reminder, a taint allows us to mark a server to prevent it from being used by a pod unless that pod is explicitly configured with a toleration for this marking.
To be certain that my vSphere CSI does not apply, I will modify the configuration of the associated K8S object.
I edit the vsphere-csi-driver.yaml file that I use to deploy the CSI (more details here). This file contains the definition of the DaemonSet object, named vsphere-csi-node. A DaemonSet is similar to a deployment, but its characteristic is to automate the deployment of the attached pod on every new node that joins the cluster and meets the eligibility criteria of the DaemonSet.
This is useful in cases where we want to ensure that a component is always running on each node, from the moment it is added to the cluster.
In my example, however, this is problematic because the driver attempts to initialize on a server that is not compatible. Therefore, I need to modify the DaemonSet to include an affinity setting, in which I explicitly state that the pod can only be deployed on a node that does not have the physical label.
---
kind: DaemonSet
apiVersion: apps/v1
metadata:
name: vsphere-csi-node
namespace: vmware-system-csi
spec:
selector:
matchLabels:
app: vsphere-csi-node
updateStrategy:
type: "RollingUpdate"
rollingUpdate:
maxUnavailable: 1
template:
metadata:
labels:
app: vsphere-csi-node
role: vsphere-csi
spec:
priorityClassName: system-node-critical
nodeSelector:
kubernetes.io/os: linux
serviceAccountName: vsphere-csi-node
hostNetwork: true
dnsPolicy: "ClusterFirstWithHostNet"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: type
operator: NotIn
values:
- physical

Click the image to enlarge.
I apply my updated file:
Kubectl apply -f vsphere-csi-driver.yaml
Thus, the CSI will disappear, and K8S will no longer attempt to deploy it on my new physical worker node.

Click the image to enlarge.
Conclusion
My cluster now has a special node, which is not based on a VM running PhotonOS, but on a physical server running Rocky Linux 9.4.
Thanks to its specific marking, I can precisely control what I want to run on it.
This article might seem long just to explain how to add a worker node to an existing cluster, but as you may have noticed, this operation is extremely simple and quick.
However, my intention was to demonstrate the ability of a Kubernetes cluster to host servers of different types and with different operating systems.
Furthermore, choosing tools like Ansible as a deployment solution isn't restrictive, since we can modify existing configurations and adapt them to the specifics of the new target.
Kubernetes is an open platform that can be adapted to many uses. Depending on your skills and preferences, a K8S cluster can be deployed in various ecosystems, and you can configure your nodes as you see fit.
On my end, I just need to leverage this new server: for the AI-based use case, it's right here!