部署总体参考:https://blog.csdn.net/tototuzuoquan/article/details/111305125
clickhouse的配置文件相关解读:https://www.cnblogs.com/zhoujinyi/archive/2004/01/13/12627780.html
流程简介:
1. 创建configmap
,data部分包含用于配置集群的remote_servers.xml
、用于连接zookeeper的zookeeper.xml
,这两个文件会被挂载在clickhouse的config.d
目录下,然后会覆盖config.xml
的相关内容; data部分还包含users.xml
,用于设置用户的账号密码和可使用的内存,会覆盖到clickhouse的user.xml
中。
2. 创建statefulset
,docker使用yandex/clickhouse-server:19.11.3.11
,通过replicas
来设置副本数,要和remote_servers.xml
相对应,同时设置持久化卷的挂载。
3. 创建service
,在selector.app
中设置第二部的statefulset
,将spec.type
设置为ClusterIP
只在集群内使用,clusterIP
设置为None
,通过DNS解析service
名来访问。
创建configmap
配置文件configd.yaml:
apiVersion: v1
kind: ConfigMap
metadata:
name: tt-test
namespace: te-sp-dev
labels:
app: tt-test
data:
remote_servers.xml: |-
<yandex>
<remote_servers incl="clickhouse_remote_servers">
<clicks_cluster>
<shard>
<internal_replication>true</internal_replication>
<replica>
<default_database>default</default_database>
<host>clickhouse-0.clickhouse</host>
<user>argus</user>
<password>root</password>
<port>9000</port>
</replica>
<replica>
<default_database>default</default_database>
<host>clickhouse-1.clickhouse</host>
<user>argus</user>
<password>root</password>
<port>9000</port>
</replica>
<replica>
<default_database>default</default_database>
<host>clickhouse-2.clickhouse</host>
<user>argus</user>
<password>root</password>
<port>9000</port>
</replica>
</shard>
</clicks_cluster>
</remote_servers>
<listen_host>0.0.0.0</listen_host>
<logger>
<level>error</level>
<log></log>
<errorlog></errorlog>
<console>1</console>
</logger>
<compression incl="clickhouse_compression">
<case>
<method>lz4</method>
</case>
</compression>
<distributed_ddl>
<path>/clickhouse/task_queue/ddl</path>
</distributed_ddl>
<macros replace="replace">
<shard>shard0</shard>
<replica>REPLICA_NAME</replica>
</macros>
</yandex>
zookeeper.xml: |-
<yandex>
<zookeeper incl="zookeeper-servers">
<node index="1">
<host>kafka-zk-zk-0.kafka-zk-hs.te-retail-senselink</host>
<port>2181</port>
</node>
<node index="2">
<host>kafka-zk-zk-1.kafka-zk-hs.te-retail-senselink</host>
<port>2181</port>
</node>
<node index="3">
<host>kafka-zk-zk-2.kafka-zk-hs.te-retail-senselink</host>
<port>2181</port>
</node>
</zookeeper>
</yandex>
users.xml: |-
<yandex>
<profiles>
<writer>
<max_memory_usage>1000000000</max_memory_usage>
<use_uncompressed_cache>0</use_uncompr