架构模型
示例1
部署一个kubernetes类型的sink,这里面还是以event-display为例,下面是资源清单
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: event-display
spec:
replicas: 1
selector:
matchLabels: &labels
app: event-display
template:
metadata:
labels: *labels
spec:
containers:
- name: event-display
image: ikubernetes/event_display
---
kind: Service
apiVersion: v1
metadata:
name: event-display
spec:
selector:
app: event-display
ports:
- protocol: TCP
port: 80
targetPort: 8080
定义pingsource资源,指定sink为event-display
apiVersion: sources.knative.dev/v1
kind: PingSource
metadata:
name: ping-00001
spec:
schedule: "* * * * *"
contentType: "application/json"
data: '{"message": "Hello Eventing!"}'
sink:
ref:
apiVersion: v1
kind: Service
name: event-display
后面knative-eventing
的namespace会出现pingsource的POD
获取event-display当中的日志信息,验证是否进行了事件发送
kubectl logs -f event-display-6496b6c66d-7drk5
架构
示例2
部署一个kservice类型的sink,这里面还是以event-display为例,下面是资源清单
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: event-display
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/min-scale: "1"
spec:
containers:
- image: ikubernetes/event_display
ports:
- containerPort: 8080
定义pingsource资源,指定sink为event-display
---
apiVersion: sources.knative.dev/v1
kind: PingSource
metadata:
name: pingsource-00001
spec:
schedule: "* * * * *"
contentType: "application/json"
data: '{"message": "Hello Eventing!"}'
sink:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display
获取event-display当中的日志信息,验证是否进行了事件发送
kubectl logs -f event-display-00001-deployment-7f488cb57b-grsc6
旨在收集一些容器的event是,比如容器的一些元数据,下面是架构:
示例2
部署一个kservice类型的sink,这里面还是以event-display为例,下面是资源清单
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: event-display
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/min-scale: "1"
spec:
containers:
- image: ikubernetes/event_display
ports:
- containerPort: 8080
定义containergsource资源,指定sink为event-display
apiVersion: sources.knative.dev/v1
kind: ContainerSource
metadata:
name: containersource-heartbeat
spec:
template:
spec:
containers:
- image: ikubernetes/containersource-heartbeats:latest
name: heartbeats
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
sink:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display
在event-display的名称空间创建了一个containersource的pod
获取event-display当中的日志信息,验证是否进行了事件发送
kubectl logs -f event-display-00001-deployment-645944b779-2b4vt
apiserversource主要记录了aoiserver上的event,比如create/delete/update/get,架构如下:
示例4:
部署一个kservice类型的sink,这里面还是以event-display为例,下面是资源清单
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: event-display
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/min-scale: "1"
spec:
containers:
- image: ikubernetes/event_display
ports:
- containerPort: 8080
定义ServiceAccount:定义向指定目标资源的get,watch,list的相关权限
apiVersion: v1
kind: ServiceAccount
metadata:
name: pod-watcher
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-reader
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pod-reader
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: pod-reader
subjects:
- kind: ServiceAccount
name: pod-watcher
定义apiserversource资源,结合serviceaccount,对指定权限的pod进行收集event
apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
name: pods-event
spec:
serviceAccountName: pod-watcher
mode: Reference
resources:
- apiVersion: v1
kind: Pod
sink:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display
会发现创建一个apiserversource的pod
获取event-display当中的日志信息,验证是否进行了事件发送
kubectl logs -f event-display-00001-deployment-9469968cd-vb4l2
示例环境说明
具体步骤
具体操作