In today's data-driven landscape, businesses rely on insightful data analysis to gain a competitive edge and make informed decisions. To unlock the power of business intelligence (BI), deploying an effective analytics and visualization platform is crucial. Metabase, an open-source solution, offers a user-friendly interface that simplifies data exploration and understanding.

By deploying Metabase on Kubernetes, businesses can seamlessly leverage the full potential of BI. This tutorial will guide you through the process of setting up Metabase on a hosted k8s cluster for both local and production use, empowering you to unlock the valuable insights hidden within your data.

What is Metabase?

Metabase

Metabase is a free, open-source business intelligence application that lets you create reports and visualizations from your data. You don't have to be a technical expert to develop dashboards and charts that help you comprehend your data with Metabase. Metabase is simple to use and suitable for everyone, from business analysts to non-technical users.

Metabase has a variety of visualization choices, such as bar charts, line charts, scatter plots, and more. Metabase also has a robust query editor, which allows you to write custom SQL queries and filter data in order to generate the reports you require.

Metabase also provides a comprehensive REST API, which may be very handy for programmatically configuring user access, database hooks, table descriptions, and other features.

Access more resources from Metabase here:

Prerequisites

Before we can deploy Metabase on Kubernetes, we need to have the following prerequisites:

Deploying Metabase

We’re going to install the open source distribution of Metabase as a docker container, there are other options of installing it as .jar file which is by far the simplest but not recommended for production scenarios.

Note: By default, Metabase configures an internal H2 database for storing the dashboards, questions, and models made on the platform. However, you may lose all of your saved data if you don’t back it up regularly, or the container gets deleted/corrupted. To avoid losing any information, you need to provision a production-ready database to store all the application data.

Here, we'll set up a MySQL database using Civo as a production-ready DB for Metabase to store application data. You may set up any other database. Currently supported ones are - MySQL, PostgreSQL & MariaDB. More info on migrating from a running H2 instance to a production database can be found here.

Prep

Before we begin production, you will need to take the following steps:

  1. Create a new Kubernetes Cluster on Civo. We’ll go with 2 Small standard size nodes for this demo.
  2. When the cluster is up and running use the Kubeconfig file, connect your local machine to the Kubernetes cluster.
  3. export KUBECONFIG=/path/to/kubeconfig.yaml
  4. Create a separate namespace for Metabase deployment. We'll use `metabase` as the namespace.
  5. kubectl namspace create metabase

Production Database Setup

Step 1: Create a new database from the Databases dropdown list on the Civo Dashboard, make sure to keep the user and password handy.

Create a new Database on Civo

Step 2: Login to your instance and create a new database. In this example, we will name it ‘metabase’. Our Metabase installation is going to use this DB as a storage house to keep all of its data:

mysql -h <database-host> -u <user> -p <password>
mysql> CREATE DATABASE metabase;

Step 3: The next step would be to set up cron jobs to regularly & automatically backup the data for a more resilient setup.

Installing Metabase

Step 1: Create a new the Metabase deployment file. You may change the configuration as per requirements and taste:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: metabase-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: metabase
  template:
    metadata:
      labels:
        app: metabase
    spec:
      containers:
        - name: metabase-container
          image: metabase/metabase:latest
          ports:
            - containerPort: 3000  # Adjust the port as needed
          env:
            - name: MB_DB_TYPE
              value: "mysql"
            - name: MB_DB_DBNAME
              value: "metabase"
            - name: MB_DB_PORT
              value: "3306"
            - name: MB_DB_USER
              value: "<username>"
            - name: MB_DB_PASS
              value: "<password>"
            - name: MB_DB_HOST
              value: "<database-hostname/ip>"

Step 2: Replace username, password, and database-hostname/ip with your database credentials and hostname.

Keep in mind that Metabase will be connecting from within your Docker container, so make sure that either: a) you’re using a fully qualified hostname, or b) that you’ve set a proper entry in your container’s /etc/hosts file.

Step 3: Run the following command to check if the metabase deployment is ready and the corresponding pod.

kubectl get deployment
kubectl get pods

If the deployment is successfully configured, you can see a pod running for Metabase.

NAME                                  READY   STATUS    RESTARTS   AGE
metabase-deployment-c957b9b49-x7bnp   1/1     Running   0          7m57s

Step 4: In order to access the Metabase UI outisde of the kubernetes cluster we need to expose the port. We can do that using a NodePort service or LoadBalancer service.

Let's create a loadbalancer serevice using a below sample yaml file:

apiVersion: v1
kind: Service
metadata:
  name: metabase-service
spec:
  selector:
    app: metabase
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000
  type: LoadBalancer
kubectl apply -f metabase-service.yaml

Once the service is created, you can access the Metabase UI outside the cluster. Open your browser and navigate to http://{external-ip:3000 to access Metabase.

Metabase UI

Step 5: Follow the prompts to set up your Metabase account and connect to your database via Admin settings.

Setting up your Metabase account

That's it! You now have Metabase up and running on Civo, ready to help you unlock the power of business intelligence. Later on, the access management, SSO, or LDAP configurations can be managed easily from here.

Summary

From this tutorial, we have found that deploying Metabase on Kubernetes can help businesses unlock the power of business intelligence by providing a flexible and scalable platform for data exploration and understanding.

By following the steps outlined in this blog post, you can set up Metabase on a hosted kubernetes cluster and start leveraging the insights hidden within your data. Don't forget to provision a production-ready database (in case of production use) to store all of your application data and regularly back it up to ensure resiliency and prevent data loss.

If you're interested in learning more about this topic, check out these other resources: