Skip to content

Commit 3b599b8

Browse files
committed
Added MultiNetworkPolicy example
1 parent 5726af0 commit 3b599b8

1 file changed

Lines changed: 121 additions & 1 deletion

File tree

content/kubevirt/networking/index.md

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ EOF
212212
#### Create new project
213213

214214
```bash
215-
oc new project localnet-demo
215+
oc new-project localnet-demo
216216
```
217217

218218
#### Create net-attach-def
@@ -342,6 +342,126 @@ oc new project localnet-demo
342342
}
343343
```
344344

345+
## Example: Firewalling (Isolation)
346+
347+
### Enable MultiNetworkPolicy
348+
349+
<https://docs.redhat.com/en/documentation/openshift_container_platform/4.17/html/networking/multiple-networks#nw-multi-network-policy-enable_configuring-multi-network-policy>
350+
351+
```shell
352+
oc patch network.operator.openshift.io cluster \
353+
--type=merge \
354+
-p '{"spec":{"useMultiNetworkPolicy":true}}'
355+
```
356+
357+
Wait for the rollout / configuration
358+
359+
```shell
360+
$ oc get co/network
361+
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE MESSAGE
362+
network 4.18.17 True True False 3d17h DaemonSet "/openshift-ovn-kubernetes/ovnkube-node" update is rolling out (3 out of 6 updated)
363+
```
364+
365+
### Create two VM's with coe network connect
366+
367+
=== "OC"
368+
369+
```bash
370+
oc apply -f {{ page.canonical_url }}localnet-fedora-vm.yaml
371+
```
372+
373+
=== "localnet-fedora-vm.yaml"
374+
375+
```yaml
376+
--8<-- "content/kubevirt/networking/localnet-fedora-vm.yaml"
377+
```
378+
379+
### Let's apply some MultiNetworkPolicy
380+
381+
382+
=== "deny-by-default"
383+
384+
```yaml
385+
apiVersion: k8s.cni.cncf.io/v1beta1
386+
kind: MultiNetworkPolicy
387+
metadata:
388+
name: deny-by-default
389+
namespace: localnet-demo
390+
annotations:
391+
k8s.v1.cni.cncf.io/policy-for: coe
392+
spec:
393+
podSelector: {}
394+
policyTypes:
395+
- Ingress
396+
- Egress
397+
ingress: []
398+
egress: []
399+
```
400+
401+
=== "allow-dns-and-default-gateway"
402+
403+
```yaml
404+
apiVersion: k8s.cni.cncf.io/v1beta1
405+
kind: MultiNetworkPolicy
406+
metadata:
407+
name: allow-dns-and-default-gateway
408+
namespace: localnet-demo
409+
annotations:
410+
k8s.v1.cni.cncf.io/policy-for: coe
411+
spec:
412+
podSelector: {}
413+
policyTypes:
414+
- Egress
415+
egress:
416+
- to:
417+
- ipBlock:
418+
cidr: 10.32.96.1/32
419+
- ipBlock:
420+
cidr: 10.32.96.31/32
421+
- ipBlock:
422+
cidr: 10.32.111.254/32
423+
```
424+
425+
=== "allow-ingress"
426+
427+
```yaml
428+
apiVersion: k8s.cni.cncf.io/v1beta1
429+
kind: MultiNetworkPolicy
430+
metadata:
431+
name: allow-ingress
432+
namespace: localnet-demo
433+
annotations:
434+
k8s.v1.cni.cncf.io/policy-for: coe
435+
spec:
436+
podSelector: {}
437+
policyTypes:
438+
- Ingress
439+
ingress:
440+
- from:
441+
- ipBlock:
442+
cidr: 0.0.0.0/0
443+
```
444+
445+
=== "allow-egress"
446+
447+
```yaml
448+
apiVersion: k8s.cni.cncf.io/v1beta1
449+
kind: MultiNetworkPolicy
450+
metadata:
451+
name: allow-egress
452+
namespace: localnet-demo
453+
annotations:
454+
k8s.v1.cni.cncf.io/policy-for: coe
455+
spec:
456+
podSelector: {}
457+
policyTypes:
458+
- Egress
459+
egress:
460+
- to:
461+
- ipBlock:
462+
cidr: 0.0.0.0/0
463+
```
464+
345465
## Debugging purpose
346466

347467
### Create br1 via nmcli

0 commit comments

Comments
 (0)