我使用 Azure Kubernetes Service (AKS) 和 Helm Chart 试着运行 Confluent 平台
简述
我整理了在AKS上配置环境的步骤,这些步骤涉及Confuent Platform的Helm Chart和ACR中的容器映像(Kafka Connector)来运行容器应用程序。

本地环境
-
- macOS Monterey 12.3
-
- python 3.8.12
-
- Azure CLI 2.34.1
- helm v3.6.3
事先准备
-
- 执行本文,并建立AKS集群环境。在图中标注为”②”。
执行本文,并将自定义的Kafka连接器Docker镜像推送到ACR(Azure容器注册表)。在图中标注为”③”。
创建(编辑)Helm Chart
Helm相关的预设设置和确认
## 現在ローカルにインストールされている Helm リポジトリ一覧
$ helm repo list
NAME URL
stable https://charts.helm.sh/stable
bitnami-azure https://marketplace.azurecr.io/helm/v1/repo
confluentinc https://confluentinc.github.io/cp-helm-charts/
bitnami https://charts.bitnami.com/bitnami
## アップデートコマンド
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "confluentinc" chart repository
...Successfully got an update from the "stable" chart repository
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "bitnami-azure" chart repository
Update Complete. ⎈Happy Helming!⎈
## Confluentのレポジトリの確認
$ helm search repo confluentinc
NAME CHART VERSION APP VERSION DESCRIPTION
confluentinc/cp-helm-charts 0.6.1 1.0 A Helm chart for Confluent Platform Community E...
stable/schema-registry-ui 0.4.4 v0.9.5 DEPRECATED - This is a web tool for the conflue...
## Helm Chrat の Pull
$ helm pull confluentinc/cp-helm-charts
$ tar zxf cp-helm-charts-0.6.1.tgz
$ ls -l
total 112
drwxr-xr-x 5 ituru staff 160 4 6 23:29 ./
drwxr-xr-x 3 ituru staff 96 4 6 22:59 ../
drwxr-xr-x 15 ituru staff 480 4 6 23:29 cp-helm-charts/
-rw-r--r-- 1 ituru staff 50496 4 6 23:29 cp-helm-charts-0.6.1.tgz
编辑 values.yaml 文件
关于cp-helm-charts中的values.yaml文件,我们将编辑以下部分(Confluent Platform使用版本6.1.0)。但是,仅使用已在ACR中注册的容器镜像来使用Kafka Connector。同时,由于本次不使用REST-Proxy,我们将其禁用。
cp-kafka-connectimageacr0ituru.azurecr.io/cp-connect-demo-cp610
cp-kafka-connectimageTag1.1.1
准备将AKS安装到系统中
获取用于连接AKS集群的身份验证信息
$ az aks get-credentials --resource-group rg_ituru_aks01 --name aks_ituru_cp01
The behavior of this command has been altered by the following extension: aks-preview
A different object named aks_ituru_cp01 already exists in your kubeconfig file.
Overwrite? (y/n): y
A different object named clusterUser_rg_ituru_aks01_aks_ituru_cp01 already exists in your kubeconfig file.
Overwrite? (y/n): y
A different object named aks_ituru_cp01 already exists in your kubeconfig file.
Overwrite? (y/n): y
Merged "aks_ituru_cp01" as current context in /Users/ituru/.kube/config
将应用部署到AKS。
等待一会儿,直到所有的Pod都启动完毕,可能需要几分钟时间。
## namespace の作成
$ kubectl create namespace akscp610
namespace/akscp610 created
## namespace のデフォルトとしての指定
$ kubectl config set-context --current --namespace akscp610
Context "aks_ituru_cp01" modified.
## デプロイ
$ helm install cp610 ./cp-helm-charts
部署完成后的确认
## インストール済み Chart の表示
$ helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
cp610 akscp610 1 2022-05-13 11:20:11.255235 +0900 JST deployed cp-helm-charts-0.6.1 1.0
## Pod の確認
$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
cp610-cp-control-center-f46bc647d-gxd4g 1/1 Running 3 (89s ago) 2m38s 10.0.1.10 aks-cpdemo01-25979417-vmss000000 <none> <none>
cp610-cp-kafka-0 2/2 Running 0 2m37s 10.0.1.78 aks-cpdemo01-25979417-vmss000002 <none> <none>
cp610-cp-kafka-1 2/2 Running 0 87s 10.0.1.42 aks-cpdemo01-25979417-vmss000001 <none> <none>
cp610-cp-kafka-2 2/2 Running 0 56s 10.0.1.19 aks-cpdemo01-25979417-vmss000000 <none> <none>
cp610-cp-kafka-connect-7d8fb4c776-25x6l 2/2 Running 2 (86s ago) 2m38s 10.0.1.41 aks-cpdemo01-25979417-vmss000001 <none> <none>
cp610-cp-ksql-server-656b866794-zt6mj 2/2 Running 2 (93s ago) 2m38s 10.0.1.17 aks-cpdemo01-25979417-vmss000000 <none> <none>
cp610-cp-schema-registry-d8466d9dd-jzmtf 2/2 Running 2 (45s ago) 2m38s 10.0.1.69 aks-cpdemo01-25979417-vmss000002 <none> <none>
cp610-cp-zookeeper-0 2/2 Running 0 2m37s 10.0.1.40 aks-cpdemo01-25979417-vmss000001 <none> <none>
cp610-cp-zookeeper-1 2/2 Running 0 94s 10.0.1.12 aks-cpdemo01-25979417-vmss000000 <none> <none>
cp610-cp-zookeeper-2 2/2 Running 0 50s 10.0.1.76 aks-cpdemo01-25979417-vmss000002 <none> <none>
## リソースの確認
$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
cp610-cp-control-center 1/1 1 1 3m37s
cp610-cp-kafka-connect 1/1 1 1 3m37s
cp610-cp-ksql-server 1/1 1 1 3m37s
cp610-cp-schema-registry 1/1 1 1 3m37s
## 起動サービスの確認
$ kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cp610-cp-control-center ClusterIP 10.1.0.83 <none> 9021/TCP 4m
cp610-cp-kafka ClusterIP 10.1.0.209 <none> 9092/TCP,5556/TCP 4m
cp610-cp-kafka-connect ClusterIP 10.1.0.38 <none> 8083/TCP,5556/TCP 4m
cp610-cp-kafka-headless ClusterIP None <none> 9092/TCP 4m
cp610-cp-ksql-server ClusterIP 10.1.0.150 <none> 8088/TCP,5556/TCP 4m
cp610-cp-schema-registry ClusterIP 10.1.0.168 <none> 8081/TCP,5556/TCP 4m
cp610-cp-zookeeper ClusterIP 10.1.0.250 <none> 2181/TCP,5556/TCP 4m
cp610-cp-zookeeper-headless ClusterIP None <none> 2888/TCP,3888/TCP 4m
## Config Map の確認
$ kubectl get configmap
NAME DATA AGE
cp610-cp-kafka-connect-jmx-configmap 1 4m27s
cp610-cp-kafka-jmx-configmap 1 4m27s
cp610-cp-ksql-server-jmx-configmap 1 4m27s
cp610-cp-ksql-server-ksql-queries-configmap 1 4m27s
cp610-cp-schema-registry-jmx-configmap 1 4m27s
cp610-cp-zookeeper-jmx-configmap 1 4m27s
kube-root-ca.crt 1 5m23s
设置之前的准备工作
创建 kafka-client Pod
为了设置 Kafka 主题,我们要准备一个客户端容器。我们将修改预先准备好的 kafka-client.yaml 文件,位于 cp-helm-charts/examples 目录下,修改内容如下。
apiVersion: v1
kind: Pod
metadata:
name: kafka-client
spec:
containers:
- name: kafka-client
image: confluentinc/cp-kafka:6.1.0
command:
- sh
- -c
- "exec tail -f /dev/null"
我要启动这个 Pod。
$ kubectl apply -f cp-helm-charts/examples/kafka-client.yaml
pod/kafka-client created
创建 ksql-client Pod
准备一个用于配置ksql的客户端容器。将cp-helm-charts/examples中预先准备的ksql-demo.yaml复制为ksql-client.yaml,并进行以下更改。
apiVersion: v1
kind: Pod
metadata:
name: ksql-client
spec:
containers:
- name: ksql-client
image: confluentinc/cp-ksqldb-cli:6.0.0
command:
- sh
- -c
- "exec tail -f /dev/null"
我会启动这个 Pod。
$ kubectl apply -f cp-helm-charts/examples/ksql-client.yaml
pod/ksql-client created
确认Pod的最新信息。
$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
cp610-cp-control-center-f46bc647d-gxd4g 1/1 Running 3 (5m8s ago) 6m17s 10.0.1.10 aks-cpdemo01-25979417-vmss000000 <none> <none>
cp610-cp-kafka-0 2/2 Running 0 6m16s 10.0.1.78 aks-cpdemo01-25979417-vmss000002 <none> <none>
cp610-cp-kafka-1 2/2 Running 0 5m6s 10.0.1.42 aks-cpdemo01-25979417-vmss000001 <none> <none>
cp610-cp-kafka-2 2/2 Running 0 4m35s 10.0.1.19 aks-cpdemo01-25979417-vmss000000 <none> <none>
cp610-cp-kafka-connect-7d8fb4c776-25x6l 2/2 Running 2 (5m5s ago) 6m17s 10.0.1.41 aks-cpdemo01-25979417-vmss000001 <none> <none>
cp610-cp-ksql-server-656b866794-zt6mj 2/2 Running 2 (5m12s ago) 6m17s 10.0.1.17 aks-cpdemo01-25979417-vmss000000 <none> <none>
cp610-cp-schema-registry-d8466d9dd-jzmtf 2/2 Running 2 (4m24s ago) 6m17s 10.0.1.69 aks-cpdemo01-25979417-vmss000002 <none> <none>
cp610-cp-zookeeper-0 2/2 Running 0 6m16s 10.0.1.40 aks-cpdemo01-25979417-vmss000001 <none> <none>
cp610-cp-zookeeper-1 2/2 Running 0 5m13s 10.0.1.12 aks-cpdemo01-25979417-vmss000000 <none> <none>
cp610-cp-zookeeper-2 2/2 Running 0 4m29s 10.0.1.76 aks-cpdemo01-25979417-vmss000002 <none> <none>
kafka-client 1/1 Running 0 52s 10.0.1.68 aks-cpdemo01-25979417-vmss000002 <none> <none>
ksql-client 1/1 Running 0 36s 10.0.1.52 aks-cpdemo01-25979417-vmss000001 <none> <none>
各种Pod连接和确认方法
连接到Pod
## Pod へのログイン(例)
$ kubectl exec -it kafka-client -- /bin/bash
$ kubectl exec -it ksql-client -- /bin/bash
连接至控制中心
## Confluent Platform の Control Center への接続(ポートフォワードの設定)
$ kubectl port-forward --address localhost svc/cp610-cp-control-center 9021:9021
Forwarding from 127.0.0.1:9021 -> 9021
Forwarding from [::1]:9021 -> 9021

确认 Kafka Connector
为了确认,将Connect重定向到本地主机。
$ kubectl port-forward --address localhost svc/cp610-cp-kafka-connect 8083:8083
Forwarding from 127.0.0.1:8083 -> 8083
Forwarding from [::1]:8083 -> 8083
※ CTRL+C で終了できます
打开另一个终端,并确认Kafka Connector插件是否存在。
$ curl http://localhost:8083/connector-plugins | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2031 100 2031 0 0 13891 0 --:--:-- --:--:-- --:--:-- 13910
[
{
"class": "com.azure.cosmos.kafka.connect.sink.CosmosDBSinkConnector",
"type": "sink",
"version": "null"
},
{
"class": "com.azure.cosmos.kafka.connect.source.CosmosDBSourceConnector",
"type": "source",
"version": "null"
},
:
中略
:
{
"class": "io.confluent.connect.azuresqldw.AzureSqlDwSinkConnector",
"type": "sink",
"version": "1.0.4"
},
:
中略
:
{
"class": "io.debezium.connector.mysql.MySqlConnector",
"type": "source",
"version": "1.8.1.Final"
},
:
省略
:
]

停止和启动AKS集群
$ az aks stop -g rg_ituru_aks01 -n aks_ituru_cp01
$ az aks start -g rg_ituru_aks01 -n aks_ituru_cp01
资源的卸载方法
## Pod のアンインストール方法(例)
$ helm delete cp610
W0407 17:38:18.658767 39907 warnings.go:70] policy/v1beta1 PodDisruptionBudget is deprecated in v1.21+, unavailable in v1.25+; use policy/v1 PodDisruptionBudget
release "cp610" uninstalled
$ kubectl delete -f cp-helm-charts/examples/kafka-client.yaml
$ kubectl delete -f cp-helm-charts/examples/ksql-client.yaml
## namespace の削除方法(namespace配下のPodも削除される)
$ kubectl delete namespace akscp610
namespace "akscp610" deleted
总结
现在,可以在AKS上构建Confluent Platform环境了。接下来,我想要对其进行配置,使其能够进行数据流处理,就像顶部的配置图一样。
请参考这篇文章。
過去に投稿した記事は、Azure Kubernetes Service (AKS) を使用して Confluent Platform の Helm Chart を使ってアプリケーションをデプロイして試してみたものです。