Skip to content

Commit

Permalink
[exporter/loadbalancingexporter] add docs/example for k8s service re…
Browse files Browse the repository at this point in the history
…solver (#24362)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
improve document for k8s service resolver of
exporter/loadbalancingexporter

**Link to tracking Issue:** <Issue number if applicable>
#24287 

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>
Add example/k8s-resolver/README.md
The description of the k8s resolver from
exporter/loadbalancingexporter/README.md can be jump-linked to example.

Signed-off-by: Yuan Fang <yuanfang@alauda.io>
  • Loading branch information
fyuan1316 committed Jul 27, 2023
1 parent 562dc48 commit bca4670
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .chloggen/add-k8s-resolver-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: loadbalancingexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added docs for k8s service resolver.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [24287]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
2 changes: 1 addition & 1 deletion exporter/loadbalancingexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ service:
- loadbalancing
```

Kubernetes resolver example
Kubernetes resolver example (For a more specific example: [example/k8s-resolver](./example/k8s-resolver/README.md))
```yaml
receivers:
otlp:
Expand Down
121 changes: 121 additions & 0 deletions exporter/loadbalancingexporter/example/k8s-resolver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Trace ID aware load-balancing exporter demo for kubernetes service resolver

## How to run

1. Pre-requirements:
```shell
kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml
```

2. Once the opentelemetry-operator is deployed, create the OpenTelemetry Collector (otelcol) instances, ServiceAccount and other necessary resources, run:
```shell
kubectl apply -f - <<EOF
apiVersion: v1
kind: Namespace
metadata:
name: observability
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: loadbalancer-role
namespace: observability
rules:
- apiGroups:
- ""
resources:
- endpoints
verbs:
- list
- watch
- get
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: loadbalancer
namespace: observability
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: loadbalancer-rolebinding
namespace: observability
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: loadbalancer-role
subjects:
- kind: ServiceAccount
name: loadbalancer
namespace: observability
---
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: loadbalancer
namespace: observability
spec:
image: docker.io/jpkroehling/otelcol-with-k8sresolver:latest
serviceAccount: loadbalancer
config: |
receivers:
otlp:
protocols:
grpc:
processors:
exporters:
loadbalancing:
protocol:
otlp:
tls:
insecure: true
resolver:
k8s:
service: backends-collector-headless.observability
service:
pipelines:
traces:
receivers:
- otlp
processors: []
exporters:
- loadbalancing
---
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: backends
namespace: observability
spec:
replicas: 5
config: |
receivers:
otlp:
protocols:
grpc:
processors:
exporters:
logging:
service:
pipelines:
traces:
receivers:
- otlp
processors: []
exporters:
- logging
EOF
```

## How does it work
- The `loadbalancer` and `backends` OpenTelemetryCollector are recognised by the opentelemetry-operator, which then creates the appropriate deployment resources.
- The `loadbalancer` ServiceAccount is used to assign to the pods corresponding to the deployment loadbalancer and backends.
- The `loadbalancer-role` Role grants `get`, `list`, and `watch` permissions on endpoint resources in its namespace. Having these permissions is essential for a kubernetes service resolver to work properly.
- The `loadbalancer-rolebinding` RoleBinding is used to bind Role `loadbalancer-role` to ServiceAccount `loadbalancer`.

0 comments on commit bca4670

Please sign in to comment.