Skip to content

Commit 428016d

Browse files
Document restrictions with port forwarding (#1264)
* Document restrictions with port forwarding Signed-off-by: Pablo Chacin <[email protected]> Co-authored-by: Heitor Tashiro Sergent <[email protected]>
1 parent f2c28bf commit 428016d

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ docs/sources/get-started/run-cloud-tests-from-the-CLI.md
55
docs/sources/get-started/run-your-first-tests.md
66
CONTRIBUTING_FILE_FORMAT.md
77
src/data/markdown/docs/40 xk6-disruptor/01 Get started/01 Welcome.md
8+
src/data/markdown/docs/40 xk6-disruptor/01 Get started/04 Expose Your Application.md
89
src/data/markdown/docs/40 xk6-disruptor/04 Examples/01 Inject Grpc faults into Service.md
910
src/data/markdown/docs/40 xk6-disruptor/04 Examples/02 Inject HTTP faults into Pod.md
1011
src/data/markdown/docs/05 Examples/02 Tutorials/01 Get started with k6/100 Test-for-functional-behavior.md
1112
src/data/markdown/docs/05 Examples/02 Tutorials/01 Get started with k6/200 Test for performance.md
1213
src/data/markdown/docs/05 Examples/02 Tutorials/01 Get started with k6/400 Reuse and re-run tests.md
14+

src/data/markdown/docs/40 xk6-disruptor/01 Get started/04 Expose Your Application.md

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,49 @@ To access your application from the test scripts, you must assign it an external
77
How you do this depends on the platform you use to deploy the application.
88
The following sections explain the different approaches.
99

10-
You can retrieve the external IP address and store in an environment variable (`SVC_IP` in this example) using the following command:
1110

12-
<CodeGroup labels={["Linux/MacOS", "Windows PowerShell"]}>
11+
## Using port-forwarding
1312

14-
```bash
15-
SVC_IP=$(kubectl -n <name space> get svc <service name> --output jsonpath='{.status.loadBalancer.ingress[0].ip}')
16-
```
13+
`kubectl`'s `port-forward` command allows accessing applications running in a Kubernetes cluster using a local port.
1714

18-
```Powershell
19-
$Env:SVC_IP=$(kubectl -n <name space> get svc <service name> --output jsonpath='{.status.loadBalancer.ingress[0].ip}')
15+
For example, the following command will make `my-service`'s port `80` accessible as `localhost:8080`:
16+
17+
```sh
18+
kubectl port-forward svc/my-service 8080:80
19+
Forwarding from 127.0.0.1:8080 -> 80
2020
```
2121

22-
</CodeGroup>
22+
### Limitations using port forwarding
23+
24+
To be able to inject faults, `xk6-disruptor` must [install an agent on each target](/javascript-api/xk6-disruptor/explanations/how-xk6-disruptor-works) that intercepts the requests and applies the desired disruptions. This process requires any existing connection to the targets to be redirected to the agent.
25+
26+
Due to a existing bug in `kubectl`, the process of installing the disruptor can potentially [break the port forwarding](https://github.com/grafana/xk6-disruptor/issues/254). Notice that this issue happens only if the faults are injected in the service that is exposed using port forward. If the faults are injected in another service not exposed by port-forwarding, there shouldn't be any issue.
27+
28+
Until this issue is solved in `kubectl`, tests using port forwarding to access a service should ensure the agent is installed in the targets before any traffic is sent by the test.
29+
30+
The simplest way to accomplish this is to ensure the scenario that executes the load (2) starts after the scenario that injects the faults (1):
31+
32+
```javascript
33+
scenarios: {
34+
disrupt: { (1)
35+
executor: 'shared-iterations',
36+
iterations: 1,
37+
vus: 1,
38+
exec: "disrupt",
39+
startTime: "0s",
40+
}
41+
load: { (2)
42+
executor: 'constant-arrival-rate',
43+
rate: 100,
44+
preAllocatedVUs: 10,
45+
maxVUs: 100,
46+
exec: "default",
47+
startTime: '20s', // give time for the agents to be installed
48+
duration: "30s",
49+
}
50+
}
51+
```
52+
2353

2454
## As a LoadBalancer service
2555

@@ -43,6 +73,20 @@ kubectl -n <name space> patch svc <service name> -p '{\"spec\": {\"type\": \"Loa
4373
</CodeGroup>
4474

4575

76+
You can retrieve the external IP address and store it in an environment variable (`SVC_IP` in this example) using the following command:
77+
78+
<CodeGroup labels={["Linux/MacOS", "Windows PowerShell"]}>
79+
80+
```bash
81+
SVC_IP=$(kubectl -n <name space> get svc <service name> --output jsonpath='{.status.loadBalancer.ingress[0].ip}')
82+
```
83+
84+
```Powershell
85+
$Env:SVC_IP=$(kubectl -n <name space> get svc <service name> --output jsonpath='{.status.loadBalancer.ingress[0].ip}')
86+
```
87+
88+
</CodeGroup>
89+
4690
### Configuring a LoadBalancer in Kind
4791

4892
[Kind](https://kind.sigs.k8s.io/) is a tool to run local Kubernetes clusters using a Docker container to emulate nodes.

0 commit comments

Comments
 (0)