This file provides step-by-step instructions to set up a Kubernetes cluster using K3S with a master node and multiple worker nodes.
- Master Node Requirements: Ubuntu OS with 2 CPU cores (VM can be used).
- Worker Nodes: Raspberry Pi devices or equivalent.
For each master and node:
- SSH into each node:
ssh user@<node-ip>
- Get the default gateway IP:
Save the default gateway IP.
ip route | grep default
- Configure static IP:
- Run the following command:
sudo nmtui
- Select Edit a connection.
- Edit the wired connection:
- Set IPv4 configuration to
Manual
. - Add a static IP address (e.g.,
192.168.0.xxx
, different for each node). - Set DNS servers to
8.8.8.8
and1.1.1.1
.
- Set IPv4 configuration to
- Save and exit the network manager.
- Run the following command:
-
Prepare the environment:
- Use Ubuntu OS with 2 CPU cores.
- Edit the GRUB configuration:
Add the following line:
sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX="cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory"
- Apply changes:
sudo update-grub sudo reboot
-
Install K3S:
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -s
-
Verify K3S installation:
systemctl status k3s
-
Retrieve cluster information:
kubectl cluster-info
-
Save the token for nodes:
sudo cat /var/lib/rancher/k3s/server/node-token > ~/.kube/node_token cat ~/.kube/node_token
Save the token for later use.
-
SSH into each worker node:
ssh pi@<node-ip>
-
Install K3S on each worker node: Replace
<master-token>
with the token from the master node and<master-ip-address>
with the master node's IP address.curl -sfL https://get.k3s.io | K3S_TOKEN="<master-token>" K3S_URL="https://<master-ip-address>:6443" K3S_NODE_NAME="<node-name>" sh -s
-
Verify K3S agent:
sudo systemctl status k3s-agent
-
Check the cluster from the master node:
sudo kubectl get nodes
- Ensure all nodes have unique static IPs within the same subnet.
- The token retrieved from the master node is required for connecting worker nodes.
- Use
kubectl
commands on the master node to monitor and manage the cluster.
By following these steps, you can successfully set up a Kubernetes cluster using K3S.
This README provides step-by-step instructions for deploying a weather application and configuring the Kubernetes cluster to schedule specific workloads on the master node while preventing others from running there.
- Kubernetes cluster up and running.
kubectl
installed and configured.- YAML configuration files for the backend, logger, notifications, predictions, and ingress services.
Apply all configuration files to deploy the components of the weather application.
kubectl apply -f ./kube_file/weather_backend.yml
kubectl apply -f ./kube_file/weather_logger.yml
kubectl apply -f ./kube_file/weather_predict.yml
kubectl apply -f ./kube_file/weather_notification.yml
kubectl apply -f ./kube_file/ingress.yml
Label the master node to identify it as masterNode
.
kubectl label node masterNode node-role.kubernetes.io/master=true
Update the ingress-nginx-controller
Deployment to include a nodeSelector
in the Pod template spec. This ensures the Pods are scheduled only on the master node.
kubectl patch deployment ingress-nginx-controller -n ingress-nginx \
--type='json' \
-p='[{"op": "add", "path": "/spec/template/spec/nodeSelector", "value": {"node-role.kubernetes.io/master": "true"}}]'
Add a taint to the master node to prevent other Pods from being scheduled on it unless they explicitly tolerate the taint.
kubectl taint nodes masterNode dedicated=master:NoSchedule
Update the ingress-nginx-controller
Deployment to include a toleration, allowing it to bypass the taint and be scheduled on the master node.
kubectl patch deployment ingress-nginx-controller -n ingress-nginx \
--type='json' \
-p='[{"op": "add", "path": "/spec/template/spec/tolerations", "value": [{"key": "dedicated", "operator": "Equal", "value": "master", "effect": "NoSchedule"}]}]'
- Backend Service:
weather_backend.yml
- Logger Service:
weather_logger.yml
- Notification Service:
weather_notification.yml
- Prediction Service:
weather_predict.yml
- Ingress Configuration:
ingress.yml
- Node Label: Added label
node-role.kubernetes.io/master=true
tomasterNode
. - NodeSelector: Ensured
ingress-nginx-controller
Pods are scheduled onmasterNode
using a NodeSelector. - Taint: Prevented scheduling of other Pods on
masterNode
with the taintdedicated=master:NoSchedule
. - Toleration: Allowed
ingress-nginx-controller
Pods to bypass the taint with a toleration.
- Ensure the
masterNode
name is correctly replaced in the commands above. - Verify the changes using
kubectl describe node masterNode
andkubectl describe deployment ingress-nginx-controller -n ingress-nginx
.
By following these steps, you ensure the weather application's ingress controller runs exclusively on the master node while maintaining control over Pod scheduling.