Skip to content
Open
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
215 changes: 181 additions & 34 deletions docs/content/reference/ingress/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,13 @@ Unlike Azure Application Gateway which requires a static IP address, ALBs are dy
drasi ingress init --use-existing --ingress-class-name alb --ingress-annotation "alb.ingress.kubernetes.io/scheme=internet-facing" --ingress-annotation "alb.ingress.kubernetes.io/target-type=ip"
```

### Using Ingress in Local Clusters (kind)
When running Drasi in local Kubernetes clusters like [kind](https://kind.sigs.k8s.io/), you need to configure ingress differently since you don't have cloud load balancers available.
### Using Ingress in Local Clusters
When running Drasi in local Kubernetes clusters like [kind](https://kind.sigs.k8s.io/) or [k3d](https://k3d.io/), you need to configure ingress differently since you don't have cloud load balancers available.

#### Prerequisites
- A kind cluster with Drasi installed
- kubectl configured to connect to your kind cluster

#### Setting up Ingress Controller
For local development with kind, you can use the built-in Contour ingress controller that Drasi can install:

```bash
drasi ingress init
```

This will install Contour as the ingress controller in your kind cluster.
#### Using Ingress with kind

#### NodePort Access
There are two ways of using ingress in a local cluster like kind. The examples below are for kind clusters.

You can configure kind to expose ports directly:
##### Option 1: Direct Port Access
You can configure kind to expose ports directly by creating your cluster with port mapping. This would require you to create a custom kind configuration file and then create the cluster using that configuration:

1. Create your kind cluster with port mapping:
```yaml
Expand All @@ -146,40 +133,200 @@ apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 8080
protocol: TCP
- containerPort: 443
hostPort: 8443
protocol: TCP
- containerPort: 30080 # Maps to contour-envoy NodePort 30080
hostPort: 8001
listenAddress: "0.0.0.0"
- containerPort: 30443 # Maps to contour-envoy NodePort 30443
hostPort: 443
listenAddress: "0.0.0.0"
```

2. Create the cluster:
```bash
kind create cluster --config kind-config.yaml
```

3. Install Drasi and configure ingress:
3. Install Drasi by following the [installation guide](/how-to-guides/installation/install-on-kind/).


4. Initialize ingress with the `--local-cluster` flag:
```bash
drasi ingress init --local-cluster
```

With this setup, access your ingress resources by appending `:8001` to the INGRESS URL shown in `drasi list`.

**Example:**

If you've deployed a Drasi Reaction called `hello-world-debug`, running `drasi list reaction` will show:
```bash
ID | AVAILABLE | INGRESS URL | MESSAGES
----------------------+-----------+---------------------------------------------------+-----------
hello-world-debug | true | http://hello-world-debug.drasi.127.0.0.1.nip.io |
```

You can then access this Reaction at:
```
http://hello-world-debug.drasi.127.0.0.1.nip.io:8001
```


##### Option 2: Port Forwarding for Local Access
If you didn't configure port mapping during cluster creation, you can use port forwarding to access your ingress resources.

1. Install Drasi by following the [installation guide](/how-to-guides/installation/install-on-kind/).
2. Initialize ingress with the `--local-cluster` flag:
```bash
drasi ingress init --local-cluster
```

3. Forward the Contour service to localhost:
```bash
kubectl port-forward -n projectcontour svc/contour-envoy 8080:80
```

There are two ways to access your ingress resources.

**Method A: Browser Access (requires hosts file entries)**

Add entries to your hosts file for each of your ingress resources:

On **Linux/macOS**:
```bash
echo "127.0.0.1 <reaction/source name>.drasi.127.0.0.1.nip.io" | sudo tee -a /etc/hosts
```

On **Windows** (run PowerShell as Administrator):
```powershell
Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value "127.0.0.1 <reaction/source name>.drasi.127.0.0.1.nip.io"
```

Then access in your browser:
```
http://<reaction/source name>.drasi.127.0.0.1.nip.io:8080
```

**Method B: Using curl with Host header (no /etc/hosts needed)**

This method is simpler and doesn't require modifying system files:
```bash
drasi ingress init
curl http://localhost:8080 -H "Host: <reaction/source name>.drasi.127.0.0.1.nip.io"
```

With this setup, your ingress resources will be accessible directly via `http://localhost:8080`.
#### Using Ingress with k3s/k3d


##### About k3s and k3d
[k3d](https://k3d.io/) is a lightweight wrapper to run [k3s](https://k3s.io/) (Rancher's minimal Kubernetes distribution) in Docker. k3s comes with Traefik as the default ingress controller, but you can disable it and use Contour instead for consistency with other environments.

#### Alternative: Port Forwarding for Local Access
Alternatively, since kind clusters don't have external load balancers, you can use port forwarding to access your ingress resources locally:
##### Option 1: Using k3d with Contour

1. First, find the Contour envoy service:
1. Create your k3d cluster with Traefik disabled and port mapping:
```bash
kubectl get svc -n projectcontour
k3d cluster create -p '8081:30080@server:0' --k3s-arg '--disable=traefik@server:0'

# **Note:** The `--k3s-arg` parameter is optional. You can omit it if you want to keep Traefik enabled.
```

2. Forward the ingress controller port to your local machine:
2. Install Drasi by following the [installation guide](/how-to-guides/installation/install-on-k3d/).
3. Initialize ingress with the `--local-cluster` and Contour websocket annotation:
```bash
drasi ingress init --local-cluster --ingress-annotation "projectcontour.io/websocket-routes=/"
```

With this setup, access your ingress resources by appending `:8081` to the INGRESS URL shown in `drasi list`.
**Example:**
If you've deployed a Drasi Reaction called `hello-world-debug`, running `drasi list reaction` will show:
```bash
ID | AVAILABLE | INGRESS URL | MESSAGES
----------------------+-----------+---------------------------------------------------+-----------
hello-world-debug | true | http://hello-world-debug.drasi.127.0.0.1.nip.io |
```

You can then access this Reaction at:
```
http://hello-world-debug.drasi.127.0.0.1.nip.io:8081
```


##### Option 2: Using k3d with Traefik

If you prefer to use the built-in Traefik ingress controller:

1. Create your k3d cluster with port mapping (Traefik enabled by default):
```bash
k3d cluster create my-cluster \
--port 8080:80@loadbalancer \
--port 8443:443@loadbalancer
```

2. Configure Drasi to use the existing Traefik ingress controller:
```bash
drasi ingress init --use-existing --ingress-class-name traefik --ingress-ip-address 127.0.0.1
```

With this setup, access your ingress resources by appending `:8080` to the INGRESS URL shown in `drasi list`.
**Example:**
If you've deployed a Drasi Reaction called `hello-world-debug`, running `drasi list reaction will show:
```bash
ID | AVAILABLE | INGRESS URL | MESSAGES
----------------------+-----------+---------------------------------------------------+-----------
hello-world-debug | true | http://hello-world-debug.drasi.127.0.0.1.nip.io |
```
You can then access this Reaction at:
```
http://hello-world-debug.drasi.127.0.0.1.nip.io:8080
```

##### Option 3: Port Forwarding for Local Access

Similar to kind, you can use port forwarding if you didn't configure port mapping during cluster creation:


1. Install Drasi by following the [installation guide](/how-to-guides/installation/install-on-kind/).
2. Initialize ingress with the `--local-cluster` flag:
```bash
# For Contour
drasi ingress init --local-cluster --ingress-annotation "projectcontour.io/websocket-routes=/"

# For Traefik
drasi ingress init --use-existing --ingress-class-name traefik --ingress-ip-address 127.0.0.1
```

3. Forward the ingress controller port to your local machine:
```bash
# For Contour
kubectl port-forward -n projectcontour svc/envoy 8080:80

# For Traefik
kubectl port-forward -n kube-system svc/traefik 8080:80
```

3. After applying your Drasi resources with ingress configuration, you can access them via `localhost:8080` with the appropriate Host header:

There are two ways to access your ingress resources.

**Method A: Browser Access (requires hosts file entries)**

Add entries to your hosts file for each of your ingress resources:

On **Linux/macOS**:
```bash
echo "127.0.0.1 <reaction/source name>.drasi.127.0.0.1.nip.io" | sudo tee -a /etc/hosts
```

On **Windows** (run PowerShell as Administrator):
```powershell
Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value "127.0.0.1 <reaction/source name>.drasi.127.0.0.1.nip.io"
```

Then access in your browser:
```
http://<reaction/source name>.drasi.127.0.0.1.nip.io:8080
```

**Method B: Using curl with Host header (no /etc/hosts needed)**

This method is simpler and doesn't require modifying system files:
```bash
curl -H "Host: hello-world-debug.drasi.127.0.0.1.nip.io" http://localhost:8080
curl http://localhost:8080 -H "Host: <reaction/source name>.drasi.127.0.0.1.nip.io"
```