《OpenShift / RHEL / DevSecOps 汇总目录》
说明:本文已经在支持 OpenShift 4.13 的环境中验证
Tempo 是 Grafana 公司推出的可对云原生应用实现请求跟踪的开源产品。它和 Jaeger 的功能大体相当,首先可以接收从被跟踪目标通过 OpenTelemetry 或 ZIPKIN 发送的跟踪数据,然后集中保存跟踪数据,最后通过 Jaeger 或 Grafana 界面进行展现。
Tempo 和 Jaeger 相比较大的区别是 Jaeger 一般使用诸如 Elasticsearch 这样的数据库来保存其接收到的跟踪数据,而 Tempo 则直接使用对象存储保存其接收到的跟踪数据。
$ oc new-project tempo-demo
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
app.kubernetes.io/name: minio
name: minio
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: minio
spec:
selector:
matchLabels:
app.kubernetes.io/name: minio
strategy:
type: Recreate
template:
metadata:
labels:
app.kubernetes.io/name: minio
spec:
containers:
- command:
- /bin/sh
- -c
- |
mkdir -p /storage/tempo && \
minio server /storage
env:
- name: MINIO_ACCESS_KEY
value: tempo
- name: MINIO_SECRET_KEY
value: supersecret
image: minio/minio
name: minio
ports:
- containerPort: 9000
volumeMounts:
- mountPath: /storage
name: storage
volumes:
- name: storage
persistentVolumeClaim:
claimName: minio
---
apiVersion: v1
kind: Service
metadata:
name: minio
spec:
ports:
- port: 9000
protocol: TCP
targetPort: 9000
selector:
app.kubernetes.io/name: minio
type: ClusterIP
apiVersion: v1
kind: Secret
metadata:
name: minio
stringData:
endpoint: http://minio.tempo-demo.svc:9000
bucket: tempo
access_key_id: tempo
access_key_secret: supersecret
type: Opaque
apiVersion: tempo.grafana.com/v1alpha1
kind: TempoStack
metadata:
name: my-tempo
spec:
storage:
secret:
name: minio
type: s3
storageSize: 1Gi
resources:
total:
limits:
memory: 2Gi
cpu: 2000m
template:
queryFrontend:
jaegerQuery:
enabled: true
$ oc get deploy -l app.kubernetes.io/name=tempo
NAME READY UP-TO-DATE AVAILABLE AGE
tempo-my-tempo-compactor 1/1 1 1 14m
tempo-my-tempo-distributor 1/1 1 1 14m
tempo-my-tempo-querier 1/1 1 1 14m
tempo-my-tempo-query-frontend 1/1 1 1 14m
$ oc get svc -l app.kubernetes.io/name=tempo
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
tempo-my-tempo-compactor ClusterIP 10.217.4.119 <none> 7946/TCP,3200/TCP 16m
tempo-my-tempo-distributor ClusterIP 10.217.5.226 <none> 4317/TCP,3200/TCP 16m
tempo-my-tempo-gossip-ring ClusterIP None <none> 7946/TCP 16m
tempo-my-tempo-ingester ClusterIP 10.217.4.249 <none> 3200/TCP,9095/TCP 16m
tempo-my-tempo-querier ClusterIP 10.217.4.88 <none> 7946/TCP,3200/TCP,9095/TCP 16m
tempo-my-tempo-query-frontend ClusterIP 10.217.4.144 <none> 3200/TCP,9095/TCP,16686/TCP,16687/TCP 16m
tempo-my-tempo-query-frontend-discovery ClusterIP None <none> 3200/TCP,9095/TCP,9096/TCP,16686/TCP,16687/TCP 16m
$ oc expose service tempo-my-tempo-query-frontend --port=16686
$ oc get route tempo-my-tempo-query-frontend -o jsonpath='{.spec.host}'
tempo-my-tempo-query-frontend-tempo-demo.apps.cluster-6htgt.6htgt.sandbox2251.opentlc.com
$ oc apply -f - <apiVersion: batch/v1
kind: Job
metadata:
name: tracegen
spec:
template:
spec:
containers:
- name: tracegen
image: ghcr.io/open-telemetry/opentelemetry-collector-contrib/tracegen:latest
command:
- "./tracegen"
args:
- -otlp-endpoint=tempo-my-tempo-distributor:4317
- -otlp-insecure
- -duration=300s
- -workers=1
restartPolicy: Never
backoffLimit: 4
EOF
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: otel-demo-app
name: otel-demo-app
spec:
replicas: 1
selector:
matchLabels:
app: otel-demo-app
template:
metadata:
labels:
app: otel-demo-app
spec:
containers:
- image: quay.io/rbaumgar/otelcol-demo-app-jvm
imagePullPolicy: IfNotPresent
name: otel-demo-app
env:
- name: OTELCOL_SERVER
value: 'http://tempo-my-tempo-distributor:4317'
---
apiVersion: v1
kind: Service
metadata:
labels:
app: otel-demo-app
name: otel-demo-app
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
name: web
selector:
app: otel-demo-app
type: ClusterIP
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: otel-demo-app
name: otel-demo-app
spec:
path: /
to:
kind: Service
name: otel-demo-app
port:
targetPort: web
$ export URL=$(oc get route otel-demo-app -o jsonpath='{.spec.host}')
$ curl $URL/hello
hello
$ curl $URL/sayHello/demo1
hello: demo1
$ curl $URL/sayRemote/demo2
hello: demo2 from http://otel-demo-app-tempo-demo.apps-crc.testing/
https://tempo-operator.netlify.app/docs/prologue/quickstart.md/