By default, ClickHouse services are only accessible within the cluster. Use an OpsRequest to expose the ClickHouse HTTP or native TCP port externally.
kubectl v1.21+ installed and configured with cluster accessdemo namespace: kubectl create ns demoA LoadBalancer requires cloud provider support. On bare-metal or local clusters, use serviceType: NodePort instead and remove the annotations block.
kubectl apply -f - <<EOF
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: clickhouse-expose-enable
namespace: demo
spec:
type: Expose
clusterName: clickhouse-cluster
expose:
- componentName: clickhouse
services:
- name: internet
serviceType: NodePort
ports:
- name: http
port: 8123
targetPort: http
switch: Enable
EOF
Monitor progress:
kubectl get opsrequest clickhouse-expose-enable -n demo -w
NAME TYPE CLUSTER STATUS PROGRESS AGE
clickhouse-expose-enable Expose clickhouse-cluster Succeed 1/1 15s
Get the external endpoint:
kubectl get service -n demo -l app.kubernetes.io/instance=clickhouse-cluster
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
clickhouse-cluster-clickhouse-0 ClusterIP 10.100.xx.xx <none> 8123/TCP,... 10m
clickhouse-cluster-clickhouse-0-headless ClusterIP None <none> ... 10m
clickhouse-cluster-clickhouse-internet NodePort 10.100.yy.yy <none> 8123:3xxxx/TCP 15s
kubectl apply -f - <<EOF
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: clickhouse-expose-disable
namespace: demo
spec:
type: Expose
clusterName: clickhouse-cluster
expose:
- componentName: clickhouse
services:
- name: internet
serviceType: NodePort
switch: Disable
EOF
kubectl delete opsrequest clickhouse-expose-enable clickhouse-expose-disable -n demo --ignore-not-found