Skip to content

Commit ea146ea

Browse files
committed
feat: Add base and ipfix overlays for separation
Keep the base overlay simple with one node and let the ipfix overlay do the heavy lifting with regard to multiple shards, replicas, and other ideal production related items.
1 parent 8ba2d9b commit ea146ea

File tree

10 files changed

+230
-16
lines changed

10 files changed

+230
-16
lines changed

base-kustomize/clickhouse/base/chi-cluster.yaml renamed to base-kustomize/clickhouse/base/chi-server-base.yaml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ spec:
77
taskID: "1"
88

99
configuration:
10-
# Use Keeper for replication
11-
zookeeper:
12-
nodes:
13-
- host: keeper-keeper
14-
port: 2181
10+
# No Keeper here for base config (single node / non-replicated)
1511

1612
users:
1713
# Disable dangerous defaults; create reader/writer explicitly.
@@ -56,10 +52,10 @@ spec:
5652
requiredDuringSchedulingIgnoredDuringExecution:
5753
nodeSelectorTerms:
5854
- matchExpressions:
59-
- key: node-role.kubernetes.io/worker
60-
operator: In
61-
values:
62-
- worker
55+
- key: node-role.kubernetes.io/worker
56+
operator: In
57+
values:
58+
- worker
6359
podAntiAffinity:
6460
requiredDuringSchedulingIgnoredDuringExecution:
6561
- labelSelector:

base-kustomize/clickhouse/base/kustomization.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
sortOptions:
33
order: fifo
44
resources:
5-
- chk-keeper.yaml
6-
- chi-cluster.yaml
5+
- chi-server-base.yaml
76
- svc-clickhouse-http.yaml
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: policy/v1
2+
kind: PodDisruptionBudget
3+
metadata:
4+
name: ch-pdb-s01
5+
namespace: clickhouse
6+
spec:
7+
minAvailable: 1
8+
selector:
9+
matchLabels:
10+
clickhouse.altinity.com/chi: server
11+
clickhouse.altinity.com/cluster: ipfix
12+
clickhouse.altinity.com/shard: s01
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: policy/v1
2+
kind: PodDisruptionBudget
3+
metadata:
4+
name: ch-pdb-s02
5+
namespace: clickhouse
6+
spec:
7+
minAvailable: 1
8+
selector:
9+
matchLabels:
10+
clickhouse.altinity.com/chi: server
11+
clickhouse.altinity.com/cluster: ipfix
12+
clickhouse.altinity.com/shard: s02
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: policy/v1
2+
kind: PodDisruptionBudget
3+
metadata:
4+
name: ch-pdb-s03
5+
namespace: clickhouse
6+
spec:
7+
minAvailable: 1
8+
selector:
9+
matchLabels:
10+
clickhouse.altinity.com/chi: server
11+
clickhouse.altinity.com/cluster: ipfix
12+
clickhouse.altinity.com/shard: s03
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
apiVersion: clickhouse.altinity.com/v1
2+
kind: ClickHouseInstallation
3+
metadata:
4+
name: server
5+
namespace: clickhouse
6+
spec:
7+
configuration:
8+
# Keeper for replication in this overlay
9+
zookeeper:
10+
nodes:
11+
- host: keeper-keeper
12+
port: 2181
13+
14+
# Override cluster layout to 3 shards × 2 replicas
15+
clusters:
16+
- name: ipfix
17+
layout:
18+
shardsCount: 3
19+
replicasCount: 2
20+
templates:
21+
podTemplate: ch-pod
22+
volumeClaimTemplate: ch-data
23+
24+
# Cluster-wide init SQL (replicated engines + distributed + hourly MV)
25+
files:
26+
10-init-ipfix.sql: |
27+
CREATE DATABASE IF NOT EXISTS ipfix ON CLUSTER '{cluster}';
28+
29+
----------------------------------------------------------------------
30+
-- Replicated VIP hourly schema
31+
----------------------------------------------------------------------
32+
CREATE TABLE IF NOT EXISTS ipfix.vip_hourly_node ON CLUSTER '{cluster}'
33+
(
34+
hour_ts DateTime,
35+
vip LowCardinality(String),
36+
dir LowCardinality(String), -- 'to' | 'from'
37+
bytes UInt64,
38+
packets UInt64,
39+
node LowCardinality(String)
40+
)
41+
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/vip_hourly_node','{replica}')
42+
PARTITION BY toYYYYMMDD(hour_ts)
43+
ORDER BY (hour_ts, vip, dir, node);
44+
45+
CREATE TABLE IF NOT EXISTS ipfix.vip_hourly_mv ON CLUSTER '{cluster}'
46+
(
47+
hour_ts DateTime,
48+
vip LowCardinality(String),
49+
dir LowCardinality(String),
50+
bytes UInt64,
51+
packets UInt64
52+
)
53+
ENGINE = ReplicatedSummingMergeTree('/clickhouse/tables/{shard}/vip_hourly_mv','{replica}')
54+
PARTITION BY toYYYYMMDD(hour_ts)
55+
ORDER BY (hour_ts, vip, dir);
56+
57+
CREATE MATERIALIZED VIEW IF NOT EXISTS ipfix.vip_hourly_mv__mv ON CLUSTER '{cluster}'
58+
TO ipfix.vip_hourly_mv
59+
AS
60+
SELECT
61+
hour_ts,
62+
vip,
63+
dir,
64+
sum(bytes) AS bytes,
65+
sum(packets) AS packets
66+
FROM ipfix.vip_hourly_node
67+
GROUP BY hour_ts, vip, dir;
68+
69+
----------------------------------------------------------------------
70+
-- Replicated flows + distributed table (replica-aware)
71+
----------------------------------------------------------------------
72+
CREATE TABLE IF NOT EXISTS ipfix.flows_local ON CLUSTER '{cluster}'
73+
(
74+
flow_start DateTime64(3),
75+
flow_end DateTime64(3),
76+
fip IPv6,
77+
src_ip IPv6,
78+
dst_ip IPv6,
79+
src_port UInt16,
80+
dst_port UInt16,
81+
proto UInt8,
82+
bytes UInt64,
83+
packets UInt64,
84+
exporter_id LowCardinality(String)
85+
)
86+
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/flows_local','{replica}')
87+
PARTITION BY toDate(flow_start)
88+
ORDER BY (fip, flow_start, src_ip, dst_ip, src_port, dst_port, proto)
89+
SETTINGS index_granularity = 8192;
90+
91+
CREATE TABLE IF NOT EXISTS ipfix.flows_dist ON CLUSTER '{cluster}'
92+
AS ipfix.flows_local
93+
ENGINE = Distributed('{cluster}', 'ipfix', 'flows_local', cityHash64(fip))
94+
SETTINGS internal_replication = 1;
95+
96+
-- Hourly rollup by FIP
97+
CREATE TABLE IF NOT EXISTS ipfix.flows_by_fip_1h ON CLUSTER '{cluster}'
98+
(
99+
ts DateTime,
100+
fip IPv6,
101+
bytes UInt64,
102+
packets UInt64
103+
)
104+
ENGINE = SummingMergeTree
105+
PARTITION BY toDate(ts)
106+
ORDER BY (fip, ts);
107+
108+
CREATE MATERIALIZED VIEW IF NOT EXISTS ipfix.mv_flows_by_fip_1h ON CLUSTER '{cluster}'
109+
TO ipfix.flows_by_fip_1h
110+
AS
111+
SELECT
112+
toStartOfHour(flow_start) AS ts,
113+
fip,
114+
sum(bytes) AS bytes,
115+
sum(packets) AS packets
116+
FROM ipfix.flows_local
117+
GROUP BY ts, fip;
118+
119+
templates:
120+
podTemplates:
121+
- name: ch-pod
122+
spec:
123+
nodeAffinity:
124+
requiredDuringSchedulingIgnoredDuringExecution:
125+
nodeSelectorTerms:
126+
- matchExpressions:
127+
- key: node-role.kubernetes.io/worker
128+
operator: In
129+
values:
130+
- worker
131+
132+
# Prefer spreading across nodes cluster-wide
133+
affinity:
134+
podAntiAffinity:
135+
preferredDuringSchedulingIgnoredDuringExecution:
136+
- weight: 100
137+
podAffinityTerm:
138+
labelSelector:
139+
matchLabels:
140+
clickhouse.altinity.com/chi: server
141+
topologyKey: kubernetes.io/hostname
142+
143+
containers:
144+
- name: clickhouse
145+
image: ${CLICKHOUSE_SERVER_IMAGE}
146+
imagePullPolicy: IfNotPresent
147+
ports:
148+
- name: http
149+
containerPort: 8123
150+
- name: native
151+
containerPort: 9000
152+
- name: inter
153+
containerPort: 9009
154+
155+
volumeClaimTemplates:
156+
- name: ch-data
157+
spec:
158+
accessModes: ["ReadWriteOnce"]
159+
storageClassName: general
160+
resources:
161+
requests:
162+
storage: 10Gi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: policy/v1
2+
kind: PodDisruptionBudget
3+
metadata:
4+
name: keeper-pdb
5+
namespace: clickhouse
6+
spec:
7+
minAvailable: 2
8+
selector:
9+
matchLabels:
10+
clickhouse-keeper.altinity.com/chi: keeper
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
namespace: clickhouse
5+
6+
resources:
7+
- ../base
8+
- chk-keeper.yaml
9+
- keeper-pdb.yaml
10+
- ch-pdb-s01.yaml
11+
- ch-pdb-s02.yaml
12+
- ch-pdb-s03.yaml
13+
14+
patchesStrategicMerge:
15+
- chi-server-ipfix.yaml

bin/install-clickhouse.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ GLOBAL_OVERRIDES_DIR="${GENESTACK_OVERRIDES_DIR}/helm-configs/global_overrides"
2626

2727
# Read the desired chart version from VERSION_FILE
2828
VERSION_FILE="${GENESTACK_OVERRIDES_DIR}/helm-chart-versions.yaml"
29-
KUSTOMIZE_DIR="/etc/genestack/kustomize/clickhouse/overlay"
29+
KUSTOMIZE_DIR="${GENESTACK_OVERRIDES_DIR}/kustomize/clickhouse/overlay"
3030
OP_RELEASE="altinity-operator"
3131

3232
need() { command -v "$1" >/dev/null || { echo "Missing required command: $1" >&2; exit 1; }; }
@@ -169,10 +169,6 @@ echo "==> Applying ClickHouse Keeper + Cluster (kustomize + envsubst)"
169169
# We envsubst only image placeholders present in manifests.
170170
kubectl kustomize "${KUSTOMIZE_DIR}" | envsubst '${CLICKHOUSE_SERVER_IMAGE} ${CLICKHOUSE_KEEPER_IMAGE}' | kubectl apply -n "${SERVICE_NAMESPACE}" -f -
171171

172-
echo "==> Waiting for ClickHouse cluster pods (CHI=ch) to be Ready"
173-
sleep 5 # wait a few seconds for stateful set to be created
174-
kubectl wait -n clickhouse --for=jsonpath='{.status.readyReplicas}'=1 statefulset/chi-ch-main-0-0 --timeout=10m
175-
176172
echo "==> Service endpoint (HTTP 8123)"
177173
kubectl -n "${SERVICE_NAMESPACE}" get svc clickhouse-http -o wide
178174

0 commit comments

Comments
 (0)