Skip to content

Commit 3920b5e

Browse files
authored
Merge pull request #32813 from tengqm/networkpolicy-example
Move NetworkPolicy into examples
2 parents 19ad6cb + b51b1d6 commit 3920b5e

File tree

3 files changed

+38
-36
lines changed

3 files changed

+38
-36
lines changed

content/en/docs/concepts/services-networking/network-policies.md

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,7 @@ See the [NetworkPolicy](/docs/reference/generated/kubernetes-api/{{< param "vers
4545

4646
An example NetworkPolicy might look like this:
4747

48-
```yaml
49-
apiVersion: networking.k8s.io/v1
50-
kind: NetworkPolicy
51-
metadata:
52-
name: test-network-policy
53-
namespace: default
54-
spec:
55-
podSelector:
56-
matchLabels:
57-
role: db
58-
policyTypes:
59-
- Ingress
60-
- Egress
61-
ingress:
62-
- from:
63-
- ipBlock:
64-
cidr: 172.17.0.0/16
65-
except:
66-
- 172.17.1.0/24
67-
- namespaceSelector:
68-
matchLabels:
69-
project: myproject
70-
- podSelector:
71-
matchLabels:
72-
role: frontend
73-
ports:
74-
- protocol: TCP
75-
port: 6379
76-
egress:
77-
- to:
78-
- ipBlock:
79-
cidr: 10.0.0.0/24
80-
ports:
81-
- protocol: TCP
82-
port: 5978
83-
```
48+
{{< codenew file="service/networking/networkpolicy.yaml" >}}
8449

8550
{{< note >}}
8651
POSTing this to the API server for your cluster will have no effect unless your chosen networking solution supports network policy.

content/en/examples/examples_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ func TestExampleObjectSchemas(t *testing.T) {
647647
"service/networking": {
648648
"curlpod": {&apps.Deployment{}},
649649
"custom-dns": {&api.Pod{}},
650+
"default-ingressclass": {&networking.IngressClass{}},
650651
"dual-stack-default-svc": {&api.Service{}},
651652
"dual-stack-ipfamilies-ipv6": {&api.Service{}},
652653
"dual-stack-ipv6-svc": {&api.Service{}},
@@ -662,6 +663,7 @@ func TestExampleObjectSchemas(t *testing.T) {
662663
"name-virtual-host-ingress": {&networking.Ingress{}},
663664
"name-virtual-host-ingress-no-third-host": {&networking.Ingress{}},
664665
"namespaced-params": {&networking.IngressClass{}},
666+
"networkpolicy": {&networking.NetworkPolicy{}},
665667
"network-policy-allow-all-egress": {&networking.NetworkPolicy{}},
666668
"network-policy-allow-all-ingress": {&networking.NetworkPolicy{}},
667669
"network-policy-default-deny-egress": {&networking.NetworkPolicy{}},
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: NetworkPolicy
3+
metadata:
4+
name: test-network-policy
5+
namespace: default
6+
spec:
7+
podSelector:
8+
matchLabels:
9+
role: db
10+
policyTypes:
11+
- Ingress
12+
- Egress
13+
ingress:
14+
- from:
15+
- ipBlock:
16+
cidr: 172.17.0.0/16
17+
except:
18+
- 172.17.1.0/24
19+
- namespaceSelector:
20+
matchLabels:
21+
project: myproject
22+
- podSelector:
23+
matchLabels:
24+
role: frontend
25+
ports:
26+
- protocol: TCP
27+
port: 6379
28+
egress:
29+
- to:
30+
- ipBlock:
31+
cidr: 10.0.0.0/24
32+
ports:
33+
- protocol: TCP
34+
port: 5978
35+

0 commit comments

Comments
 (0)