Initialize Doris Cluster

This document describes how to initialize the passwords of root and admin accounts for Doris clusters on Kubernetes, and how to initialize the database by executing SQL statements automatically in batch.

Note
  • The following steps apply only when you have created a cluster for the first time. Further configuration or modification after the initial cluster creation is not valid.

Configure DorisInitializer

You can configure the account passwords and SQL initialization behavior for the Doris cluster by setting up the DorisInitializer Custom Resource.

A basic DorisInitializer CR sample

doris-initializer.yaml

apiVersion: al-assad.github.io/v1beta1
kind: DorisInitializer
metadata:
  name: basic-init
spec:
  # Target doris cluster name
  cluster: basic
  image: tnir/mysqlclient:1.4.6

  # The number of retries for the initialization script
  maxRetry: 3

  # Changes the default root & admin user password for Doris.(optional)
  rootPassword: ""
  adminPassword: ""

  # Doris initialization sql script.(optional)
  initSqlScript: |
    CREATE DATABASE IF NOT EXISTS DEMO;
    USE DEMO;
    CREATE TABLE IF NOT EXISTS demo.example_tbl(
      `user_id` LARGEINT NOT NULL,
      `date` DATE NOT NULL,
      `city` VARCHAR(20),
      `age` SMALLINT COMMENT,
      `sex` TINYINT COMMENT,
      `last_visit_date` DATETIME REPLACE DEFAULT "1970-01-01 00:00:00",
      `cost` BIGINT SUM DEFAULT "0",
      `max_dwell_time` INT MAX DEFAULT "0",
      `min_dwell_time` INT MIN DEFAULT "99999"
    )
      AGGREGATE KEY(`user_id`, `date`, `city`, `age`, `sex`)
      DISTRIBUTED BY HASH(`user_id`) BUCKETS 1
      PROPERTIES (
        "replication_allocation" = "tag.location.default: 1"
      );
    INSERT INTO example_tbl VALUES
      (1, '2021-01-01', 'Vienna', 18, 1, '2021-01-01 00:00:00', 20, 10, 10),
      (2, '2021-01-02', 'Frankfurt', 20, 1, '2021-04-01 6:00:00', 15, 2, 2),
      (3, '2021-05-02', 'Milan', 32, 0, '2021-07-01 23:00:00', 30, 11, 11),
      (4, '2021-06-12', 'Vienna', 22, 0, '2021-08-02 08:00:00', 11, 6, 6);    
A advanced DorisInitializer CR sample

doris-initializer.yaml

apiVersion: al-assad.github.io/v1beta1
kind: DorisInitializer
metadata:
  name: basic-init
spec:
  ## Target doris cluster name
  cluster: basic

  ## Doris initializer image, it's actually a mysql client image with python runtime.
  image: tnir/mysqlclient:1.4.6

  ## ImagePullPolicy of Doris monitor Pods
  ## Ref: https://kubernetes.io/docs/concepts/configuration/overview/#container-images
  # imagePullPolicy: IfNotPresent

  ## Ref: https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod
  # imagePullSecrets:
  # - name: secretName

  ## Specifies the service account for prometheus/grafana/loki/promtail components.
  # serviceAccount: ""

  ## Tolerations are applied to Doris cluster pods, allowing (but do not require) pods to be scheduled onto nodes
  ##  with matching taints.
  ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
  # tolerations: []

  ## Describes the compute resource requirements.
  ## Ref: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
  # requests:
  #   cpu: 100m
  #   memory: 100Mi
  # limits:
  #   cpu: 2000m
  #   memory: 2Gi

  # The number of retries for the initialization script.
  maxRetry: 3

  # Changes the default root & admin user password for Doris.(optional)
  rootPassword: ""
  adminPassword: ""

  # Doris initialization sql script content.(optional)
  initSqlScript: ""
Note
It is recommended to organize Doris cluster configurations under the ${cluster_name} directory and save them as ${cluster_name}/doris-initializer.yaml.

Set the Name of the Doris Cluster

In the ${cluster_name}/doris-initializer.yaml file, modify the spec.cluster field to correspond to the metadata.name of the DorisCluster CR:

spec:
  cluster: ${cluster_name}

Setting the Initial Account Passwords

When the Doris cluster is created, the root and admin accounts are created by default, but their passwords are empty, which can pose some security risks. You can set the initial passwords as follows:

spec:
  # ...
  rootPassword: "your password"
  adminPassword: "your password"

Set the Initialization SQL Script

The cluster can also automatically execute the SQL statements in batch in initSqlScript during the initialization. This function can be used to create some databases or tables for the cluster and perform user privilege management operations.

spec:
  # ...
  initSqlScript: |
    CREATE DATABASE app;
    GRANT ALL PRIVILEGES ON app.* TO 'developer'@'%';    

Initialize the cluster

kubectl apply -f ${cluster_name}/doris-initializer.yaml --namespace=${namespace}

The above command will automatically create an initialization Job. Once initialization is complete, the Pod’s status will change to Completed.

To check the status of the initialization task, run the following command:

kubectl get dorisinitializer ${dorisinitializer.metadata.name} -n ${namespace} -o yaml