Ensure you have the following prerequisites on your master and worker nodes:
- A Linux-based environment.
- Node.js and npm installed on the master node for running the deployment service.
First, set up your master node to initiate the Kubernetes cluster and start the Node.js deployment service.
Navigate to your project directory and install the required Node.js dependencies:
npm install
Execute the MasterSetup.sh script:
sh MasterSetup.sh
This script performs the following actions:
Installs k3s on the master node. Saves the k3s node join token to k3s-node-token.txt Starts the Node.js application that listens for deployment requests on port 3000.
After setting up the master node, add worker nodes to the cluster using the join token.
On each worker node, run the WorkerSetup.sh script with the worker's name, master node's IP address, and the join token present in the k3s-node-token.txt
file:
sh WorkerSetup.sh <worker-name> <master-ip> <token>
Replace , , and with your specific details.
With the cluster ready, you can now deploy applications using the Node.js API.
Send a POST request to /deploy endpoint with the Docker image URL:
curl -X POST http://<master-node-ip>:3000/deploy \
-H "Content-Type: application/json" \
-d '{"imageUrl": your_public_docker_image}'
This request deploys the specified Docker image as a Kubernetes deployment and creates a NodePort service to expose it.
The API response includes the NodePort assigned to the service. Access your deployment using master node IP address and the provided NodePort:
http://<node-ip>:<NodePort>