You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/17-tips-and-tricks/docs/01-server-for-testing-network-policies.md
+66-1
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,9 @@
1
-
# Server for testing network policies
1
+
# Servers for testing network policies
2
2
3
3
Sometimes you may have a question that asks you to block ingress to a pod on all but some specific port. If a pod that meets the port requirement is not already present in the given namespace, then the issue here is "How do I create a pod onto which to attach the netpol that listens on the given port so I can test the policy?". You can't just run an nginx pod as that always listens on port 80. You could configure it otherwise, but that would require you to mount a configmap into the nginx pod containing an alternate config for nginx with the new port number. That's far too much hassle under exam conditions!
4
4
5
+
## Simple server
6
+
5
7
Fortunately, the default Python distribution contains a simple server that can have its port number configured from the command line, meaning you can run it imperatively. Let's say the network policy requires blocking all but port 9000. We can start a server test pod to listen on 9000 like so. If it's a different port, just put that port number instead of 9000.
6
8
7
9
```
@@ -26,5 +28,68 @@ You should get a response.
26
28
27
29
Now apply your network policy and test again.
28
30
31
+
## Slightly more advanced server
32
+
33
+
Perhaps you want to set up several pods and have each serve a specific message on a configurable port so you can tell them apart by their reponses. We can do that with a pod and a config map for each. The pod is the same each time - except for giving it a unique name and mounting the appropriate config map.
34
+
35
+
The following simulates a pod found in one of the Killer.sh network policy questions.
36
+
37
+
1. Create a config map which contains a shell script to run the server on a given port with a given message
0 commit comments