使用HELM在阿里雲下佈署KAFKA

一、helm安裝

1)下載helm客戶端

helm git

https://github.com/helm/helm/blob/master/docs/install.md?spm=a2c4e.11153940.blogcont159601.23.670342e63B1sLX&file=install.md

kafka-manager下載

https://github.com/yahoo/kafka-manager/releases

 

2)helm客戶端爲v2.12.2版本,所以helm服務端建議使用相同版本的tiller(helm服務端程序)。

安裝tiller時會報錯,因會使用grc.io,google的鏡像。

#helm init --upgrade

需使用國內鏡像源。

#helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.12.2 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

其他安裝方式可以查看第一點安裝說明。

3)安裝完成後,查看helm服務端與客戶端版本

#helm version

Client: &version.Version{SemVer:"v2.12.2", GitCommit:"7d2b0c73d734f6586ed222a567c5d103fed435be", GitTreeState:"clean"}

Server: &version.Version{SemVer:"v2.12.2", GitCommit:"7d2b0c73d734f6586ed222a567c5d103fed435be", GitTreeState:"clean"}

#helm search 

NAME                                  CHART VERSION APP VERSION   DESCRIPTION                                                 

incubator/ack-arms-pilot              0.1.1                       ARMS Pilot - Webhook Admission Controller                   

incubator/ack-hyperledger-fabric      0.2.2         1.1.0         Hyperledger Fabric Helm chart for Kubernetes on Alibaba C...

incubator/exposecontroller            2.3.82                                                                                  

incubator/glusterfs                   0.1.0                       GlusterFS is a scalable network filesystem                  

incubator/jenkins-x-platform          0.0.3193                    Jenkins X next gen cloud CI / CD platform for Kubernetes    

incubator/kafka                       0.2.1                       Apache Kafka is publish-subscribe messaging rethought as ...

..........

helm --help

Flags:

--debug enable verbose output

-h, --help help for helm

--home string location of your Helm config. Overrides $HELM_HOME (default "/Users/huming/.helm")

--host string address of Tiller. Overrides $HELM_HOST

--kube-context string name of the kubeconfig context to use

--kubeconfig string absolute path to the kubeconfig file to use

--tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300)

--tiller-namespace string namespace of Tiller (default "kube-system")

4)向helm服務端查看已安裝的chart

client#helm list 

如有報錯,需在每臺node上安裝socat,以centos7爲例。

k8s-node1#yum install socat

5)添加rbac,爲tiller更新serviceaccount從default改爲tiller.

自Kubernetes 1.6版本開始,API Server啓用了RBAC授權。而目前的Tiller部署沒有定義授權的ServiceAccount,這會導致訪問API Server時被拒絕。我們可以採用如下方法,明確爲Tiller部署添加授權。

client#kubectl create serviceaccount --namespace kube-system tiller

client#kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller

client#kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'

二、中間件佈署

1、中間件特點:

1、中件間一般啓動和關閉存在順序執行;

2、使用比較大的共享存儲。

3、使用存儲時,因每個雲廠商的存儲驅動不一樣,需要按需修改。

4、使用storageclass進行掛載volume極簡單化。

2、kafka+zk中間件(kafka3節點,zk3節點,kafka manager1節點佈署)

2.1添加一個 阿里雲倉庫:

client#helm repo add incubator https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/

client#helm repo update

client#helm search kafka

NAME           CHART VERSION APP VERSION DESCRIPTION                                                 

incubator/kafka 0.2.1                   Apache Kafka is publish-subscribe messaging rethought as ...

2.2下載kafka

client#heml fetch incubator/kafka

client# ls 

kafka-0.2.1.tgz

2.3解壓和查看目錄結構

client# tar xvf kafka-0.2.1.tgz && cd kafka

client#tree

2.4配置修改

1)把./charts/zookeeper/templates/statefulset.yaml中的zookeeper的鏡像地址改爲registry.cn-hangzhou.aliyuncs.com/appstore/k8szk:v2 

2)查看華爲雲的storageclass,並做修改,查看到華爲雲支持的有多個類型的,我們目前選擇普通IO型的雲盤(alicloud-disk-efficiency),做爲存儲使用。

client$ kubectl get sc --all-namespaces
NAME                       PROVISIONER     AGE
alicloud-disk-available    alicloud/disk   43d
alicloud-disk-common       alicloud/disk   43d
alicloud-disk-efficiency   alicloud/disk   43d
alicloud-disk-ssd          alicloud/disk   43d

將以下兩個文件中的橘紅色部分,改爲alicloud-disk-efficiency,這裏如在阿里雲操作,需改爲阿里雲提供支持的類型。

3)添加kafka manager配置。

#cd charts/ && helm create kafkamanager

後加需更新配置。

#helm update kafka ./

2.5安裝kafka

client#cd kafka
client#helm install ./ -n kafka  --namespace  middle
client#helm status kafka
client#helm ls
client#kubectl get statefulset -n middle
client#kubectl get svc -n middle
client#kubectl get pvc -n middle

2.6測試。

配置kafkamanager:

場景:

1)k8s集羣內的服務訪問kafka;

2)羣集外部應用訪問kafka;

測試流程:

登錄任意一個kafka pod,

1、創建一個topic

pod# bin/kafka-topics.sh --create --zookeeper 10.247.171.181:2181 --replication-factor 1 --partitions 1 --topic device

2、創建消費者

pod# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic device --from-beginning

3、創建生產者

pod#bin/kafka-console-producer.sh --broker-list localhost:9092 --topic device 使用本地ip

pod#bin/kafka-console-producer.sh --broker-list 10.247.40.178:9092 --topic device 使用集羣ip

集羣外,可使用內部slb或nodeport形式訪問kafka。

client#bin/kafka-console-producer.sh --broker-list 10.10.10.119:30946 --topic device 使用服務器內網ip和nodeport

client#bin/kafka-console-producer.sh --broker-list 10.10.31.211:30946 --topic device 使用SLB ip

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章