DEV Community

Cover image for How to self-host any open source service?
Sibelius Seraphini for Woovi

Posted on

How to self-host any open source service?

Self-hosting an open-source service can provide greater control, privacy, and customization options than managed services. Kubernetes (K8s) is a powerful orchestration tool that simplifies deploying, scaling, and managing containerized applications.

This is a practical of getting an open-source self-hosted service and deploying to a k8s cluster. We recommend searching and trying in this respective order:

Helm Chart

Search for an existing Helm Chart for the service that you want to self-host. Search like: <service> helm chart
Helm Charts are like packages for k8s.
You just need to setup a values.yaml to customize to your own needs.

Imagine that I want to self-host n8n service.
I found the n8n helm chart

You create a folder inside deployment/n8n

and you create 2 files

Chart.yaml

apiVersion: v2
name: n8n
version: 1.0.0
dependencies:
  - name: n8n
    repository: oci://8gears.container-registry.com/library
    version: 0.25.2
Enter fullscreen mode Exit fullscreen mode

and

values.yaml

config:
  database:
    type: postgresdb
    postgresdb:
      host: pg.n8n
      database: n8n
      user: n8n
      password: safepassword
image:
  tag: '1.73.1'
Enter fullscreen mode Exit fullscreen mode

You can just run helm install to install your chart to a k8s cluster.

helm install n8n ./deployments/n8n -f ./deployments/n8n/values.yaml -n n8n
Enter fullscreen mode Exit fullscreen mode

You could also use ArgoCD to sync it if you are using GitOps.
Check how to setup ArgoCD in this article: Bootstrapping ArgoCD with Helm and Helmfile

If this didn't work in the first try, check pods, check logs, modify values.yaml, read the yamls of the helm chart to understand what is breaking

Pure Kubernetes setup

If you didn't get luck to fine a good helm chart or any helm chart for the service you want to self host, try to search only by <service> kubernetes

If you file, just copy the yamls files and modify them to your use case. It probably gonna have at least one deployment and one service file.

Docker Compose

If there is no resource about self hosting the service using kubernetes, let's fallback to docker compose. Search like this: <service> docker compose.
If you find a docker-compose.yaml file, read it to understand all the services that are required to run the service you want to self host.
You can remove any optional service to simplify your setup, and add them back later on.
I recommend having some shared resources like databases in a different deployment so you can reuse ithem n different self-hosted services.
This makes self-hosting faster, easier, and cheaper.
Do not reuse resources/services if this is a critical production service.

You need to translate the docker-compose to k8s yamls, you can use chatgpt if you don't know how to translate, but it will be mostly some deployments and some services. Or try Kompose.io.

Here is an example of deployment of n8n based on a docker-compose.yaml

n8n-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: n8n
  name: n8n-server
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 2
  selector:
    matchLabels:
      app: n8n-server
  template:
    metadata:
      labels:
        app: n8n-server
    spec:
      containers:
        - name: n8n-server
          image: docker.n8n.io/n8nio/n8n:latest
          imagePullPolicy: Always
          resources:
            requests:
              cpu: 100m
          ports:
            - containerPort: 5678
          envFrom:
            - secretRef:
                name: n8n-secrets
Enter fullscreen mode Exit fullscreen mode

n8n-service.yaml

apiVersion: v1
kind: Service
metadata:
  namespace: n8n
  name: n8n-server
spec:
  selector:
    app: n8n-server
  ports:
    - protocol: TCP
      port: 5678
      targetPort: 5678
Enter fullscreen mode Exit fullscreen mode
apiVersion: v1
kind: Secret
metadata:
  name: n8n-secrets
  namespace: n8n
stringData:
   N8N_HOST: "n8n.dev.to"
Enter fullscreen mode Exit fullscreen mode

The deployment will run a number of instances of n8n, and service will enable us to expose to a nginx/ingress or loadbalancer.
Keep all secrets in a secret config or use a vault solution.
You can also self-host a vault solution.

Docker

Follow the same steps as docker compose, and transform a single docker image in 1 deployment and 1 service like above changing the image to your service docker image.

None of the above

If your service does not even have a docker image, you can create a Dockerfile from scratch to create an image.
You can host this image in any docker registry.
You can also self-host the docker registry.

Conclusion

By following these steps, you can self-host any open-source service using Kubernetes, giving you full control and flexibility. While Kubernetes has a learning curve, the long-term benefits of scalability, reliability, and customization make it worth the effort

What services does not fit any of the above?


Woovi is a fintech platform revolutionizing how businesses and developers handle payments in Brazil. Built with a developer-first mindset, Woovi simplifies integration with instant payment methods like Pix, enabling companies to receive payments seamlessly and automate financial workflows.

If you want to work with us, we are hiring!

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.