Skip to content

Commit 0a0841e

Browse files
authored
Added support for Gateway API, Istio Ambient Mode (#10)
1 parent c368700 commit 0a0841e

34 files changed

Lines changed: 550 additions & 39 deletions

.github/workflows/opentofu-plan.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
type: [istio, cilium]
21+
type: [istio-sidecar, cilium]
2222

2323
name: 'Terraform'
2424
runs-on: ubuntu-latest
@@ -54,7 +54,7 @@ jobs:
5454
skip_check: CKV_K8S_25,CKV_K8S_22,CKV_K8S_35,CKV_K8S_26,CKV_K8S_11,CKV_K8S_15,CKV_K8S_12
5555

5656
- name: Upload SARIF file
57-
uses: github/codeql-action/upload-sarif@v3
57+
uses: github/codeql-action/upload-sarif@v4
5858
# Results are generated only on a success or failure
5959
# this is required since GitHub by default won't run the next step
6060
# when the previous one has failed. Security checks that do not pass will 'fail'.

.github/workflows/terraform-plan.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
type: [istio, cilium]
21+
type: [istio-sidecar, cilium]
2222

2323
name: 'Terraform'
2424
runs-on: ubuntu-latest
@@ -54,7 +54,7 @@ jobs:
5454
skip_check: CKV_K8S_25,CKV_K8S_22,CKV_K8S_35,CKV_K8S_26,CKV_K8S_11,CKV_K8S_15,CKV_K8S_12
5555

5656
- name: Upload SARIF file
57-
uses: github/codeql-action/upload-sarif@v3
57+
uses: github/codeql-action/upload-sarif@v4
5858
# Results are generated only on a success or failure
5959
# this is required since GitHub by default won't run the next step
6060
# when the previous one has failed. Security checks that do not pass will 'fail'.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
*.lock.hcl
1010
local-cluster-config
1111
kubeconfig*
12+
*.yaml
13+
!example.yaml
14+
!gateway.yaml

Makefile

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,44 @@ help:
2727
$(info - create-cluster-cilium: creates the cluster with Cilium enabled)
2828
$(info - destroy-cluster-cilium: deletes the cluster with Cilium enabled)
2929
$(info )
30-
$(info - create-cluster-istio: creates the cluster with Istio enabled)
31-
$(info - destroy-cluster-istio: deletes the cluster with Istio enabled)
30+
$(info - create-cluster-istio-ambient: creates the cluster with Istio enabled - Ambient Mode)
31+
$(info - destroy-cluster-istio-ambient: deletes the cluster with Istio enabled - Ambient Mode)
32+
$(info )
33+
$(info - create-cluster-istio-sidecar: creates the cluster with Istio enabled - Sidecar Mode)
34+
$(info - destroy-cluster-istio-sidecar: deletes the cluster with Istio enabled - Sidecar Mode)
35+
36+
.PHONY: create-cluster-istio-ambient
37+
create-cluster-istio-ambient: export WORKING_PATH=$(ROOT_DIR)/examples/kind-with-istio-ambient
38+
create-cluster-istio-ambient: init apply ## Creates a local cluster with Istio (Ambient Mode) enabled
39+
@echo "Created the cluster with Istio (Ambient Mode) enabled"
3240

33-
.PHONY: create-cluster-istio
34-
create-cluster-istio: export WORKING_PATH=$(ROOT_DIR)/examples/kind-with-istio
35-
create-cluster-istio: init
36-
create-cluster-istio: apply
37-
create-cluster-istio: ## Creates a local cluster with Istio enabled
38-
@echo "Created the cluster with Istio enabled"
41+
.PHONY: create-cluster-istio-sidecar
42+
create-cluster-istio-sidecar: export WORKING_PATH=$(ROOT_DIR)/examples/kind-with-istio-sidecar
43+
create-cluster-istio-sidecar: init apply ## Creates a local cluster with Istio (Sidecar Mode) enabled
44+
@echo "Created the cluster with Istio (Sidecar Mode) enabled"
3945

4046
.PHONY: create-cluster-cilium
4147
create-cluster-cilium: export WORKING_PATH=$(ROOT_DIR)/examples/kind-with-cilium
42-
create-cluster-cilium: init
43-
create-cluster-cilium: apply
44-
create-cluster-cilium: ## Creates a local cluster with Cilium enabled
48+
create-cluster-cilium: init apply ## Creates a local cluster with Cilium enabled
4549
@echo "Created the cluster with Cilium enabled"
4650

47-
.PHONY: destroy-cluster-istio
48-
destroy-cluster-istio: export WORKING_PATH=$(ROOT_DIR)/examples/kind-with-istio
49-
destroy-cluster-istio: destroy
50-
destroy-cluster-istio: ## Destroys a previously created local cluster with Istio
51-
@echo "Created the cluster with Istio enabled"
51+
.PHONY: destroy-cluster-istio-ambient
52+
destroy-cluster-istio-ambient: export WORKING_PATH=$(ROOT_DIR)/examples/kind-with-istio-ambient
53+
destroy-cluster-istio-ambient: destroy
54+
destroy-cluster-istio-ambient: ## Destroys a previously created local cluster with Istio (Ambient Mode)
55+
@echo "Destroyed the cluster with Istio (Ambient Mode)"
56+
57+
.PHONY: destroy-cluster-istio-sidecar
58+
destroy-cluster-istio-sidecar: export WORKING_PATH=$(ROOT_DIR)/examples/kind-with-istio-sidecar
59+
destroy-cluster-istio-sidecar: destroy
60+
destroy-cluster-istio-sidecar: ## Destroys a previously created local cluster with Istio (Sidecar Mode)
61+
@echo "Destroyed the cluster with Istio (Sidecar Mode)"
5262

5363
.PHONY: destroy-cluster-cilium
5464
destroy-cluster-cilium: export WORKING_PATH=$(ROOT_DIR)/examples/kind-with-cilium
5565
destroy-cluster-cilium: destroy
5666
destroy-cluster-cilium: ## Destroys a previously created local cluster with Cilium
57-
@echo "Created the cluster with Cilium enabled"
67+
@echo "Destroyed the cluster with Cilium"
5868

5969
.PHONY: fmt
6070
fmt: ## Performs auto-formatting of the code
@@ -76,7 +86,7 @@ docs: ## Generates documentation for all terraform modules
7686

7787
init: ## Initializes the working directory
7888
cd $(WORKING_PATH)
79-
$(TF_BIN) init -upgrade -reconfigure
89+
$(TF_BIN) init
8090
$(TF_BIN) validate
8191
cd -
8292

examples/kind-with-cilium/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ and all the resources will be deleted.
4646

4747
| Name | Version |
4848
|------|---------|
49-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6.0 |
49+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.8.0 |
5050
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | 3.1.1 |
51-
| <a name="requirement_kind"></a> [kind](#requirement\_kind) | 0.10.0 |
51+
| <a name="requirement_kind"></a> [kind](#requirement\_kind) | 0.11.0 |
5252
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | 3.0.1 |
5353

5454
## Modules

examples/kind-with-cilium/providers.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
terraform {
2-
required_version = ">= 1.6.0"
2+
required_version = ">= 1.8.0"
3+
34
required_providers {
45
kind = {
56
source = "tehcyx/kind"
6-
version = "0.10.0"
7+
version = "0.11.0"
78
}
89
helm = {
910
source = "hashicorp/helm"
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# kind-with-istio-ambient
2+
3+
This example shows how a KIND (Kubernetes-in-Docker) Cluster, configured with Istio in Ambient Mode, can be created with easy steps.
4+
5+
The configuration of the Gateway API Controller is perfomed with the `docker` Provider, following [this guide](https://kubernetes.io/blog/2026/01/28/experimenting-gateway-api-with-kind/).
6+
7+
Additionally, the example will deploy a Workload example taken directly from the [Istio Repository](https://github.com/istio/istio),
8+
9+
The Gateway API Controller will map the port 80 and expose the Service through it. If you want to use the HTTPS port, you need to customise the `example.yaml` file and also register a valid key pair to be used for the TLS communication.
10+
11+
## Requirements
12+
13+
The following tools are required for this project:
14+
15+
* `docker` (up and running)
16+
* `terraform` (1.6+) / `opentofu` (1.6+)
17+
* `helm` (3.0+)
18+
* `kind` (0.30.0+)
19+
20+
## How to run the example
21+
22+
In a Terminal, type the following commands to initialize the Terraform/OpenTofu Workspace and create the cluster:
23+
24+
```sh
25+
export TF_BIN=tofu # change to `terraform` if you want to use Terraform instead of OpenTofu
26+
$TF_BIN init
27+
$TF_BIN plan
28+
$TF_BIN apply
29+
# Apply again to overcome a bug with the Kubernetes Provider while applying the Manifest for Gateway
30+
$TF_BIN apply
31+
```
32+
33+
After the completion of the above described commands, if no error has been returned, you should see that 2 Containers are running:
34+
35+
* the Kubernetes Control Plane
36+
* two Worker Nodes
37+
38+
Additionally, a new file, `kubeconfig`, will be placed in this folder, giving you the possibility to authenticate yourself against the cluster and inspect it with your favorite tool (e.g. k9s, headlamp, Lens).
39+
40+
You can now access the example Service at the following address:
41+
42+
`http://localhost/hello`
43+
44+
e.g. with `cURL`:
45+
46+
```sh
47+
GW_ADDR=$(kubectl get gateway -n istio-ingress gateway -o jsonpath='{.status.addresses[0].value}')
48+
curl --resolve helloworld.example.com:80:$GW_ADDR http://helloworld.example.com/hello
49+
```
50+
51+
You should see the message:
52+
53+
`Hello version: v2, instance: helloworld-v2-<unique-id>`
54+
55+
At this point you can also use the `istioctl` command line tool to verify that the cluster is working with Istio successfully.
56+
57+
## How to destroy the cluster
58+
59+
In a Terminal, you can simply run:
60+
61+
```sh
62+
export TF_BIN=tofu # change to `terraform` if you want to use Terraform instead of OpenTofu
63+
$TF_BIN destroy
64+
```
65+
66+
and all the resources will be deleted.
67+
<!-- BEGIN_TF_DOCS -->
68+
## Requirements
69+
70+
| Name | Version |
71+
|------|---------|
72+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.8.0 |
73+
| <a name="requirement_docker"></a> [docker](#requirement\_docker) | 3.9.0 |
74+
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | 3.1.1 |
75+
| <a name="requirement_kind"></a> [kind](#requirement\_kind) | 0.11.0 |
76+
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | 3.0.1 |
77+
| <a name="requirement_null"></a> [null](#requirement\_null) | 3.2.4 |
78+
79+
## Modules
80+
81+
| Name | Source | Version |
82+
|------|--------|---------|
83+
| <a name="module_istio"></a> [istio](#module\_istio) | ../../modules/istio-mesh | n/a |
84+
| <a name="module_kind"></a> [kind](#module\_kind) | ../../modules/kind-cluster | n/a |
85+
86+
## Resources
87+
88+
| Name | Type |
89+
|------|------|
90+
| [docker_container.cloud_controller_manager](https://registry.terraform.io/providers/kreuzwerker/docker/3.9.0/docs/resources/container) | resource |
91+
| [docker_image.cloud_controller_manager](https://registry.terraform.io/providers/kreuzwerker/docker/3.9.0/docs/resources/image) | resource |
92+
| [kubernetes_manifest.gateway](https://registry.terraform.io/providers/hashicorp/kubernetes/3.0.1/docs/resources/manifest) | resource |
93+
| [kubernetes_namespace_v1.ingress](https://registry.terraform.io/providers/hashicorp/kubernetes/3.0.1/docs/resources/namespace_v1) | resource |
94+
| [kubernetes_namespace_v1.workshop](https://registry.terraform.io/providers/hashicorp/kubernetes/3.0.1/docs/resources/namespace_v1) | resource |
95+
| [null_resource.install_example](https://registry.terraform.io/providers/hashicorp/null/3.2.4/docs/resources/resource) | resource |
96+
97+
## Inputs
98+
99+
| Name | Description | Type | Default | Required |
100+
|------|-------------|------|---------|:--------:|
101+
| <a name="input_port_configuration"></a> [port\_configuration](#input\_port\_configuration) | Defines the port mappings for the cluster nodes | <pre>map(object({<br/> app_protocol = string<br/> node_port = number<br/> host_port = number<br/> target_port = number<br/> protocol = string<br/> }))</pre> | <pre>{<br/> "http": {<br/> "app_protocol": "http",<br/> "host_port": 80,<br/> "node_port": 30000,<br/> "protocol": "TCP",<br/> "target_port": 80<br/> },<br/> "https": {<br/> "app_protocol": "https",<br/> "host_port": 443,<br/> "node_port": 30001,<br/> "protocol": "TCP",<br/> "target_port": 443<br/> },<br/> "status-port": {<br/> "app_protocol": "http",<br/> "host_port": 15021,<br/> "node_port": 30002,<br/> "protocol": "TCP",<br/> "target_port": 15021<br/> }<br/>}</pre> | no |
102+
103+
## Outputs
104+
105+
No outputs.
106+
<!-- END_TF_DOCS -->
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: http
5+
spec:
6+
parentRefs:
7+
- name: gateway
8+
namespace: istio-ingress
9+
hostnames: ["helloworld.example.com"]
10+
rules:
11+
- backendRefs:
12+
- name: helloworld
13+
port: 5000
14+
---
15+
apiVersion: v1
16+
kind: Service
17+
metadata:
18+
name: helloworld
19+
labels:
20+
app: helloworld
21+
service: helloworld
22+
spec:
23+
ports:
24+
- port: 5000
25+
name: http
26+
selector:
27+
app: helloworld
28+
version: v2
29+
---
30+
apiVersion: apps/v1
31+
kind: Deployment
32+
metadata:
33+
name: helloworld-v1
34+
labels:
35+
app: helloworld
36+
version: v1
37+
spec:
38+
replicas: 1
39+
selector:
40+
matchLabels:
41+
app: helloworld
42+
version: v1
43+
template:
44+
metadata:
45+
labels:
46+
app: helloworld
47+
version: v1
48+
spec:
49+
containers:
50+
- name: helloworld
51+
image: docker.io/istio/examples-helloworld-v1:1.0
52+
resources:
53+
requests:
54+
cpu: "100m"
55+
imagePullPolicy: IfNotPresent
56+
ports:
57+
- containerPort: 5000
58+
---
59+
apiVersion: apps/v1
60+
kind: Deployment
61+
metadata:
62+
name: helloworld-v2
63+
labels:
64+
app: helloworld
65+
version: v2
66+
spec:
67+
replicas: 1
68+
selector:
69+
matchLabels:
70+
app: helloworld
71+
version: v2
72+
template:
73+
metadata:
74+
labels:
75+
app: helloworld
76+
version: v2
77+
spec:
78+
containers:
79+
- name: helloworld
80+
image: docker.io/istio/examples-helloworld-v2:1.0
81+
resources:
82+
requests:
83+
cpu: "100m"
84+
imagePullPolicy: IfNotPresent
85+
ports:
86+
- containerPort: 5000
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: gateway
5+
namespace: istio-ingress
6+
spec:
7+
gatewayClassName: istio
8+
listeners:
9+
- name: default
10+
hostname: "*.example.com"
11+
port: 80
12+
protocol: HTTP
13+
allowedRoutes:
14+
namespaces:
15+
from: All
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Pulls the image
2+
resource "docker_image" "cloud_controller_manager" {
3+
name = "registry.k8s.io/cloud-provider-kind/cloud-controller-manager:v0.10.0"
4+
}
5+
6+
# Create a container
7+
resource "docker_container" "cloud_controller_manager" {
8+
image = docker_image.cloud_controller_manager.image_id
9+
name = "cloud-provider-kind"
10+
rm = true
11+
network_mode = "host"
12+
13+
volumes {
14+
host_path = "/var/run/docker.sock"
15+
container_path = "/var/run/docker.sock"
16+
}
17+
}

0 commit comments

Comments
 (0)