Deploying istio sidecar for Jaeger Tracing

# Introduction

### What is Istio and Jaeger?

Istio is a service mesh that helps manage, secure, and monitor microservices running inside a Kubernetes cluster. It automatically adds a sidecar proxy (Envoy) to each service to handle traffic routing, security, and observability — without changing your application code.

Jaeger is a distributed tracing system used to monitor and visualize how requests flow through different services. With Jaeger, you can trace requests across microservices, identify performance bottlenecks, and debug failures more easily.

Together, Istio + Jaeger allows you to see detailed traces of every request, helping you understand and optimize your system's behavior.

In this article, I’ll walk you through how to:

- Deploy Istio into a Kubernetes cluster
- Inject Istio sidecars into your application pods
- Enable and configure Jaeger for distributed tracing
- Access and use the Jaeger UI with istioctl

# Required Environment
Below are the software requirements and versions used for this setup:

| Software Type          | Software Name       | Version          |
|------------------------|---------------------|------------------|
| Kubernetes             | K3s                 | v1.31.5+k3s1     |
| Kubernetes Nodes       | -                   | At least 1 (2+ recommended) |
| Istio                  | Istio               | v1.26.0          |
| Jaeger (via Istio)     | Jaeger              | v1.53.0          |


# Istio Setup
## 1.1 Installing Istio with Jaeger Integration

We’ll use the demo profile for simplicity, which includes Jaeger out of the box.

- Step-by-step Installation
```
# Download Istio
curl -L https://istio.io/downloadIstio | sh -
cd istio-<version>
export PATH=$PWD/bin:$PATH

# Install Istio with tracing components (demo profile includes Jaeger)
istioctl install --set profile=demo -y
```

- `curl -L https://istio.io/downloadIstio | sh -`
    - This command downloads the latest version of Istio and unpacks it into your current directory.
- `cd istio-<version>`
   - Moves you into the newly downloaded Istio directory (e.g., istio-1.22.0).
- `export PATH=$PWD/bin:$PATH`
   - Adds the Istio CLI tool istioctl to your system’s PATH so you can use it from anywhere in the terminal.
- `istioctl install --set profile=demo -y`
   - Installs Istio into your Kubernetes cluster using the demo profile, which includes helpful add-ons like Jaeger (tracing), Kiali (visual service map), Grafana (metrics dashboard), and Prometheus (monitoring). This is great for learning and experimenting.

To verify the installation, use the following command.
```
kubectl get pods -n istio-system
```
You should see a jaeger pod running in the istio-system namespace.


## 1.2 Injecting Istio Sidecars

Istio sidecars can be injected automatically or manually. We'll enable automatic injection using namespace labeling.

### 1.2.1 Label the Namespace for Auto-Injection
```
kubectl label namespace default istio-injection=enabled
```
This command adds a label (`istio-injection=enabled`) to the default namespace. It tells Istio to automatically inject the Envoy sidecar proxy into all pods deployed in that namespace.

Without this label, new pods won’t have the Istio sidecar unless you inject it manually.

### 1.2.2 Apply to all relevant namespaces

If your applications run in multiple namespaces, you’ll need to label each one like this:
```
kubectl label namespace <your-namespace> istio-injection=enabled
```
Replace <your-namespace> with the actual namespace name (e.g., frontend, backend, etc.).
This ensures Istio's features like tracing, metrics, and traffic control are applied to all your services.

# Accessing the Jaeger Dashboard

## 2.1 Accessing jaeger UI through istioctl command

Instead of manual port-forwarding, Istio provides a built-in command:
```
istioctl dashboard jaeger --address localhost
```
This will launch the Jaeger UI in your default browser at:
```
http://localhost:16686
```

As an example, when i accessed the jaeger dashboard from the cdsl's doktor-share-ancher server, the below happened.

```
cdsl@doktor-share-ancher:~$ istioctl dashboard jaeger --address 192.168.100.178
http://192.168.100.178:16686
Failed to open browser; open http://192.168.100.178:16686 in your browser.
```

The above is an example of accessing jaeger through the istioctl command.
Since there are permission issues to directly open the browser from my VM, i will access the following site.
```
http://192.168.100.178:16686
```

## 2.2 Jaeger UI
This is an example of what the Jaeger UI will look like.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3893426/747b544f-231f-4f80-b5dc-cd03021543bd.png)

The Jaeger UI helps you trace how a request flows through different microservices in your system. It shows a timeline of each service the request passes through, how long each one takes, and where delays or errors happen. You can see the full path of a request, filter by service or time, and debug performance issues by checking detailed logs and tags for each trace.

## 2.3 Jaeger UI features

By using the Jaeger UI, we now have access to a lot of microservice tracing features to further analyze request behavior and service performance, such as visualizing request paths, measuring response time per service, identifying slow spans, and detecting where failures occur.

### 2.3.1 Microservice Trace Filtering
In the jaeger UI, you can select which microservice's trace you want to analyse, and further specify it by certain metrics.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3893426/51164226-50ff-4602-8fdf-3b0ed438a1fc.png)


The metrics that can be changed are
- service/microservice name
- the time range/stamp the trace was taken
- number of traces
- tags 
- operation

### 2.3.2 Trace Upload
Apart from directly analysing live traces from the application, you can also save traces as a .json file and upload it to the jaeger UI to be used.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3893426/d759dba3-9032-4c2e-b9c2-a22a174026f4.png)

this feature allows you to analyse traces during a certain evernt or when the application is down.

### 2.3.3 Comparing traces

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3893426/78123efc-26fb-4a60-9b95-372f9b541241.png)

The jaeger UI also allows you to compare the differences between two different traces. Each trace has a unique Trace ID, which can be used in the `compare` tab for further analysis.

### 2.3.4 System Architecture
The jaeger UI also allows you to have better understanding of the architecture of the current system/application you are working on. The UI provides two graphs which are derived from the flow of microservices where the traces are obtained from

- Force Directed Graph

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3893426/678609c1-1456-4919-8f60-380e084e9f0e.png)


The Force Directed Graph (FDG) is a visualization that displays the relationships between different services in a distributed system. It uses a physical simulation to arrange the nodes (representing services) and edges (representing dependencies) in a way that makes it easier to understand the structure of the system. 

- Directed Acyclic Graph

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3893426/642b997d-357d-4c4f-9498-709a548a3fdf.png)

The Directed Acyclic Graph(DAG) is a graph that is directed and without cycles connecting the other edges. The graph enables to detect any cyclic dependencies between the microservices.

### 2.3.5 Monitor 

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3893426/4f44abf9-2366-43a5-94af-de4b5603699e.png)


The "Monitor" tab in the Jaeger UI provides a high-level view of service health and performance, using Service Performance Monitoring (SPM). It displays aggregated metrics like request rates, error rates, and latencies at both the service and operation levels. This tab helps identify potential issues and anomalies in your system without needing to know specific service or operation names upfront, according to Jaeger documentation. 


# Reference

| Topic         | Link | Description |
|---------------|------|-------------|
| **K3s**       | [https://k3s.io/](https://k3s.io/) | Official K3s homepage — lightweight Kubernetes for edge/IoT. Includes install instructions. |
|               | [K3s Installation Guide](https://docs.k3s.io/installation/) | Step-by-step installation and system requirements for K3s. |
| **Kubernetes**| [https://kubernetes.io/docs/home/](https://kubernetes.io/docs/home/) | Official Kubernetes documentation — includes concepts, tutorials, and API references. |
|               | [Kubernetes Download Tools](https://kubernetes.io/docs/tasks/tools/) | Guide to install `kubectl` and other Kubernetes tools. |
| **Istio**     | [https://istio.io/latest/docs/](https://istio.io/latest/docs/) | Official Istio documentation site with installation, features, and examples. |
|               | [Istio Quick Start](https://istio.io/latest/docs/setup/getting-started/) | Beginner-friendly setup guide with sample apps. |
|               | [Download Istio](https://istio.io/latest/docs/setup/getting-started/#download) | How to download and install Istio using `istioctl`. |
| **Jaeger**    | [https://www.jaegertracing.io/docs/](https://www.jaegertracing.io/docs/) | Official Jaeger documentation — learn what Jaeger is and how to use it. |
|               | [Jaeger Getting Started](https://www.jaegertracing.io/docs/2.6/getting-started/) | Beginner-friendly walkthrough with Docker examples. |
|               | [Jaeger Configuration](https://www.jaegertracing.io/docs/2.6/configuration/) | Full guide to configuring Jaeger including backend options. |