typesense/typesense-kubernetes

Single pod and HorizontalPodAutoscaler Example

Opened this issue · 5 comments

Thanks for an awesome software and example.

This is more of a help request.

I am a startup company, and High Availability is too expensive for me, as I am dealing with a large dataset. I have about 3.2 million records similar to your airbnb example. Note that I am also self-hosting the map tiles server on the same node IoI

The example here requires to manually modify the ConfigMap and increment
typesense-{increment}.ts.typesense.svc.cluster.local:8107:8108
based on how many replicaset I have.

To be honest I am using Kubernetes only for its autoscaling capabilities.
(I mean Kubernetes without autoscaling capability doesn't worth the effort :) )

Is it possible to make a single Statefulset pod of a Typesense and horizontally auto scale it? Can it choose the typesense-0 as a master and the rest for read access, without any configuration?

+1 for more examples on auto-scale config.

+1 can you help with a helm chart example for installation or something beyond what is offered in the above

Not sure if you were asking me but the YouTube link I posted below is the best resource to learn about Statefulsets.

https://www.youtube.com/watch?v=eUa-IDPGL-Q

The Typesense helm chart basically creates a highly available or HA Statefulset of Typesense pods.
In the video, the instructor talks about mongo-db master/slave or leader/follower relationship. The very concept can be applied to Typesense.
This config map from the helm chart defines that relationship.

apiVersion: v1
kind: ConfigMap
metadata:
  name: nodeslist
  namespace: typesense
data:
  nodes: "typesense-0.ts.typesense.svc.cluster.local:8107:8108,typesense-1.ts.typesense.svc.cluster.local:8107:8108,typesense-2.ts.typesense.svc.cluster.local:8107:8108" 

The simplest method to run Typesense in Kubernetes is by using a Deployment, not a Statefulset. I chose this option as it is more straightforward to set up, as demonstrated in the provided deployment example.

apiVersion: v1
kind: Service
metadata:
  name: typesense-service
spec:
  selector:
    app: typesense
  ports:
    - name: port
      protocol: TCP
      port: 8108
      targetPort: 8108
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: typesense-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: typesense
  template:
    metadata:
      labels:
        app: typesense
    spec:
      containers:
        - name: typesense
          # NOTE : you can update to the latest release
          image: typesense/typesense:0.23.1
          command:
            - "/opt/typesense-server"
            - "-d"
            - "/usr/share/typesense/data"
            - "--api-key"
            - "xyz"
            - "--api-port"
            - "8108"
          ports:
            - containerPort: 8108
              name: http
          volumeMounts:
            - name: typesense-storage
              mountPath: /usr/share/typesense/data
      volumes:
        - name: typesense-storage
          emptyDir:
            sizeLimit: 1Gi