This OpenTelemetry repository provides a complete demo on how you can deploy OpenTelemetry on Kubernetes, we can use this as a starting point.

OpenTelemetry solution
conn, err := grpc.DialContext(ctx, "localhost:30080", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())

Extra port mappings can be used to port forward to the kind nodes. This is a cross-platform option to get traffic into your kind cluster.

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
# port forward 30080 on the host to 30080 on this node
extraPortMappings:
- containerPort: 30080
hostPort: 30080
- role: worker
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.24.0) 🖼
✓ Preparing nodes 📦 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining worker nodes 🚜
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kindThanks for using kind! 😊

What is Jaeger?

Deploy Jaeger

Operators are pieces of software that ease the operational complexity of running another piece of software.

Before you start, pay attention to the Prerequisite section.

Since version 1.31 the Jaeger Operator uses webhooks to validate Jaeger custom resources (CRs). This requires an installed version of the cert-manager.

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.9.1/cert-manager.yaml

By default, cert-manager will be installed into the cert-manager namespace.

helm install my-release jaegertracing/jaeger-operator
helm install my-release jaegertracing/jaeger-operator --version 2.25.0

You can also deploy the Jaeger operator using deployment files.

kubectl create -f https://github.com/jaegertracing/jaeger-operator/releases/download/v1.36.0/jaeger-operator.yaml

NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
my-jaeger-operator 1/1 1 1 2m58s
apiVersion: jaegertracing.io/v1
kind: Jaeger
metadata:
name: simplest
NAME                     READY STATUS    RESTARTS   AGE
simplest-656d7cf5c8-lff7b 1/1 Running 0 3m55s
{"level":"info","ts":1660155049.86027,"caller":"channelz/logging.go:50","msg":"[core]Channel Connectivity change to READY","system":"grpc","grpc_log":true}
{"level":"info","ts":1660155049.8612773,"caller":"grpc/builder.go:120","msg":"Agent collector connection state change","dialTarget":":14250","status":"READY"}
{"level":"info","ts":1660155049.8617437,"caller":"app/server.go:241","msg":"Starting HTTP server","port":16686,"addr":":16686"}
{"level":"info","ts":1660155049.8621716,"caller":"app/server.go:260","msg":"Starting GRPC server","port":16685,"addr":":16685"}
Forwarding from 127.0.0.1:16686 -> 16686
Forwarding from [::1]:16686 -> 16686
Jaeger UI

Deploy the OpenTelemetry Collector

exporters:
jaeger:
endpoint: "simplest-collector.default.svc.cluster.local:14250"
...
otel-collector-config: |
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
...
configmap/otel-collector-conf created
service/otel-collector created
deployment.apps/otel-collector created
"Everything is ready. Begin running and processing data."

Run the application

Remember, that the application access the Kubernetes cluster through a NodePort on port 30080. The Kubernetes service will bind the 4317 port used to access the OTLP receiver to port 30080 on the Kubernetes node.

By doing so, it makes it possible for us to access the Collector by using the static address <node-ip>:30080. In case you are running a local cluster, this will be localhost:30080. Source

2022/08/10 20:31:37 Waiting for connection...
2022/08/10 20:31:37 Doing really hard work (1 / 10)
2022/08/10 20:31:38 Doing really hard work (2 / 10)
2022/08/10 20:31:39 Doing really hard work (3 / 10)
2022/08/10 20:31:40 Doing really hard work (4 / 10)
2022/08/10 20:31:41 Doing really hard work (5 / 10)
2022/08/10 20:31:42 Doing really hard work (6 / 10)
2022/08/10 20:31:43 Doing really hard work (7 / 10)
2022/08/10 20:31:44 Doing really hard work (8 / 10)
2022/08/10 20:31:45 Doing really hard work (9 / 10)
2022/08/10 20:31:46 Doing really hard work (10 / 10)
2022/08/10 20:31:47 Done!

Viewing the data

kubectl port-forward svc/simplest-query 16686:16686
res, err := resource.New(ctx,  resource.WithAttributes(   // the service name used to display traces in backends   semconv.ServiceNameKey.String("test-service"),  ),
conn, err := grpc.DialContext(ctx, "localhost:30080", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) if err != nil {  return nil, fmt.Errorf("failed to create gRPC connection to collector: %w", err) }
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐