Skip to content

Commit b7a64c8

Browse files
committed
chore: improve ck memberjoin (#2431)
Co-authored-by: loomts <loomts@users.noreply.github.com>
1 parent 5e6d1e8 commit b7a64c8

File tree

11 files changed

+145
-114
lines changed

11 files changed

+145
-114
lines changed

addons-cluster/clickhouse-cluster/templates/cluster-tls-secrets.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
{{- if and .Values.tls.enabled (eq .Values.tls.issuer "UserProvided") }}
2+
{{- $clusterName := include "kblib.clusterName" . }}
3+
{{- $namespace := .Release.Namespace }}
4+
{{- $svcNames := list (printf "%s-clickhouse" $clusterName) (printf "%s-ch-keeper" $clusterName) }}
5+
{{- $clusterDomain := "cluster.local" }}
6+
{{- $dnsNames := list "localhost" }}
7+
{{- range $svc := $svcNames }}
8+
{{- $dnsNames = concat $dnsNames (list
9+
$svc
10+
(printf "%s.%s.svc" $svc $namespace)
11+
(printf "*.%s-headless.%s.svc.%s" $svc $namespace $clusterDomain)
12+
) }}
13+
{{- end }}
214
{{- $ca := genCA "KubeBlocks" 36500 }}
3-
{{- $cert := genSignedCert "clickhouse" (list "127.0.0.1" "::1") (list "localhost" "*.cluster.local") 36500 $ca }}
15+
{{- $cert := genSignedCert "clickhouse" (list "127.0.0.1" "::1") $dnsNames 36500 $ca }}
416
apiVersion: v1
517
kind: Secret
618
metadata:
@@ -12,4 +24,4 @@ stringData:
1224
ca.crt: {{ $ca.Cert | quote }}
1325
tls.crt: {{ $cert.Cert | quote }}
1426
tls.key: {{ $cert.Key | quote }}
15-
{{- end }}
27+
{{- end }}

addons/clickhouse/configs/00_default_overrides.xml.tpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
<server>
101101
<certificateFile>{{$CERT_FILE}}</certificateFile>
102102
<privateKeyFile>{{$KEY_FILE}}</privateKeyFile>
103+
<!--
104+
Use relaxed verification for ClickHouse to skip hostname check, while still supporting TLS encryption.
105+
-->
103106
<verificationMode>relaxed</verificationMode>
104107
<caConfig>{{$CA_FILE}}</caConfig>
105108
<cacheSessions>true</cacheSessions>
@@ -114,7 +117,7 @@
114117
<cacheSessions>true</cacheSessions>
115118
<disableProtocols>sslv2,sslv3</disableProtocols>
116119
<preferServerCiphers>true</preferServerCiphers>
117-
<verificationMode>relaxed</verificationMode>
120+
<verificationMode>strict</verificationMode>
118121
<invalidCertificateHandler>
119122
<name>RejectCertificateHandler</name>
120123
</invalidCertificateHandler>

addons/clickhouse/configs/ch-keeper_00_default_overrides.xml.tpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
<server>
8484
<certificateFile>{{$CERT_FILE}}</certificateFile>
8585
<privateKeyFile>{{$KEY_FILE}}</privateKeyFile>
86+
<!--
87+
Use relaxed verification for Keeper to skip hostname check, while still supporting TLS encryption.
88+
-->
8689
<verificationMode>relaxed</verificationMode>
8790
<caConfig>{{$CA_FILE}}</caConfig>
8891
<cacheSessions>true</cacheSessions>
@@ -97,7 +100,7 @@
97100
<cacheSessions>true</cacheSessions>
98101
<disableProtocols>sslv2,sslv3</disableProtocols>
99102
<preferServerCiphers>true</preferServerCiphers>
100-
<verificationMode>relaxed</verificationMode>
103+
<verificationMode>strict</verificationMode>
101104
<invalidCertificateHandler>
102105
<name>RejectCertificateHandler</name>
103106
</invalidCertificateHandler>

addons/clickhouse/configs/client.xml.tpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<config>
2-
<user>admin</user>
2+
<user from_env="CLICKHOUSE_ADMIN_USER"/>
33
<password from_env="CLICKHOUSE_ADMIN_PASSWORD"/>
44
{{- if $.component.tlsConfig -}}
55
{{- $CA_FILE := getCAFile -}}
66
<secure>true</secure>
7+
<port from_env="CLICKHOUSE_TCP_SECURE_PORT"/>
78
<openSSL>
89
<client>
910
<caConfig>{{$CA_FILE}}</caConfig>
11+
<certificateFile>{{$CERT_FILE}}</certificateFile>
12+
<privateKeyFile>{{$KEY_FILE}}</privateKeyFile>
1013
</client>
1114
</openSSL>
1215
{{- end }}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
HOST="127.0.0.1"
5-
SCHEME="http"
64
PORT="${CLICKHOUSE_HTTP_PORT:-8123}"
7-
8-
wget_args=(
9-
-O /dev/null
10-
-q
11-
-T 3
12-
--tries=1
5+
CURL_ARGS=(
6+
-sf
7+
--max-time 3
8+
"http://127.0.0.1:${PORT}/ping"
139
)
1410

1511
if [[ "${TLS_ENABLED:-false}" == "true" ]]; then
16-
SCHEME="https"
1712
PORT="${CLICKHOUSE_HTTPS_PORT:-8443}"
18-
wget_args+=(--no-check-certificate)
13+
CURL_ARGS=(
14+
-sf
15+
--max-time 3
16+
--cacert /etc/pki/tls/ca.pem
17+
--cert /etc/pki/tls/cert.pem
18+
--key /etc/pki/tls/key.pem
19+
"https://127.0.0.1:${PORT}/ping"
20+
)
1921
fi
2022

21-
endpoint="${SCHEME}://${HOST}:${PORT}/ping"
22-
23-
if ! /shared-tools/wget "${wget_args[@]}" "${endpoint}"; then
24-
echo "Readiness probe failed accessing ${endpoint}" >&2
23+
if ! /shared-tools/curl "${CURL_ARGS[@]}" >/dev/null; then
24+
echo "Readiness probe failed" >&2
2525
exit 1
2626
fi

addons/clickhouse/scripts/common.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ function keeper_run() {
4343
--query "$query"
4444
)
4545
if [[ "${TLS_ENABLED:-false}" == "true" ]]; then
46-
keeper_args+=(--secure --tls-ca-file "$CLICKHOUSE_TLS_CA" --tls-cert-file "$CLICKHOUSE_TLS_CERT" --tls-key-file "$CLICKHOUSE_TLS_KEY")
46+
keeper_args+=(--tls-ca-file "$CLICKHOUSE_TLS_CA" --tls-cert-file "$CLICKHOUSE_TLS_CERT" --tls-key-file "$CLICKHOUSE_TLS_KEY")
4747
fi
4848
if output=$(clickhouse-keeper-client "${keeper_args[@]}" 2>&1); then
49-
5049
if [[ "$output" != *"Coordination error"* ]] &&
5150
[[ "$output" != *"Connection refused"* ]] &&
5251
[[ "$output" != *"Timeout"* ]]; then
@@ -130,15 +129,29 @@ function get_mode_by_keeper() {
130129
echo "$mode" | awk '{print $2}'
131130
}
132131

133-
# Find leader node from member addresses
132+
# Get mode with retry to tolerate some network failures
133+
function get_mode_with_retry() {
134+
local host="$1"
135+
for _ in {1..5}; do
136+
local mode
137+
if mode=$(get_mode "$host") && [[ -n "$mode" ]]; then
138+
echo "$mode"
139+
return 0
140+
fi
141+
sleep 6
142+
done
143+
return 1
144+
}
145+
146+
# Find leader node from member addresses with retry mechanism
134147
function find_leader() {
135148
local member_addresses="$1"
136149
[[ -z "$member_addresses" ]] && return 1
137150

138151
while IFS=',' read -ra members; do
139152
for member_addr in "${members[@]}"; do
140153
local member_fqdn="${member_addr%:*}"
141-
mode=$(get_mode "$member_fqdn")
154+
local mode=$(get_mode_with_retry "$member_fqdn")
142155
if [[ "$mode" == "leader" || "$mode" == "standalone" ]]; then
143156
echo "$member_fqdn"
144157
return 0

addons/clickhouse/scripts/keeper-member-join.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,11 @@ if [[ "${TLS_ENABLED:-false}" == "true" ]]; then
88
keeper_raft_port=${CLICKHOUSE_KEEPER_RAFT_TLS_PORT:-9444}
99
fi
1010

11-
function check_is_leader() {
12-
local mode=$(get_mode 127.0.0.1)
13-
if [[ "$mode" == "leader" ]]; then
14-
echo "INFO: This member is the leader, no need to join."
15-
return 0
16-
fi
17-
}
18-
1911
# 1. Find leader from existing members
2012
leader_fqdn=$(find_leader "$KB_MEMBER_ADDRESSES")
2113
if [[ -z "$leader_fqdn" ]]; then
22-
if ! check_is_leader; then
23-
echo "ERROR: Could not find cluster leader."
24-
exit 1
25-
fi
14+
echo "ERROR: Could not find keeper leader"
15+
exit 1
2616
fi
2717

2818
# 2. Extract ordinal from pod name and calculate server ID

addons/clickhouse/templates/cmpd-ch.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ spec:
2424
- sh
2525
- -c
2626
- |
27-
cp /bin/wget /shared-tools/wget
28-
chmod +x /shared-tools/wget
27+
cp /bin/curl /shared-tools/curl
28+
chmod +x /shared-tools/curl
2929
volumeMounts:
3030
- name: shared-tools
3131
mountPath: /shared-tools

addons/clickhouse/values.yaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,24 @@ clickhouseVersions:
3333
- version: 22.3.18
3434
imageTag: 22.3.18-debian-11-r3
3535

36-
busyboxImage:
37-
# if the value of busyboxImage.registry is not specified using `--set`, it will be set to the value of 'image.registry' by default
38-
registry: ""
39-
repository: apecloud/busybox
40-
pullPolicy: IfNotPresent
41-
# Overrides the image tag whose default is the chart appVersion.
42-
tag: 1.37.0-musl
43-
4436
roleProbe:
4537
initialDelaySeconds: 15
4638
failureThreshold: 3
4739
periodSeconds: 3
4840
timeoutSeconds: 3
4941

42+
busyboxImage:
43+
registry: ""
44+
repository: apecloud/bash-busybox
45+
pullPolicy: IfNotPresent
46+
# Overrides the image tag whose default is the chart appVersion.
47+
tag: 1.37.0-musl-curl
48+
5049
backupImage:
5150
registry: ""
5251
repository: apecloud/clickhouse-backup-full
5352
pullPolicy: IfNotPresent
54-
tag: 2.6.14
53+
tag: 2.6.42
5554

5655
restore:
5756
schemaReadyTimeoutSeconds: 1800

addons/etcd/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ images:
4949
pullPolicy: IfNotPresent
5050
bashBusybox:
5151
repository: apecloud/bash-busybox
52-
tag: 1.37.0-musl
52+
tag: 1.37.0-musl-curl

0 commit comments

Comments
 (0)