Skip to content

Commit

Permalink
support STARROCKS_ROOT
Browse files Browse the repository at this point in the history
Signed-off-by: yandongxiao <[email protected]>
  • Loading branch information
yandongxiao committed Nov 19, 2024
1 parent 06af429 commit 39d3274
Show file tree
Hide file tree
Showing 13 changed files with 387 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ gen-crd-api-reference-docs-master/
*.tgz

temp/
cmd/cmd
269 changes: 269 additions & 0 deletions doc/setup-starrocks-when-readOnlyRootFilesystem-is-true.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
# Background

StarRocks has three components: Frontend (FE), Backend (BE), and Compute Node(CN). When the `readOnlyRootFilesystem` is
set to `true`, the components of StarRocks cannot start normally. This is because the components of StarRocks write data
to the disk, and the `readOnlyRootFilesystem` setting prevents the components from writing data to the disk.

For the FE component, FE writes data to the following directories:

```bash
# in fe directory
drwxr-xr-x 2 root root 4.0K Nov 19 11:27 plugins
drwxr-xr-x 4 root root 4.0K Nov 19 11:27 temp_dir

# in fe/bin directory
-rw-r--r-- 1 root root 2 Nov 19 11:27 fe.pid

# in fe/conf directory
lrwxrwxrwx 1 root root 30 Nov 19 11:27 fe.conf -> /etc/starrocks/fe/conf/fe.conf
```

For the BE component, BE writes data to the following directories:

```bash
# in be directory
drwxr-xr-x 2 root root 4.0K Nov 19 11:27 spill

# in be/conf directory
lrwxrwxrwx 1 root root 30 Nov 19 11:27 be.conf -> /etc/starrocks/be/conf/be.conf

# in be/bin directory
-rw-r----- 1 root root 3 Nov 19 11:27 be.pid

# in be/lib directory
drwxr-xr-x 2 root root 4.0K Nov 19 11:27 jdbc_drivers
drwxr-xr-x 2 root root 4.0K Nov 19 11:27 small_file
drwxr-xr-x 130 root root 4.0K Nov 19 11:27 udf
drwxr-xr-x 2 root root 4.0K Nov 19 11:27 udf-runtime
```

This document describes how to set up StarRocks when the `readOnlyRootFilesystem` field is set to `true`.

# How

We create and mount a volume, and in the entrypoint script, we will copy everything from the original directory to the
mounted volume. This way, the components of StarRocks can write data to the mounted volume.

> Note: you should use the operator version `v1.9.9` or later.
# Steps

There are two ways to deploy StarRocks cluster:

1. Deploy StarRocks cluster with `StarRocksCluster` CR yaml.
2. Deploy StarRocks cluster with Helm chart.

Therefore, there are two ways to set up StarRocks when the `readOnlyRootFilesystem` field is set to `true`.

## By using StarRocksCluster CR yaml

```yaml
apiVersion: starrocks.com/v1
kind: StarRocksCluster
metadata:
name: kube-starrocks
namespace: starrocks
spec:
starRocksFeSpec:
command: [ "bash", "-c" ]
args:
- cp -r /opt/starrocks/* /opt/starrocks-artifacts && export STARROCKS_ROOT=/opt/starrocks-artifacts && exec /opt/starrocks-artifacts/fe_entrypoint.sh $FE_SERVICE_NAME
readOnlyRootFilesystem: true
configMapInfo:
configMapName: kube-starrocks-fe-cm
resolveKey: fe.conf
image: starrocks/fe-ubuntu:3.2.2
imagePullPolicy: IfNotPresent
replicas: 1
requests:
cpu: 1m
memory: 22Mi
storageVolumes:
- mountPath: /opt/starrocks-artifacts
name: fe-artifacts
storageClassName: emptyDir
storageSize: 20Gi
- mountPath: /opt/starrocks-meta
name: fe-meta
storageSize: 10Gi
- mountPath: /opt/starrocks-log
name: fe-log
storageSize: 10Gi
starRocksBeSpec:
command: [ "bash", "-c" ]
args:
- cp -r /opt/starrocks/* /opt/starrocks-artifacts && export STARROCKS_ROOT=/opt/starrocks-artifacts && exec /opt/starrocks-artifacts/be_entrypoint.sh $FE_SERVICE_NAME
readOnlyRootFilesystem: true
configMapInfo:
configMapName: kube-starrocks-be-cm
resolveKey: be.conf
image: starrocks/be-ubuntu:3.2.2
imagePullPolicy: IfNotPresent
replicas: 1
requests:
cpu: 1m
memory: 10Mi
storageVolumes:
- mountPath: /opt/starrocks-artifacts
name: be-artifacts
storageClassName: emptyDir
storageSize: 20Gi
- mountPath: /opt/starrocks-storage
name: be-storage # the name must be this
storageSize: 10Gi
- mountPath: /opt/starrocks-log
name: be-log # the name must be this
storageSize: 10Gi

---

apiVersion: v1
data:
fe.conf: |
LOG_DIR = ${STARROCKS_HOME}/log
DATE = "$(date +%Y%m%d-%H%M%S)"
JAVA_OPTS="-Dlog4j2.formatMsgNoLookups=true -Xmx8192m -XX:+UseG1GC -Xlog:gc*:${LOG_DIR}/fe.gc.log.$DATE:time"
http_port = 8030
rpc_port = 9020
query_port = 9030
edit_log_port = 9010
mysql_service_nio_enabled = true
sys_log_level = INFO
# config for meta and log
meta_dir = /opt/starrocks-meta
dump_log_dir = /opt/starrocks-log
sys_log_dir = /opt/starrocks-log
audit_log_dir = /opt/starrocks-log
kind: ConfigMap
metadata:
name: kube-starrocks-fe-cm
namespace: starrocks

---

apiVersion: v1
data:
be.conf: |
be_port = 9060
webserver_port = 8040
heartbeat_service_port = 9050
brpc_port = 8060
sys_log_level = INFO
default_rowset_type = beta
# config for storage and log
storage_root_path = /opt/starrocks-storage
sys_log_dir = /opt/starrocks-log
kind: ConfigMap
metadata:
name: kube-starrocks-be-cm
namespace: starrocks
```
## By using Helm Chart
If you are using the `kube-starrocks` Helm chart, add the following snippets to `values.yaml`.

> Note: you should use the chart version `v1.9.9` or later.

```yaml
operator:
starrocksOperator:
image:
repository: operator
tag: v1.9.9-rc1
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 1m
memory: 20Mi
starrocks:
initPassword:
enabled: false
password: "123456"
starrocksBeSpec:
readOnlyRootFilesystem: true
entrypoint:
script: |
#! /bin/bash
echo "do something before start BE"
cp -r /opt/starrocks/* /opt/starrocks-artifacts
export STARROCKS_ROOT=/opt/starrocks-artifacts
exec /opt/starrocks-artifacts/be_entrypoint.sh $FE_SERVICE_NAME
image:
repository: starrocks/be-ubuntu
tag: 3.2.2
replicas: 1
resources:
limits:
cpu: 8
memory: 8Gi
requests:
cpu: 1m
memory: 10Mi
storageSpec:
name: be
storageSize: 10Gi
storageMountPath: /opt/starrocks-storage
logStorageSize: 10Gi
logMountPath: /opt/starrocks-log
spillStorageSize: 10Gi
spillMountPath: /opt/starrocks-spill
emptyDirs:
- name: be-artifacts
mountPath: /opt/starrocks-artifacts
config: |
be_port = 9060
webserver_port = 8040
heartbeat_service_port = 9050
brpc_port = 8060
sys_log_level = INFO
default_rowset_type = beta
# config for storage and log
storage_root_path = /opt/starrocks-storage
sys_log_dir = /opt/starrocks-log
spill_local_storage_dir = /opt/starrocks-spill
starrocksFESpec:
readOnlyRootFilesystem: true
entrypoint:
script: |
#! /bin/bash
cp -r /opt/starrocks/* /opt/starrocks-artifacts
export STARROCKS_ROOT=/opt/starrocks-artifacts
exec /opt/starrocks/fe_entrypoint.sh $FE_SERVICE_NAME
image:
repository: starrocks/fe-ubuntu
tag: 3.2.2
resources:
limits:
cpu: 2
memory: 4Gi
requests:
cpu: 1m
memory: 20Mi
storageSpec:
name: fe
storageSize: 10Gi
storageMountPath: /opt/starrocks-meta
logStorageSize: 10Gi
logMountPath: /opt/starrocks-log
emptyDirs:
- name: fe-artifacts
mountPath: /opt/starrocks-artifacts
config: |
LOG_DIR = ${STARROCKS_HOME}/log
DATE = "$(date +%Y%m%d-%H%M%S)"
JAVA_OPTS="-Dlog4j2.formatMsgNoLookups=true -Xmx8192m -XX:+UseG1GC -Xlog:gc*:${LOG_DIR}/fe.gc.log.$DATE:time"
http_port = 8030
rpc_port = 9020
query_port = 9030
edit_log_port = 9010
mysql_service_nio_enabled = true
sys_log_level = INFO
# config for meta and log
meta_dir = /opt/starrocks-meta
dump_log_dir = /opt/starrocks-log
sys_log_dir = /opt/starrocks-log
audit_log_dir = /opt/starrocks-log
```
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ be.conf: |
{{- end }}

{{- define "starrockscluster.fe.log.path" -}}
{{- if .Values.starrocksFESpec.storageSpec.logMountPath }}
{{- print .Values.starrocksFESpec.storageSpec.logMountPath }}
{{- else }}
{{- print "/opt/starrocks/fe/log" }}
{{- end }}
{{- end }}

{{- define "starrockscluster.be.data.suffix" -}}
{{- print "-data" }}
Expand All @@ -126,16 +130,24 @@ be.conf: |
{{- end }}

{{- define "starrockscluster.be.log.path" -}}
{{- if .Values.starrocksBeSpec.storageSpec.logMountPath }}
{{- print .Values.starrocksBeSpec.storageSpec.logMountPath }}
{{- else }}
{{- print "/opt/starrocks/be/log" }}
{{- end }}
{{- end }}

{{- define "starrockscluster.be.spill.suffix" -}}
{{- print "-spill" }}
{{- end }}

{{- define "starrockscluster.be.spill.path" -}}
{{- if .Values.starrocksBeSpec.storageSpec.spillMountPath }}
{{- print .Values.starrocksBeSpec.storageSpec.spillMountPath }}
{{- else }}
{{- print "/opt/starrocks/be/spill" }}
{{- end }}
{{- end }}

{{- define "starrockscluster.cn.data.suffix" -}}
{{- print "-data" }}
Expand All @@ -154,16 +166,24 @@ be.conf: |
{{- end }}

{{- define "starrockscluster.cn.log.path" -}}
{{- if .Values.starrocksCnSpec.storageSpec.logMountPath }}
{{- print .Values.starrocksCnSpec.storageSpec.logMountPath }}
{{- else }}
{{- print "/opt/starrocks/cn/log" }}
{{- end }}
{{- end }}

{{- define "starrockscluster.cn.spill.suffix" -}}
{{- print "-spill" }}
{{- end }}

{{- define "starrockscluster.cn.spill.path" -}}
{{- if .Values.starrocksCnSpec.storageSpec.spillMountPath }}
{{- print .Values.starrocksCnSpec.storageSpec.spillMountPath }}
{{- else }}
{{- print "/opt/starrocks/cn/spill" }}
{{- end }}
{{- end }}

{{- define "starrockscluster.entrypoint.script.name" -}}
{{- print "entrypoint.sh" }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ spec:
runAsNonRoot: {{ include "starrockscluster.fe.runAsNonRoot" . }}
{{- if .Values.starrocksFESpec.readOnlyRootFilesystem }}
readOnlyRootFilesystem: {{ .Values.starrocksFESpec.readOnlyRootFilesystem }}
{{-end }}
{{- end }}
{{- if or .Values.starrocksFESpec.nodeSelector .Values.starrocksCluster.componentValues.nodeSelector }}
nodeSelector:
{{- include "starrockscluster.fe.nodeSelector" . | nindent 6 }}
Expand Down Expand Up @@ -324,7 +324,7 @@ spec:
runAsNonRoot: {{ include "starrockscluster.be.runAsNonRoot" . }}
{{- if .Values.starrocksBeSpec.readOnlyRootFilesystem }}
readOnlyRootFilesystem: {{ .Values.starrocksBeSpec.readOnlyRootFilesystem }}
{{-end }}
{{- end }}
{{- if or .Values.starrocksBeSpec.capabilities .Values.datadog.profiling.be }}
capabilities:
{{- if or .Values.starrocksBeSpec.capabilities.add .Values.datadog.profiling.be }}
Expand Down Expand Up @@ -539,7 +539,7 @@ spec:
runAsNonRoot: {{ include "starrockscluster.cn.runAsNonRoot" . }}
{{- if .Values.starrocksCnSpec.readOnlyRootFilesystem }}
readOnlyRootFilesystem: {{ .Values.starrocksCnSpec.readOnlyRootFilesystem }}
{{-end }}
{{- end }}
{{- if or .Values.starrocksCnSpec.capabilities .Values.datadog.profiling.cn }}
capabilities:
{{- if or .Values.starrocksCnSpec.capabilities.add .Values.datadog.profiling.cn }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ starrocksFESpec:
storageSize: 10Gi
# If storageMountPath is empty, the storageMountPath will be set to /opt/starrocks/fe/meta.
storageMountPath: ""
logMountPath: ""
# Setting this parameter can persist log storage, and the mount path is /opt/starrocks/fe/log.
# If you set it to 0Gi, the related PVC will not be created, and the log will not be persisted.
logStorageSize: 5Gi
Expand Down Expand Up @@ -587,6 +588,8 @@ starrocksCnSpec:
storageCount: 1
# see the comment of storageCount for the usage of storageMountPath.
storageMountPath: ""
logMountPath: ""
spillMountPath: ""
# the storage size of persistent volume for log, and the mount path is /opt/starrocks/cn/log.
# If you set it to 0Gi, the related PVC will not be created, and the log will not be persisted.
logStorageSize: 20Gi
Expand Down Expand Up @@ -865,6 +868,8 @@ starrocksBeSpec:
storageCount: 1
# see the comment of storageCount for the usage of storageMountPath.
storageMountPath: ""
logMountPath: ""
spillMountPath: ""
# Setting this parameter can persist log storage, and the mount path is /opt/starrocks/be/log.
# If you set it to 0Gi, the related PVC will not be created, and the log will not be persisted.
logStorageSize: 20Gi
Expand Down
Loading

0 comments on commit 39d3274

Please sign in to comment.