Skip to content

Commit d7be797

Browse files
authored
Merge pull request #28 from dinudaniel/feature/chaos-mesh-on-oke
[FEATURE] Add Chaos Mesh on OKE
2 parents 32e5cb0 + a95edb3 commit d7be797

22 files changed

Lines changed: 1479 additions & 0 deletions

chaos-mesh-on-oke-sample/README.md

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Deploy Chaos Mesh on OKE using Oracle Resource Manager
2+
3+
## Introduction
4+
5+
Oracle Kubernetes Engine (OKE) is the managed Kubernetes service on Oracle Cloud Infrastructure (OCI). It provides a managed Kubernetes control plane, worker node pools, and native integration with OCI networking and load balancing.
6+
7+
Chaos Mesh is an open source chaos engineering platform for Kubernetes. It lets you run controlled experiments against Kubernetes workloads and observe how applications behave under failures or resource pressure.
8+
9+
This Terraform stack deploys an OKE cluster and installs Chaos Mesh on it. The included basic usage example deploys `nginx`, configures an HPA, and runs a Chaos Mesh `StressChaos` memory experiment.
10+
11+
## Objectives
12+
13+
- Deploy an enhanced OKE cluster and the required OCI networking resources.
14+
- Install Chaos Mesh on OKE using Oracle Resource Manager (ORM).
15+
- Show a basic usage example with an `nginx` deployment, HPA, and `StressChaos` experiment.
16+
17+
## Prerequisites
18+
19+
- Access to an active OCI tenancy.
20+
- A compartment where the resources will be created.
21+
- Sufficient privileges to create and manage Resource Manager stacks/jobs, OKE, networking, compute, block volume, and load balancer resources. Example policies:
22+
23+
```text
24+
allow group <group-name> to manage orm-stacks in compartment <compartment-name>
25+
allow group <group-name> to manage orm-jobs in compartment <compartment-name>
26+
allow group <group-name> to manage cluster-family in compartment <compartment-name>
27+
```
28+
29+
- A machine with OCI CLI configured and `kubectl` installed.
30+
- SSH public key. The ORM stack schema requires this input.
31+
32+
## Task 1: Deploy Chaos Mesh on OKE using Oracle Resource Manager
33+
34+
1. Download the GitHub release archive as a `.zip` file.
35+
36+
2. Unzip the archive on your local machine.
37+
38+
3. In the OCI Console, create a Resource Manager stack:
39+
40+
- Open the navigation menu and go to **Developer Services** > **Resource Manager** > **Stacks**.
41+
- Click **Create stack**.
42+
- Select **My configuration**.
43+
- In the **My configuration** section, select **Folder**.
44+
- Upload the directory from the unzipped archive.
45+
- Give the stack a meaningful name, for example `chaos-mesh-on-oke`.
46+
- Choose the compartment where the stack metadata should be stored.
47+
- Click **Next**.
48+
49+
4. Configure stack variables:
50+
51+
- Choose the compartment where the OKE and networking resources will be created.
52+
- Select the Kubernetes version.
53+
- Provide your SSH public key.
54+
- Keep **Enable Metrics Server** and **Enable cert-manager** enabled. They are required for the HPA example.
55+
- Choose the Chaos Mesh dashboard service type. `ClusterIP` is recommended.
56+
- Click **Next**.
57+
58+
5. Review the stack configuration.
59+
60+
6. Select **Run apply** and click **Create**.
61+
62+
7. Wait for the apply job to finish. The stack creates:
63+
64+
- OCI networking resources: VCN, subnets, gateways, route/security resources, and network security groups.
65+
- An enhanced OKE cluster named `chaosmesh`.
66+
- A 3-node OKE node pool named `chaosmesh-pool`.
67+
- OKE add-ons: cert-manager and Metrics Server.
68+
- A Kubernetes namespace named `chaos-mesh`.
69+
- Chaos Mesh resources, via helm, installed in `chaos-mesh` namespace.
70+
71+
## Task 2: Access the OKE cluster
72+
73+
1. In the OCI Console, open **Developer Services** > **Kubernetes Clusters (OKE)**.
74+
75+
2. Select the cluster named `chaosmesh`.
76+
77+
3. Click **Actions** drop-down menu and then click **Access Cluster**.
78+
79+
4. Copy the OCI CLI command shown in the console.
80+
81+
5. Paste and run the command in a shell on a machine where OCI CLI and kubectl are configured.
82+
83+
6. Confirm that `kubectl` can access the cluster:
84+
85+
```bash
86+
kubectl get nodes
87+
```
88+
89+
## Task 3: Access the Chaos Mesh web interface
90+
91+
1. In the same shell, start port forwarding and leave this command running:
92+
93+
```bash
94+
kubectl port-forward -n chaos-mesh svc/chaos-dashboard 2333:2333
95+
```
96+
97+
2. Open the Chaos Mesh dashboard in a browser:
98+
99+
```text
100+
http://localhost:2333
101+
```
102+
103+
3. In another shell, generate a login token:
104+
105+
```bash
106+
kubectl create token chaos-dashboard -n chaos-mesh
107+
```
108+
109+
4. In the web interface, give the token a name, for example `chaos`, and paste the token value generated above. Then click **Submit**
110+
111+
## Task 4: Run a basic usage example with nginx, HPA, and StressChaos
112+
113+
The example uses the Kubernetes manifests included in **chaos-mesh-on-oke-sample** directory:
114+
115+
- `deployment.yaml` deploys `nginx`.
116+
- `hpa.yaml` creates the HPA. This is the Horizontal Pod Autoscaler (HPA) manifest.
117+
- `stresschaos.yaml` creates the Chaos Mesh memory stress experiment.
118+
119+
1. Open a new shell and change to the Terraform directory from the unzipped archive:
120+
121+
```bash
122+
cd <unzipped-archive>
123+
```
124+
125+
2. Create the `nginx` deployment:
126+
127+
```bash
128+
kubectl apply -f deployment.yaml
129+
kubectl rollout status deployment/nginx -n default
130+
kubectl get pods -n default -l app=nginx
131+
```
132+
133+
3. Configure the HPA:
134+
135+
```bash
136+
kubectl apply -f hpa.yaml
137+
kubectl get hpa nginx-hpa -n default
138+
```
139+
140+
4. Create the Chaos Mesh stress experiment:
141+
142+
```bash
143+
kubectl apply -f stresschaos.yaml
144+
kubectl get stresschaos nginx-mem-1 -n default
145+
```
146+
147+
5. Observe the deployment while the experiment runs:
148+
149+
```bash
150+
kubectl get deployment nginx -n default -w
151+
```
152+
153+
6. In another shell, observe the HPA:
154+
155+
```bash
156+
kubectl get hpa nginx-hpa -n default -w
157+
```
158+
159+
7. Optional: watch the nginx pods directly:
160+
161+
```bash
162+
kubectl get pods -n default -l app=nginx -w
163+
```
164+
165+
8. Expected behavior:
166+
167+
- Chaos Mesh injects memory stress into the `nginx` pod for the duration defined in `stresschaos.yaml`.
168+
- The HPA detects increased memory consumption.
169+
- The number of `nginx` pods increases.
170+
- After the experiment ends and the HPA stabilization period passes, the deployment scales down again.
171+
172+
## Task 5: Clean up
173+
174+
1. Delete the Chaos Mesh stress experiment:
175+
176+
```bash
177+
kubectl delete -f stresschaos.yaml --ignore-not-found=true
178+
```
179+
180+
2. Delete the HPA:
181+
182+
```bash
183+
kubectl delete -f hpa.yaml --ignore-not-found=true
184+
```
185+
186+
3. Delete the `nginx` deployment:
187+
188+
```bash
189+
kubectl delete -f deployment.yaml --ignore-not-found=true
190+
```
191+
192+
4. Stop the Chaos Mesh dashboard port-forward command with `Ctrl+C`.
193+
194+
5. Destroy the OCI resources created by the Terraform stack:
195+
196+
- Go to **Developer Services** > **Resource Manager** > **Stacks**.
197+
- Select the stack you created.
198+
- Click **Destroy**.
199+
- Review the destroy job and confirm.
200+
201+
6. Wait for the destroy job to complete successfully.
202+

chaos-mesh-on-oke-sample/addons.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
2+
# The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
resource "oci_containerengine_addon" "metrics_server" {
5+
count = var.enable_metrics_server ? 1 : 0
6+
cluster_id = oci_containerengine_cluster.chaosmesh.id
7+
addon_name = "KubernetesMetricsServer"
8+
remove_addon_resources_on_delete = true
9+
10+
depends_on = [oci_containerengine_node_pool.chaosmesh-pool, oci_containerengine_addon.cert_manager]
11+
}
12+
13+
resource "oci_containerengine_addon" "cert_manager" {
14+
count = var.enable_cert_manager ? 1 : 0
15+
cluster_id = oci_containerengine_cluster.chaosmesh.id
16+
addon_name = "CertManager"
17+
remove_addon_resources_on_delete = true
18+
19+
depends_on = [oci_containerengine_node_pool.chaosmesh-pool]
20+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
4+
# The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
6+
mkdir -p /etc/crio/crio.conf.d
7+
echo "[crio]" > /etc/crio/crio.conf.d/11-default.conf
8+
echo " [crio.image]" >> /etc/crio/crio.conf.d/11-default.conf
9+
echo " short_name_mode=\"disabled\"" >> /etc/crio/crio.conf.d/11-default.conf
10+
curl --fail -H "Authorization: Bearer Oracle" -L0 http://169.254.169.254/opc/v2/instance/metadata/oke_init_script | base64 --decode >/var/run/oke-init.sh
11+
sudo bash /var/run/oke-init.sh
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
2+
# The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
apiVersion: apps/v1
5+
kind: Deployment
6+
metadata:
7+
name: nginx
8+
namespace: default
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
app: nginx
14+
template:
15+
metadata:
16+
labels:
17+
app: nginx
18+
spec:
19+
containers:
20+
- name: nginx
21+
image: docker.io/nginx
22+
ports:
23+
- containerPort: 80

chaos-mesh-on-oke-sample/hpa.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
2+
# The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
apiVersion: autoscaling/v2
5+
kind: HorizontalPodAutoscaler
6+
metadata:
7+
name: nginx-hpa
8+
namespace: default
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: nginx
14+
minReplicas: 1
15+
maxReplicas: 10
16+
metrics:
17+
- type: Resource
18+
resource:
19+
name: memory
20+
target:
21+
type: AverageValue
22+
averageValue: 100Mi

0 commit comments

Comments
 (0)