Clickhouse集群化(二)单节点部署
1. k8s单节点部署
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: clickhouse
labels:
app: clickhouse
spec:
replicas: 1
serviceName: clickhouse
selector:
matchLabels:
app: clickhouse
template:
metadata:
labels:
app: clickhouse
spec:
containers:
- name: clickhouse
image: clickhouse-server:24.1.2.5
imagePullPolicy: IfNotPresent
env:
ports:
- containerPort: 8123
protocol: TCP
livenessProbe:
httpGet:
scheme: HTTP
path: /ping
port: 8123
initialDelaySeconds: 600
periodSeconds: 10
timeoutSeconds: 10
successThreshold: 1
failureThreshold: 6
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- "node1"
- "node2"
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- clickhouse
topologyKey: "kubernetes.io/hostname"
---
apiVersion: v1
kind: Service
metadata:
labels:
app: clickhouse
name: clickhouse
spec:
ipFamilies:
- IPv4
- IPv6
ipFamilyPolicy: PreferDualStack
type: NodePort
ports:
- port: 8123
protocol: TCP
targetPort: 8123
nodePort: 31120
selector:
app: clickhouse-v1
clickhouse默认使用无密码的default用户 也可以根据环境变量进行修改
apiVersion: v1
kind: Secret
metadata:
name: clickhouse-secrets
namespace: gzzx
type: Opaque
data:
user: xxx # Base64 编码的用户
password: xx # Base64 编码的密码
env:
- name: CLICKHOUSE_USER
valueFrom:
secretKeyRef:
name: clickhouse-secrets
key: user
- name: CLICKHOUSE_PASSWORD
valueFrom:
secretKeyRef:
name: clickhouse-secrets
key: password