|
| 1 | +# Introduction to OpenTelemetry Operator |
| 2 | + |
| 3 | +OpenTelemetry Operator [documentation](https://opentelemetry.io/docs/platforms/kubernetes/operator/) |
| 4 | + |
| 5 | +## We need a Kubernetes cluster |
| 6 | + |
| 7 | +Lets create a Kubernetes cluster to play with using [kind](https://kind.sigs.k8s.io/docs/user/quick-start/) |
| 8 | + |
| 9 | +``` |
| 10 | +kind create cluster --name otel --image kindest/node:v1.34.0 |
| 11 | +``` |
| 12 | + |
| 13 | +Test our cluster: |
| 14 | + |
| 15 | +``` |
| 16 | +kubectl get nodes |
| 17 | +NAME STATUS ROLES AGE VERSION |
| 18 | +otel-control-plane Ready control-plane 40s v1.34.0 |
| 19 | +``` |
| 20 | + |
| 21 | +## Helm charts |
| 22 | + |
| 23 | +### OpenTelemetry Operator chart |
| 24 | +``` |
| 25 | +helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts |
| 26 | +helm repo update |
| 27 | +
|
| 28 | +helm search repo open-telemetry --versions |
| 29 | +``` |
| 30 | + |
| 31 | +We'll install version `0.93.0` at the time of this guide. |
| 32 | +I would suggest to make sure the version you pick is compatible with the Kubernetes version you are running. </br> |
| 33 | + |
| 34 | +``` |
| 35 | +OTEL_VERSION=0.93.0 |
| 36 | +``` |
| 37 | + |
| 38 | +### Cert-manager chart |
| 39 | + |
| 40 | +We will need cert-manager deployed which Otel uses for local TLS certificate management |
| 41 | + |
| 42 | +``` |
| 43 | +helm repo add jetstack https://charts.jetstack.io |
| 44 | +
|
| 45 | +helm search repo jetstack --versions |
| 46 | +``` |
| 47 | + |
| 48 | +We'll install version `v1.18.2` of cert-manager at the time of this guide which is compatible with our Kubernetes version. </br> |
| 49 | + |
| 50 | +``` |
| 51 | +CERTMANAGER_VERSION=v1.18.2 |
| 52 | +``` |
| 53 | + |
| 54 | +### Install helm charts |
| 55 | + |
| 56 | +Install cert-manager: |
| 57 | + |
| 58 | +``` |
| 59 | +helm install \ |
| 60 | +cert-manager jetstack/cert-manager \ |
| 61 | +--namespace cert-manager \ |
| 62 | +--create-namespace \ |
| 63 | +--version $CERTMANAGER_VERSION \ |
| 64 | +--set crds.enabled=true \ |
| 65 | +--set startupapicheck.timeout="5m" |
| 66 | +``` |
| 67 | + |
| 68 | +Install OpenTelemetry Operator: |
| 69 | + |
| 70 | +``` |
| 71 | +helm install opentelemetry-operator open-telemetry/opentelemetry-operator \ |
| 72 | +--namespace opentelemetry-operator-system \ |
| 73 | +--create-namespace \ |
| 74 | +--version $OTEL_VERSION \ |
| 75 | +--values=monitoring/opentelemetry/kubernetes/values.yaml |
| 76 | +``` |
| 77 | + |
| 78 | +View our install: |
| 79 | + |
| 80 | +``` |
| 81 | +kubectl get pods -n cert-manager |
| 82 | +kubectl get pods -n opentelemetry-operator-system |
| 83 | +``` |
| 84 | + |
| 85 | +## Create a Collector |
| 86 | + |
| 87 | +In this guide I copied a starter collector from the [official documentation](https://opentelemetry.io/docs/platforms/kubernetes/operator/#getting-started) and changed some of the values. |
| 88 | + |
| 89 | +To split out the guides, we'll have separate collectors for logs, metrics and traces. |
| 90 | + |
| 91 | +Let's deploy our collectors in a central `monitoring` namespace: |
| 92 | + |
| 93 | +``` |
| 94 | +
|
| 95 | +kubectl create namespace monitoring |
| 96 | +
|
| 97 | +kubectl apply -n monitoring -f monitoring/opentelemetry/kubernetes/collector-tracing.yaml |
| 98 | +``` |
| 99 | + |
| 100 | +View our collector: |
| 101 | + |
| 102 | +``` |
| 103 | +kubectl -n monitoring get pods |
| 104 | +kubectl -n monitoring get svc |
| 105 | +``` |
| 106 | + |
| 107 | +## Tracing |
| 108 | + |
| 109 | +### Instrumentation |
| 110 | + |
| 111 | +To start receiving traces, we'll be using the OpenTelemetry [auto instrumentation](https://opentelemetry.io/docs/platforms/kubernetes/operator/automatic/) to inject the instrumentation into our Kubernetes pods. |
| 112 | + |
| 113 | +To make use of the auto injection for Opentelemetry, we use the `Instrumentation` resources. |
| 114 | + |
| 115 | +Note that I am creating this in the default namespace next to where my applications are. |
| 116 | + |
| 117 | +``` |
| 118 | +kubectl apply -f monitoring/opentelemetry/kubernetes/instrumentation.yaml |
| 119 | +``` |
| 120 | + |
| 121 | +### Deploy Microservices |
| 122 | + |
| 123 | +Build applications: |
| 124 | + |
| 125 | +``` |
| 126 | +docker compose --file monitoring/opentelemetry/docker-compose.yaml build |
| 127 | +``` |
| 128 | + |
| 129 | +Load images into `kind`: |
| 130 | + |
| 131 | +``` |
| 132 | +kind load docker-image aimvector/service-mesh:videos-web-1.0.0 --name otel |
| 133 | +kind load docker-image aimvector/service-mesh:playlists-api-1.0.0 --name otel |
| 134 | +kind load docker-image aimvector/service-mesh:videos-api-1.0.0 --name otel |
| 135 | +``` |
| 136 | + |
| 137 | +``` |
| 138 | +kubectl apply -f monitoring/opentelemetry/applications/playlists-api/ |
| 139 | +kubectl apply -f monitoring/opentelemetry/applications/playlists-db/ |
| 140 | +kubectl apply -f monitoring/opentelemetry/applications/videos-web/ |
| 141 | +kubectl apply -f monitoring/opentelemetry/applications/videos-db/ |
| 142 | +kubectl apply -f monitoring/opentelemetry/applications/videos-api/ |
| 143 | +``` |
| 144 | + |
| 145 | +Generate some traffic with `port-forward` |
| 146 | + |
| 147 | +``` |
| 148 | +kubectl port-forward svc/videos-web 80:80 |
| 149 | +kubectl port-forward svc/playlists-api 81:80 |
| 150 | +``` |
| 151 | + |
| 152 | +### Tracing Data Store |
| 153 | + |
| 154 | +In this guide, we'll use a Tempo database for tracing data |
| 155 | + |
| 156 | +``` |
| 157 | +helm repo add grafana https://grafana.github.io/helm-charts |
| 158 | +helm repo update |
| 159 | +
|
| 160 | +helm search repo grafana/tempo |
| 161 | +
|
| 162 | +TEMPO_VERSION=1.23.3 |
| 163 | +
|
| 164 | +helm upgrade tempo grafana/tempo \ |
| 165 | + --create-namespace \ |
| 166 | + --namespace grafana \ |
| 167 | + --version $TEMPO_VERSION \ |
| 168 | + --values monitoring/opentelemetry/kubernetes/tempo.yaml |
| 169 | +``` |
| 170 | + |
| 171 | +### Metrics Data Store |
| 172 | + |
| 173 | +In this guide, we'll use a Prometheus for our metrics data |
| 174 | + |
| 175 | +``` |
| 176 | +helm repo add prometheus-community https://prometheus-community.github.io/helm-charts |
| 177 | +helm search repo prometheus-community --versions |
| 178 | +
|
| 179 | +PROMETHEUS_STACK_VERSION=77.5.0 |
| 180 | +
|
| 181 | +helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \ |
| 182 | + --version ${PROMETHEUS_STACK_VERSION} \ |
| 183 | + --namespace prometheus-operator-system \ |
| 184 | + --create-namespace \ |
| 185 | + --set prometheusOperator.enabled=true \ |
| 186 | + --set prometheusOperator.nodeSelector."kubernetes\.io/os"=linux \ |
| 187 | + --set prometheusOperator.fullnameOverride="prometheus-operator" \ |
| 188 | + --set prometheusOperator.manageCrds=true \ |
| 189 | + --set alertmanager.enabled=false \ |
| 190 | + --set grafana.enabled=false \ |
| 191 | + --set prometheus-node-exporter.enabled=false \ |
| 192 | + --set nodeExporter.enabled=false \ |
| 193 | + --set kubeStateMetrics.enabled=false \ |
| 194 | + --set prometheus.enabled=false |
| 195 | +
|
| 196 | +kubectl -n prometheus-operator-system get pods |
| 197 | +
|
| 198 | +# Deploy our dedicated Prometheus for metrics storage |
| 199 | +
|
| 200 | +kubectl apply -n monitoring -f monitoring/opentelemetry/kubernetes/prometheus.yaml |
| 201 | +``` |
| 202 | + |
| 203 | +### Dashboards |
| 204 | + |
| 205 | +In this guide I use a simple Grafana for dashboards |
| 206 | + |
| 207 | +``` |
| 208 | +helm search repo grafana/grafana |
| 209 | +
|
| 210 | +GRAFANA_VERSION=9.4.4 |
| 211 | +
|
| 212 | +helm install grafana grafana/grafana \ |
| 213 | + --namespace grafana \ |
| 214 | + --version $GRAFANA_VERSION \ |
| 215 | + --values monitoring/opentelemetry/kubernetes/grafana.yaml |
| 216 | +
|
| 217 | +``` |
| 218 | + |
| 219 | +### Access Grafana |
| 220 | + |
| 221 | +We can `port-forward` to Grafana |
| 222 | + |
| 223 | +``` |
| 224 | +kubectl -n grafana port-forward svc/grafana 3000:80 |
| 225 | +``` |
0 commit comments