[Kubernetes (K8S)] Helm install PostHog to provide product analytics stack within Kubernetes (K8S)

PostHog

PostHog provides open-source product analytics, built for developers. Automate the collection of every event on your website or app, with no need to send data to 3rd parties. With just 1 click you can deploy on your own infrastructure, having full API/SQL access to the underlying data.

This article is about how to use Helm to install PostHog on Kubernetes (K8S).

Prerequisites

  • Kubernetes (K8S)
    Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.

    For more information about installing and using Kubernetes (K8s), see the Kubernetes (K8s) Docs.

  • Helm
    Helm is the best way to find, share, and use software built for Kubernetes.

    For more information about installing and using Helm, see the Helm Docs.

How to Install

Helm install posthog into posthog namespace.

1
2
3
4
5
6
7
8
9
10
11
# crate namespace:
$ kubectl create namespace posthog

# Add the Stable Helm repository:
$ helm repo add posthog https://posthog.github.io/charts/

# Update your local Helm chart repository cache:
$ helm repo update

# To install Helm chart:
$ helm install posthog posthog/posthog -n posthog -f values.yaml

See Helm release about posthog

1
2
3
$ helm list --namespace posthog
NAME NAMESPACE REVISION UPDATED STATUS CHART
posthog posthog 1 2021-01-23 11:19:51.65893 +0800 +0800 deployed posthog-1.20.0 v1.4.4

See pods about posthog.

1
2
3
4
5
6
7
8
9
10
11
12
13
$ kubectl get pods -n posthog
NAME READY STATUS RESTARTS AGE
posthog-beat-598b5654ff-n7f4p 1/1 Running 3 2d8h
posthog-metrics-7d5469b975-mv5zw 1/1 Running 0 2d8h
posthog-plugins-6fbbc5749d-dc9br 1/1 Running 0 2d8h
posthog-plugins-6fbbc5749d-dcc28 1/1 Running 0 2d8h
posthog-posthog-postgresql-0 1/1 Running 1 2d10h
posthog-posthog-redis-master-0 1/1 Running 0 2d8h
posthog-posthog-redis-slave-0 1/1 Running 0 2d8h
posthog-posthog-redis-slave-1 1/1 Running 0 2d8h
posthog-web-f5757799-sxfpm 1/1 Running 1 2d8h
posthog-worker-587f698956-sn8lt 1/1 Running 0 2d8h
posthog-worker-587f698956-xqrn9 1/1 Running 1 2d8h

Custom values.yaml

Remember to replace content within {{ }} with your prefer value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# values.yaml

# charts/values.yaml at master · PostHog/charts
# https://github.com/PostHog/charts/blob/master/charts/posthog/values.yaml

posthogSecret: {{ .Values.posthogSecret }}

# Name of the service and what port to expose on the pod
# Don't change these unless you know what you're doing
service:
type: ClusterIP

## Configure ingress resource that allow you to access the
## PostHog installation. Set up the URL
## ref: http://kubernetes.io/docs/user-guide/ingress/
##
ingress:
enabled: true
hostname: {{ .Values.ingress.hostname }}

## Ingress annotations
##
annotations:
kubernetes.io/ingress.class: "nginx"
# kubernetes.io/tls-acme: "true"

certmanager.k8s.io/acme-challenge-type: http01
certmanager.k8s.io/cluster-issuer: {{ .Values.clusterIssuer }}
# cert-manager.io/acme-challenge-type: dns01
# cert-manager.io/cluster-issuer: cert-manager-webhook-dnspod-cluster-issuer

## Ingress TLS configuration
## Secrets must be manually created in the namespace
##
tls:
- secretName: {{ .Values.ingress.secretName }}
hosts:
- {{ .Values.ingress.hostname }}

## Prometheus Exporter / Metrics
##
metrics:
enabled: true

Web UI

Then, you can visit https://{{ .Values.ingress.hostname }} to access PostHog Web UI.

FAQS

502 Bad Gateway

PostHog may fail to initialize or upgrade database since it will take too long. You can do it yoursef.

First, enter into Pod posthog-web bash.

1
$ kubectl exec -n posthog `kubectl get pods -n posthog | grep posthog-web | awk '{print $2}'` -it -- bash

Then, run posthog upgrade within container to run all migrations and create an admin account.

1
$ python manage.py migrate

Finally, you can visit Web UI without any error.

References

[1] Deploying with Helm Chart (Kubernetes) - PostHog Docs - https://posthog.com/docs/deployment/deploy-kubernetes

[2] charts/values.yaml at master · PostHog/charts - https://github.com/PostHog/charts/blob/master/charts/posthog/values.yaml

[3] PostHog - Open-Source Product Analytics - https://posthog.com/

[4] PostHog/posthog: 🦔 PostHog is developer-friendly, open-source product analytics. - https://github.com/PostHog/posthog

[5] Helm - https://helm.sh/

[6] Kubernetes - https://kubernetes.io/