๋ฐ์ดํ„ฐ ์—”์ง€๋‹ˆ์–ด๋ง

๋ฐ์ดํ„ฐ ๋ถ„์„ ํ™˜๊ฒฝ ๊ตฌ์ถ• - 02. ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์— Clickhouse ์„ค์น˜ ๋ฐ ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑ

Tempo 2025. 3. 22. 09:00

์ด๋ฒˆ ๊ธ€์—์„œ๋Š” Kubernetes ํ™˜๊ฒฝ์—์„œ ClickHouse๋ฅผ ๋ฐฐํฌ ๋ฐ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.
Docker Desktop์˜ ๋‚ด์žฅ Kubernetes๋ฅผ ํ™œ์šฉํ•˜๊ณ , Helm ๋ฐ Bitnami Helm ์ฐจํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ„ํŽธํ•˜๊ฒŒ ClickHouse๋ฅผ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.

1. ์‚ฌ์ „ ์ค€๋น„

1) kubectl ์„ค์น˜ (Kubernetes CLI)

kubectl์€ Kubernetes ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋ช…๋ น์ค„ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.

๐Ÿ”น macOS

brew install kubectl

๐Ÿ”น Windows (PowerShell)

choco install kubernetes-cli

โœ… ์„ค์น˜ ํ™•์ธ:

kubectl version --client

2) Docker Desktop์—์„œ Kubernetes ํ™œ์„ฑํ™”

Docker Desktop์—๋Š” Kubernetes๊ฐ€ ๊ธฐ๋ณธ์ ์œผ๋กœ ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฉฐ, ๊ฐ„๋‹จํ•œ ์„ค์ •์œผ๋กœ ํ™œ์„ฑํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ”น Kubernetes ํ™œ์„ฑํ™” ๋ฐฉ๋ฒ•

  1. Docker Desktop ์‹คํ–‰
  2. Settings(์„ค์ •) → Kubernetes ํƒญ ์ด๋™

3. "Enable Kubernetes" ์˜ต์…˜ ์ฒดํฌ ํ›„ "Apply & Restart" ํด๋ฆญ

๊ฝค ์˜ค๋žœ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฝ๋‹ˆ๋‹ค.

kubectl ๋ช…๋ น์–ด๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๋Š”์ง€ ํ™•์ธ

kubectl version --client
kubectl get nodes  # Kubernetes ๋…ธ๋“œ ์ƒํƒœ ํ™•์ธ

3) Helm ์„ค์น˜ (ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €)

Helm์€ Kubernetes์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‰ฝ๊ฒŒ ๋ฐฐํฌํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.
๋กœ์ปฌ์— Helm์„ ์„ค์น˜ํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ”น Helm ์„ค์น˜ (Mac)

brew install helm

๐Ÿ”น Helm ์„ค์น˜ (Windows)

choco install kubernetes-helm

๐Ÿ”น ์„ค์น˜ ํ™•์ธ

helm version

2. Bitnami Helm Chart๋ฅผ ์ด์šฉํ•œ ClickHouse ์„ค์น˜

์ด์ œ Bitnami์˜ ๊ณต์‹ Helm ์ฐจํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ClickHouse๋ฅผ Kubernetes์— ๋ฐฐํฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. Bitnami Helm Repository ์ถ”๊ฐ€ ํ›„ ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์ง€๋งŒ, values.yaml ํŒŒ์ผ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ•ฉ๋‹ˆ๋‹ค.

1) ClickHouse value.yaml ํŒŒ์ผ ์ƒ์„ฑ

๋จผ์ € values.yaml ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

mkdir clickhouse-local && cd clickhouse-local
touch values.yaml

์ƒ์„ฑ๋œ ํด๋” ๊ตฌ์กฐ

โ””โ”€โ”€ clickhouse-local
    โ””โ”€โ”€ values.yaml

๊ทธ๋ฆฌ๊ณ  artifacthub ๋‚ด bitnami/clickhouse ์ €์žฅ์†Œ์— ์ ‘์†ํ•˜์—ฌ values.yaml ์›๋ณธ์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

artifacthub ๋‚ด bitnami clickhouse ์ €์žฅ์†Œ
values.yaml

ํ•ด๋‹น ์›๋ณธ์„ ์ด์ „์— ์ƒ์„ฑํ•œ values.yaml ํŒŒ์ผ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

2) ClickHouse ์„ค์ • ๋ณ€๊ฒฝ

ํ•ด๋‹น values.yaml ํŒŒ์ผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฐฐํฌํ•˜๊ธฐ ์œ„ํ•ด ๋ช‡๊ฐ€์ง€ ์„ค์ •์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

1. Authentication ์„ค์ •

  • values.yaml์—์„œ auth: ๋ฅผ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค. username๊ณผ password๋ฅผ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

2. Resource ์„ค์ •

  • values.yaml์—์„œ๋Š” clickhouse, zookeeper์— ๋Œ€ํ•œ ๋ฆฌ์†Œ์Šค๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์šฐ์„  clickhouse์˜ ๋ฆฌ์†Œ์Šค๋งŒ ๋ณ€๊ฒฝํ•˜์—ฌ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.
  • resourcePreset ์„ค์ •์„ ๋ณ€๊ฒฝํ•˜์—ฌ ์ด๋ฏธ ์ง€์ •๋œ ๋ฆฌ์†Œ์Šค๋กœ ๋ฐฐํฌํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋ฆฌ์†Œ์Šค preset ์„ค์ •๋ณ„ cpu, memory ์‚ฌ์šฉ๋Ÿ‰์€ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
  • DB IDE(DBeaver, HeidiSQL ๋“ฑ)์™€ ์—ฐ๊ฒฐ์„ ์œ„ํ•ด request(cpu: 2, memory: 1Gi) / limit(cpu:3, memory 2Gi)๋กœ ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
    • ์ด๋ณด๋‹ค ์ž‘์„ ๊ฒฝ์šฐ DBeaver์—์„œ ์—ฐ๊ฒฐ ์‹œ MEMORY_LIMIT_EXCEED ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

3. replica, shard ์„ค์ •

  • values.yaml์—์„œ shards: ๋ฅผ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒˆ ์‹ค์Šต์—์„œ๋Š” shards 2, replicaCount 2๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
  • zookeeper์˜ replicaCount๋ฅผ 2๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. 

3) ClickHouse ๋ฐฐํฌ

์ด์ œ ClickHouse๋ฅผ Kubernetes ํด๋Ÿฌ์Šคํ„ฐ์— ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค. clickhouse-local ๋””๋ ‰ํ† ๋ฆฌ์—์„œ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • ๊ฐ ๋„ค์ž„์ŠคํŽ˜์ด์Šค ๋ณ„ ๋ฆฌ์†Œ์Šค ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•ด ๋ณ„๋„์˜ ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ์ƒ์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.(clickhouse)
helm install clickhouse oci://registry-1.docker.io/bitnamicharts/clickhouse -f ./values.yaml --create-namespace --namespace clickhouse

์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด, ๋ฐฐํฌ๋œ ๋ฆฌ์†Œ์Šค๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

kubectl get pods -n clickhouse

์ถœ๋ ฅ ์˜ˆ์‹œ:

NAME                     READY   STATUS    RESTARTS   AGE
clickhouse-shard0-0      1/1     Running   0          53s
clickhouse-shard0-1      1/1     Running   0          78s
clickhouse-shard1-0      1/1     Running   0          53s
clickhouse-shard1-1      1/1     Running   0          78s
clickhouse-zookeeper-0   1/1     Running   0          71s
clickhouse-zookeeper-1   1/1     Running   0          87s

3. ClickHouse ์ ‘์† ๋ฐ ํ…Œ์ŠคํŠธ

1) Pod ๋‚ด๋ถ€์—์„œ ClickHouse ์ ‘์†

ClickHouse Pod์— ์ง์ ‘ ์ ‘์†ํ•˜์—ฌ ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

kubectl exec -it pod/clickhouse-shard0-0 -n clickhouse -- clickhouse-client --user <username> --password <password>

 

์ƒ˜ํ”Œ ๋ฐ์ดํ„ฐ ์‚ฝ์ž… ๋ฐ ์กฐํšŒ

CREATE TABLE default.test_table (
    id UInt32,
    name String
) ENGINE = MergeTree()
ORDER BY id;

INSERT INTO default.test_table VALUES (1, 'Alice'), (2, 'Bob');

SELECT * FROM default.test_table;

 

ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑ ์กฐํšŒ

select * from system.clusters

 

2) ์™ธ๋ถ€์—์„œ ClickHouse ์ ‘์† (Port Forwarding)

๋กœ์ปฌ ํ™˜๊ฒฝ์—์„œ ClickHouse์— ์ ‘๊ทผํ•˜๋ ค๋ฉด ํฌํŠธ ํฌ์›Œ๋”ฉ์„ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

kubectl port-forward svc/clickhouse 8123:8123 -n clickhouse

์ด์ œ ์›น ๋ธŒ๋ผ์šฐ์ € ๋˜๋Š” curl ๋ช…๋ น์–ด๋กœ ClickHouse์˜ REST API์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

curl "http://localhost:8123/?query=SELECT%201"

์ถœ๋ ฅ:

1

4. ClickHouse ์—…๋ฐ์ดํŠธ

values.yaml ํŒŒ์ผ ๋‚ด ์„ค์ • ๋ณ€๊ฒฝ ํ›„ ์—…๋ฐ์ดํŠธ ์‹œ ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

helm upgrade clickhouse oci://registry-1.docker.io/bitnamicharts/clickhouse -f ./clickhouse-local/values.yaml -n clickhouse

 

5. ClickHouse ์ œ๊ฑฐ ๋ฐฉ๋ฒ• (Cleanup)

ํ…Œ์ŠคํŠธ๊ฐ€ ๋๋‚œ ํ›„ Helm์„ ์‚ฌ์šฉํ•˜์—ฌ ClickHouse๋ฅผ ์‚ญ์ œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

helm uninstall my-clickhouse

์‚ญ์ œ๋œ ๋ฆฌ์†Œ์Šค ํ™•์ธ:

kubectl get all
๋ฐ˜์‘ํ˜•