k8s的heapster项目中止以后,
事件收集的项目,就推荐使用https://github.com/heptiolabs/eventrouter项目了。
部署文档很简单,但有两个问题要解决:
一,eventrouter的官方镜像如何拿到?
官方yaml文件里,镜像地址为:
gcr.io/heptio-images/eventrouter:latest
众所周知,这个url不***,在国内是不可能下载的。
于是,我们迂回一点操作。
1,在github上新建一个项目,里面只有一个文件,Dockerfile。内容可如下:
FROM gcr.io/heptio-images/eventrouter:latest MAINTAINER chengang <aguncn@163.com>
2,在dockerhub里,新建一个自动编译的仓库,项目指向github里的项目。
3,编译成功之后,docker pull命令下载即可。
二,如何将sink配置为kafka?
默认的sink为glog,是控制台输出,那如何将集件输出到kafka中的呢?
这时,就不得不吐槽一下官方文件文档了,连一个像样的配置demo都找不到。
于是,只好看看源文件中go的接口,凑合了一个最简版的json文件。
https://github.com/heptiolabs/eventrouter/blob/master/sinks/interfaces.go
case "kafka": viper.SetDefault("kafkaBrokers", []string{"kafka:9092"}) viper.SetDefault("kafkaTopic", "eventrouter") viper.SetDefault("kafkaAsync", true) viper.SetDefault("kafkaRetryMax", 5) brokers := viper.GetStringSlice("kafkaBrokers") topic := viper.GetString("kafkaTopic") async := viper.GetBool("kakfkaAsync") retryMax := viper.GetInt("kafkaRetryMax") e, err := NewKafkaSink(brokers, topic, async, retryMax) if err != nil { panic(err.Error()) } return e
最终作成的yaml文件内容如下:# Copyright 2017 Heptio Inc.## Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: v1
kind: ServiceAccount
metadata:
name: eventrouter
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: eventrouter
rules:
- apiGroups: [""]
resources: ["events"]
verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: eventrouter
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: eventrouter
subjects:
- kind: ServiceAccount
name: eventrouter
namespace: kube-system
---
apiVersion: v1
data:
config.json: |-
{
"sink": "kafka"
"kafkaBrokers": ["x1:9092", "x2:9092"]
}
kind: ConfigMap
metadata:
name: eventrouter-cm
namespace: kube-system
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: eventrouter
namespace: kube-system
labels:
app: eventrouter
spec:
replicas: 1
selector:
matchLabels:
app: eventrouter
template:
metadata:
labels:
app: eventrouter
tier: control-plane-addons
spec:
containers:
- name: kube-eventrouter
image: harbor/3rd_part/eventrouter:20190311
imagePullPolicy: IfNotPresent
volumeMounts:
- name: config-volume
mountPath: /etc/eventrouter
serviceAccount: eventrouter
volumes:
- name: config-volume
configMap:
name: eventrouter-cm
如果kafka后面接的elk,那么,在kibana中看到的样子如下:
所有评论(0)