Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions collector/istio/examples/k8s/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.21-alpine AS build

WORKDIR /app
COPY . .
RUN go build -o app main.go

FROM alpine:3.14
COPY --from=build /app/app /app
ENTRYPOINT ["/app"]
105 changes: 105 additions & 0 deletions collector/istio/examples/k8s/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
kind := $(shell command -v kind 2> /dev/null)
docker := $(shell command -v docker 2> /dev/null)
@kubectl := $(shell command -v kubectl 2> /dev/null)
@kill := $(shell command -v kill 2> /dev/null)
@curl := $(shell command -v curl 2> /dev/null)
@lsof := $(shell command -v lsof 2> /dev/null)
@istioctl := $(shell command -v istioctl 2> /dev/null)

CLUSTER_NAME := "go-istio-cluster"
CLUSTER_CONFIG := "kind-config.yaml"
IMAGE_NAME := "go-istio-demo"
IMAGE_TAG := "latest"

.PHONY: all
all: create-cluster deploy-image deploy-otel deploy-isito-telemetry

.PHONY: check-istioctl
check-istioctl:
@echo "Checking istioctl..."
ifndef @istioctl
$(error "istioctl is not available please install it")
else
@echo "istioctl is available"
endif

.PHONY: install-istioctl
install-istioctl:
@echo "Installing istioctl..."
ifndef @istioctl
curl -sL https://istio.io/downloadIstioctl | sh -
sudo mv ~/.istioctl/bin/istioctl /usr/local/bin/istioctl
else
@echo "istioctl is already installed"
endif

.PHONY: create-cluster
create-cluster:
@echo "Creating cluster..."
@kind create cluster --name $(CLUSTER_NAME) --config $(CLUSTER_CONFIG)

.PHONY: delete-cluster
delete-cluster:
@echo "Deleting cluster..."
@kind delete cluster --name $(CLUSTER_NAME)

.PHONY: build-image
build-image:
@echo "Building image..."
@docker build -t $(IMAGE_NAME) .

.PHONY: load-image
load-image:
@echo "Loading image..."
@kind load docker-image $(IMAGE_NAME):$(IMAGE_TAG) --name $(CLUSTER_NAME)

.PHONY: deploy-image
deploy-image: build-image load-image
@echo "Deploying image..."
@kubectl apply -f go-istio-demo.yaml
@kubectl apply -f sleep-demo.yaml

.PHONY: undeploy-image
undeploy-image:
@echo "Undeploying image..."
@kubectl delete -f sleep-demo.yaml
@kubectl delete -f go-istio-demo.yaml

.PHONY: deploy-otel
deploy-otel:
@echo "Deploying OpenTelemetry..."
@kubectl apply -f namespace.yaml
@kubectl apply -f lightstep-secret.yaml
@kubectl apply -f otel-collector-service.yaml
@kubectl apply -f otel-collector-rbac.yaml
@kubectl apply -f otel-collector-configmap.yaml
@kubectl apply -f otel-collector-deployment.yaml

.PHONY: undeploy-otel
undeploy-otel:
@echo "Undeploying OpenTelemetry..."
@kubectl delete -f otel-collector-deployment.yaml
@kubectl delete -f otel-collector-configmap.yaml
@kubectl delete -f otel-collector-rbac.yaml
@kubectl delete -f otel-collector-service.yaml
@kubectl delete -f lightstep-secret.yaml
@kubectl delete -f namespace.yaml

.PHONY: deploy-isito-telemetry
deploy-isito-telemetry: check-istioctl
@echo "Deploying Istio..."
@istioctl install
@kubectl apply -f istio-telemetry.yaml
@kubectl apply -f sleep-demo-telemtry.yaml

.PHONY: undeploy-istio-telemetry
undeploy-istio-telemetry:
@echo "Undeploying Istio..."
@kubectl delete -f sleep-demo-telemtry.yaml
@kubectl delete -f istio-telemetry.yaml

.PHONY: test
test:
@echo "Testing..."
@SOURCE_POD=$$(kubectl get pod -l app=sleep -n go-istio-demo -o jsonpath={.items..metadata.name}); \
kubectl -n go-istio-demo exec "$$SOURCE_POD" -c sleep -- curl -sS -v go-istio-demo:80/healthz
168 changes: 168 additions & 0 deletions collector/istio/examples/k8s/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Ingest metrics using the Istio integration

The OTel Collector has a variety of [third party receivers](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/master/receiver) that provide integration with a wide variety of metric sources.

Please note that not all metrics receivers available for the OpenTelemetry Collector have been tested by Cloud Observability, and there may be bugs or unexpected issues in using these contributed receivers with Cloud Observability metrics. File any issues with the appropriate OpenTelemetry community.
{: .callout}

## Prerequisites

* Docker
* Go: https://golang.org/doc/install
* Docker: https://docs.docker.com/get-docker/
* Kubernetes CLI (kubectl): https://kubernetes.io/docs/tasks/tools/install-kubectl/
* kind (Kubernetes in Docker): https://kind.sigs.k8s.io/docs/user/quick-start/
* Istio: https://istio.io/latest/docs/setup/getting-started/
* A Cloud Observability account
* Cloud Observability [access token][ls-docs-access-token]

## Running the Example

Run make to build the example:

```sh
make all
```


## Configuration

Installation of the OpenTelemetry Collector varies, please refer to the [collector documentation](https://opentelemetry.io/docs/collector/) for more information.

The example collector's configuration, used for this project shows using processors to add metrics with Cloud Observability:

``` yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: otel-collector-conf
namespace: istio-system
labels:
app: otel-collector
data:
otel-collector-config.yaml: |
receivers:
otlp:
protocols:
grpc:
http:

processors:
batch:

exporters:
logging:
loglevel: debug
otlp/lightstep:
endpoint: ingest.lightstep.com:443
headers:
"lightstep-access-token": "{LS_ACCESS_TOKEN}"
extensions:
health_check:

service:
extensions:
- health_check
pipelines:
logs:
receivers: [otlp]
processors: [batch]
exporters: [logging]
traces:
receivers: [otlp]
processors: [batch]
exporters: [logging, otlp/lightstep]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [logging, otlp/lightstep]
```

#### Build the Docker image:

```sh
make build-image
```

#### Create the cluster

```sh
make create-cluster
```

#### Install Istio

* Label the default namespace to enable automatic sidecar injection for Istio

```sh
istioctl install --set profile=demo -y
kubectl label namespace default istio-injection=enabled
```

#### Load the Docker image into the kind cluster

```sh
make load-image
```

#### Deploy the application

```sh
make deploy-image
```

#### Apply the otel deployment to your Kubernetes cluster

First edit the `[lightstep-secret.yaml](lightstep-secret.yaml)` file and replace `${LS_ACCESS_TOKEN}` with your [access token][ls-docs-access-token].
Then apply the secret & other otel resources to your cluster:

```sh
make deploy-otel
```

* Verify that the OpenTelemetry Collector is running:

```sh
kubectl get pods -l app=otel-collector
```

#### Apply the istio telemetry to your Kubernetes cluster

```sh
make deploy-isito-telemetry
```

#### Test service

```sh
kubectl -n go-istio-demo port-forward svc/go-istio-demo 8080:80
```

```sh
curl http://localhost:8080
Hello, Golang with Istio!
```

#### Checks

* Check the status of the pods in the go-istio-demo namespace

```sh
kubectl -n go-istio-demo get pods
```

```sh
kubectl port-forward svc/golang-demo 8080:80
```

* Check the pod's metrics logs and events

* Find the pod name of the OpenTelemetry Collector deployment

```sh
kubectl get pods -l app=otel-collector
kubectl logs -f <otel-collector-pod-name>
```


[ls-docs-access-token]: https://docs.lightstep.com/docs/create-and-manage-access-tokens
42 changes: 42 additions & 0 deletions collector/istio/examples/k8s/go-istio-demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: v1
kind: Namespace
metadata:
name: go-istio-demo
labels:
istio-injection: enabled
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: go-istio-demo
namespace: go-istio-demo
spec:
replicas: 1
selector:
matchLabels:
app: go-istio-demo
template:
metadata:
labels:
app: go-istio-demo
spec:
containers:
- name: app
image: go-istio-demo:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: go-istio-demo
namespace: go-istio-demo
spec:
selector:
app: go-istio-demo
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: ClusterIP
3 changes: 3 additions & 0 deletions collector/istio/examples/k8s/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module opentelementry-examples/istio

go 1.21
39 changes: 39 additions & 0 deletions collector/istio/examples/k8s/istio-telemetry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: istio
namespace: istio-system
data:
meshNetworks: |-
networks: {}
mesh: |-
accessLogFile: /dev/stdout
defaultConfig:
discoveryAddress: istiod.istio-system.svc:15012
defaultProviders:
accessLogging:
- opentelemetry
extensionProviders:
- name: "otel-tracing"
opentelemetry:
service: "otel-collector.istio-system.svc.cluster.local"
port: 4317
- name: "otel-logging"
envoyOtelAls:
service: "otel-collector.istio-system.svc.cluster.local"
port: 4317
enablePrometheusMerge: true
rootNamespace: istio-system
trustDomain: cluster.local
---
apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
name: mesh-default
spec:
accessLogging:
- providers:
- name: otel-logging
tracing:
- providers:
- name: otel-tracing
5 changes: 5 additions & 0 deletions collector/istio/examples/k8s/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
8 changes: 8 additions & 0 deletions collector/istio/examples/k8s/lightstep-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: lightstep-access-token
namespace: istio-system
type: Opaque
data:
access_token: ${LS_ACCESS_TOKEN}
Loading