Skip to content

Commit 7f9933f

Browse files
committed
Initial commit
0 parents  commit 7f9933f

25 files changed

+740
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
.venv
3+
*__pycache__/
4+
istio-1.25.0/

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.PHONY: start-minikube
2+
start-minikube:
3+
@minikube start --driver=docker --cpus 8 --memory 8G --addons=metrics-server
4+
5+
.PHONY: install-istio
6+
install-istio:
7+
@istioctl install -f patches/tracing.yaml --skip-confirmation
8+
@kubectl apply -f patches/telemetry.yaml
9+
@kubectl label namespace default istio-injection=enabled --overwrite
10+
@kubectl apply \
11+
-f https://raw.githubusercontent.com/istio/istio/release-1.25/samples/addons/prometheus.yaml \
12+
-f https://raw.githubusercontent.com/istio/istio/release-1.25/samples/addons/kiali.yaml \
13+
-f https://raw.githubusercontent.com/istio/istio/release-1.25/samples/addons/grafana.yaml \
14+
-f https://raw.githubusercontent.com/istio/istio/release-1.25/samples/addons/jaeger.yaml
15+
@kubectl apply -k patches
16+
@kubectl rollout restart deployment -n istio-system grafana
17+
@kubectl rollout restart deployment -n istio-system kiali
18+
19+
.PHONY: create-python-app
20+
create-python-app:
21+
@kubectl apply -k python-app/k8s
22+
23+
.PHONY: test-python-app
24+
test-python-app:
25+
@./tests/h2load.sh

README.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Python Flask App with Istio Integration
2+
3+
This project is a simple Flask web application deployed in Kubernetes using Istio for traffic management and monitoring.
4+
5+
## Project Structure
6+
7+
---
8+
9+
```text
10+
├── Makefile
11+
├── README.md
12+
├── kustomization.yaml
13+
├── patches
14+
│ ├── grafana-cm.yaml
15+
│ └── kustomization.yaml
16+
├── python-app
17+
│ ├── Dockerfile
18+
│ ├── app.py
19+
│ ├── k8s
20+
│ │ ├── base
21+
│ │ │ ├── app-service.yaml
22+
│ │ │ ├── ingressgateway-istio.yaml
23+
│ │ │ ├── kustomization.yaml
24+
│ │ │ ├── v1
25+
│ │ │ │ └── app-deployment-v1.yaml
26+
│ │ │ ├── v2
27+
│ │ │ │ └── app-deployment-v2.yaml
28+
│ │ │ └── v3
29+
│ │ │ └── app-deployment-v3.yaml
30+
│ │ ├── destination-rule.yaml
31+
│ │ ├── kustomization.yaml
32+
│ │ ├── security
33+
│ │ │ ├── auth-policy.yaml
34+
│ │ │ ├── kustomization.yaml
35+
│ │ │ └── peer-authentication.yaml
36+
│ │ └── vs.yaml
37+
│ └── templates
38+
│ └── index.html
39+
└── tests
40+
└── h2load.sh
41+
```
42+
43+
- `app.py` - Main Flask application file.
44+
- `Dockerfile` - Docker image for the application.
45+
- `templates/index.html` - HTML template for the homepage.
46+
- `Makefile` - Automation scripts for tasks like starting Minikube, installing Istio, and deploying the app.
47+
- `k8s/` - Kubernetes manifests for deploying the application.
48+
- `tests/h2load.sh` - Script for performance testing.
49+
- `patches` - Patch `ConfigMap` to access grafana dashboard using istio `VirtualService`.
50+
51+
## Requirements
52+
53+
---
54+
55+
- [Python 3.11](https://www.python.org/downloads/release/python-3110/)
56+
- [Docker](https://www.docker.com/)
57+
- [Minikube](https://minikube.sigs.k8s.io/docs/)
58+
- [Istio](https://istio.io/)
59+
- [Kubernetes CLI](https://kubernetes.io/docs/reference/kubectl/) (`kubectl`)
60+
- [Istio CLI](https://istio.io/latest/docs/ops/diagnostic-tools/istioctl/) (`istioctl`)
61+
62+
## Installation and Usage
63+
64+
---
65+
66+
### 1. Start Minikube
67+
```bash
68+
make start-minikube
69+
```
70+
71+
### 2. Install Istio
72+
```bash
73+
make install-istio
74+
```
75+
76+
### 3. Build Docker Image (optional)
77+
78+
You can build the Docker image for the application using the provided Dockerfile. The Dockerfile is located in the `python-app` directory.
79+
```bash
80+
docker build -t istio-python-app:latest python-app/
81+
docker tag istio-python-app:latest <your-registry>/istio-python-app:latest
82+
docker push <your-registry>/istio-python-app:latest
83+
```
84+
85+
And then change the image name in the [deployments](./python-app/k8s/base) files located in `python-app/k8s/base/` (`v1`, `v2`, `v3` folders) to match your registry.
86+
87+
### 4. Deploy the Application to Kubernetes
88+
```bash
89+
make create-python-app
90+
```
91+
92+
### 5. Forward istio-ingressgateway port
93+
```bash
94+
kubectl port-forward -n istio-system service/istio-ingressgateway 8080:80
95+
```
96+
97+
98+
## Accessing the Application
99+
100+
---
101+
102+
After deployment, the application will be accessible via the Istio Ingress Gateway. To get access by URL add the following into the `/etc/hosts` file:
103+
104+
```text
105+
127.0.0.1 example.local
106+
```
107+
108+
Then, you can access the application using the following URL:
109+
110+
```text
111+
http://example.local:8080/app
112+
```
113+
114+
To access the grafana dashboard you can use the following URL:
115+
116+
```text
117+
http://example.local:8080/grafana
118+
```
119+
120+
To access the Kiali dashboard, you can use the following URL:
121+
122+
```text
123+
http://example.local:8080/kiali
124+
```
125+
126+
You can also access to the API endpoint using the following command:
127+
128+
```bash
129+
curl -H "Authorization: Bearer my-static-token-123" http://example.local:8080/app/api
130+
```
131+
132+
## Testing the application
133+
134+
---
135+
136+
To test the application, you can use the `h2load.sh` script located in the `tests` directory. This script uses `h2load` to perform load testing on the application.
137+
Use the following command to run the test:
138+
139+
```bash
140+
make test-python-app
141+
```
142+
143+
## Monitoring
144+
145+
---
146+
147+
- **[Prometheus](https://istio.io/latest/docs/ops/integrations/prometheus/)**: Application metrics.
148+
- **[Kiali](https://istio.io/latest/docs/ops/integrations/kiali/)**: Visualization of network traffic.

kustomization.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- python-app/k8s

patches/grafana-cm.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Source: grafana/templates/configmap.yaml
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: grafana
6+
namespace: istio-system
7+
labels:
8+
helm.sh/chart: grafana-8.6.3
9+
app.kubernetes.io/name: grafana
10+
app.kubernetes.io/instance: grafana
11+
app.kubernetes.io/version: "11.3.1"
12+
data:
13+
grafana.ini: |
14+
[analytics]
15+
check_for_updates = true
16+
[grafana_net]
17+
url = https://grafana.net
18+
[log]
19+
mode = console
20+
[paths]
21+
data = /var/lib/grafana/
22+
logs = /var/log/grafana
23+
plugins = /var/lib/grafana/plugins
24+
provisioning = /etc/grafana/provisioning
25+
[server]
26+
domain = ''
27+
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
28+
serve_from_sub_path = true
29+
datasources.yaml: |
30+
apiVersion: 1
31+
datasources:
32+
- access: proxy
33+
editable: true
34+
isDefault: true
35+
jsonData:
36+
timeInterval: 15s
37+
name: Prometheus
38+
orgId: 1
39+
type: prometheus
40+
url: http://prometheus:9090
41+
- access: proxy
42+
editable: true
43+
isDefault: false
44+
jsonData:
45+
timeInterval: 5s
46+
name: Loki
47+
orgId: 1
48+
type: loki
49+
url: http://loki:3100
50+
dashboardproviders.yaml: |
51+
apiVersion: 1
52+
providers:
53+
- disableDeletion: false
54+
folder: istio
55+
name: istio
56+
options:
57+
path: /var/lib/grafana/dashboards/istio
58+
orgId: 1
59+
type: file
60+
- disableDeletion: false
61+
folder: istio
62+
name: istio-services
63+
options:
64+
path: /var/lib/grafana/dashboards/istio-services
65+
orgId: 1
66+
type: file

patches/kiali-cm.yaml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
# Source: kiali-server/templates/configmap.yaml
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: kiali
7+
namespace: "istio-system"
8+
labels:
9+
helm.sh/chart: kiali-server-2.5.0
10+
app: kiali
11+
app.kubernetes.io/name: kiali
12+
app.kubernetes.io/instance: kiali
13+
version: "v2.5.0"
14+
app.kubernetes.io/version: "v2.5.0"
15+
app.kubernetes.io/part-of: "kiali"
16+
data:
17+
config.yaml: |
18+
additional_display_details:
19+
- annotation: kiali.io/api-spec
20+
icon_annotation: kiali.io/api-type
21+
title: API Documentation
22+
auth:
23+
openid: {}
24+
openshift:
25+
client_id_prefix: kiali
26+
strategy: anonymous
27+
clustering:
28+
autodetect_secrets:
29+
enabled: true
30+
label: kiali.io/multiCluster=true
31+
clusters: []
32+
deployment:
33+
additional_service_yaml: {}
34+
affinity:
35+
node: {}
36+
pod: {}
37+
pod_anti: {}
38+
cluster_wide_access: true
39+
configmap_annotations: {}
40+
custom_envs: []
41+
custom_secrets: []
42+
dns:
43+
config: {}
44+
policy: ""
45+
host_aliases: []
46+
hpa:
47+
api_version: autoscaling/v2
48+
spec: {}
49+
image_digest: ""
50+
image_name: quay.io/kiali/kiali
51+
image_pull_policy: IfNotPresent
52+
image_pull_secrets: []
53+
image_version: v2.5
54+
ingress:
55+
additional_labels: {}
56+
class_name: nginx
57+
override_yaml:
58+
metadata: {}
59+
ingress_enabled: false
60+
instance_name: kiali
61+
logger:
62+
log_format: text
63+
log_level: info
64+
sampler_rate: "1"
65+
time_field_format: 2006-01-02T15:04:05Z07:00
66+
namespace: istio-system
67+
node_selector: {}
68+
pod_annotations: {}
69+
pod_labels:
70+
sidecar.istio.io/inject: "false"
71+
priority_class_name: ""
72+
probes:
73+
liveness:
74+
initial_delay_seconds: 5
75+
period_seconds: 30
76+
readiness:
77+
initial_delay_seconds: 5
78+
period_seconds: 30
79+
startup:
80+
failure_threshold: 6
81+
initial_delay_seconds: 30
82+
period_seconds: 10
83+
remote_cluster_resources_only: false
84+
replicas: 1
85+
resources:
86+
limits:
87+
memory: 1Gi
88+
requests:
89+
cpu: 10m
90+
memory: 64Mi
91+
secret_name: kiali
92+
security_context: {}
93+
service_annotations: {}
94+
service_type: ""
95+
tolerations: []
96+
topology_spread_constraints: []
97+
version_label: v2.5.0
98+
view_only_mode: false
99+
external_services:
100+
custom_dashboards:
101+
enabled: true
102+
istio:
103+
root_namespace: istio-system
104+
tracing:
105+
enabled: true
106+
internal_url: "http://tracing.istio-system:16685/jaeger"
107+
use_grpc: true
108+
external_url: "http://localhost:16686"
109+
identity:
110+
cert_file: ""
111+
private_key_file: ""
112+
istio_namespace: istio-system
113+
kiali_feature_flags:
114+
disabled_features: []
115+
validations:
116+
ignore:
117+
- KIA1301
118+
login_token:
119+
signing_key: CHANGEME00000000
120+
server:
121+
observability:
122+
metrics:
123+
enabled: true
124+
port: 9090
125+
port: 20001
126+
web_root: /kiali
127+
...

patches/kustomization.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
namespace: istio-system
5+
6+
resources:
7+
- grafana-cm.yaml
8+
- kiali-cm.yaml

0 commit comments

Comments
 (0)