Deploying a SolidJS application on Kubernetes can seem challenging for beginners, but with a clear step-by-step process, it becomes manageable. This tutorial guides you through the essential steps to containerize your SolidJS app and deploy it on a Kubernetes cluster.

Prerequisites

  • Basic knowledge of SolidJS and JavaScript
  • Docker installed on your machine
  • Kubernetes cluster (local or cloud-based)
  • kubectl configured to interact with your cluster
  • kubectl and Docker installed

Step 1: Build Your SolidJS Application

Ensure your SolidJS app is ready for deployment. Run the build command to generate static files:

npm run build

This creates a dist directory with your static assets.

Step 2: Containerize Your Application

Create a Dockerfile in your project root:

FROM nginx:alpine
COPY ./dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Build your Docker image:

docker build -t solidjs-app:latest .

Test your container locally:

docker run -p 8080:80 solidjs-app:latest

Open your browser and navigate to http://localhost:8080 to verify the deployment.

Step 3: Push Docker Image to Registry

Tag your image for your container registry (e.g., Docker Hub):

docker tag solidjs-app:latest yourdockerhubusername/solidjs-app:latest

Login to Docker Hub:

docker login

Push the image:

docker push yourdockerhubusername/solidjs-app:latest

Step 4: Create Kubernetes Deployment and Service

Write a deployment YAML file (solidjs-deployment.yaml):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: solidjs-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: solidjs
  template:
    metadata:
      labels:
        app: solidjs
    spec:
      containers:
      - name: solidjs
        image: yourdockerhubusername/solidjs-app:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: solidjs-service
spec:
  type: LoadBalancer
  selector:
    app: solidjs
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

Apply the configuration:

kubectl apply -f solidjs-deployment.yaml

Check the status of your deployment and service:

kubectl get deployments
kubectl get services

Step 5: Access Your Application

If your cluster provides an external IP, access your app via the LoadBalancer IP:

kubectl get service solidjs-service

Open the external IP in your browser to see your SolidJS app running on Kubernetes.

Conclusion

Deploying a SolidJS application on Kubernetes involves building, containerizing, pushing the image, and creating deployment configurations. With these steps, beginners can confidently deploy their static SolidJS apps on any Kubernetes cluster, making their projects scalable and production-ready.