@@ -33,7 +33,7 @@ The above list is sorted alphabetically by product name, not by recommendation o
33
33
To see how Kubernetes network policy works, start off by creating an ` nginx ` deployment.
34
34
35
35
``` console
36
- kubectl run nginx --image=nginx --replicas=2
36
+ kubectl create deployment nginx --image=nginx
37
37
```
38
38
``` none
39
39
deployment.apps/nginx created
@@ -62,7 +62,6 @@ service/nginx 10.100.0.16 <none> 80/TCP 33s
62
62
63
63
NAME READY STATUS RESTARTS AGE
64
64
pod/nginx-701339712-e0qfq 1/1 Running 0 35s
65
- pod/nginx-701339712-o00ef 1/1 Running 0 35s
66
65
```
67
66
68
67
## Test the service by accessing it from another pod
@@ -72,7 +71,7 @@ You should be able to access the new `nginx` service from other pods. To test, a
72
71
Start a busybox container, and use ` wget ` on the ` nginx ` service:
73
72
74
73
``` console
75
- kubectl run busybox --rm -ti --image=busybox /bin/sh
74
+ kubectl run --generator=run-pod/v1 busybox --rm -ti --image=busybox -- /bin/sh
76
75
```
77
76
78
77
``` console
@@ -97,14 +96,21 @@ metadata:
97
96
spec :
98
97
podSelector :
99
98
matchLabels :
100
- run : nginx
99
+ app : nginx
101
100
ingress :
102
101
- from :
103
102
- podSelector :
104
103
matchLabels :
105
104
access : " true"
106
105
` ` `
107
106
107
+ {{< note >}}
108
+
109
+ In the case, the label ` app=nginx` is automatically added.
110
+
111
+ {{< /note >}}
112
+
113
+
108
114
# # Assign the policy to the service
109
115
110
116
Use kubectl to create a NetworkPolicy from the above nginx-policy.yaml file :
@@ -121,7 +127,7 @@ networkpolicy.networking.k8s.io/access-nginx created
121
127
If we attempt to access the nginx Service from a pod without the correct labels, the request will now time out :
122
128
123
129
` ` ` console
124
- kubectl run busybox --rm -ti --image=busybox /bin/sh
130
+ kubectl run --generator=run-pod/v1 busybox --rm -ti --image=busybox -- /bin/sh
125
131
` ` `
126
132
127
133
` ` ` console
@@ -140,7 +146,7 @@ wget: download timed out
140
146
Create a pod with the correct labels, and you'll see that the request is allowed :
141
147
142
148
` ` ` console
143
- kubectl run busybox --rm -ti --labels="access=true" --image=busybox /bin/sh
149
+ kubectl run --generator=run-pod/v1 busybox --rm -ti --labels="access=true" --image=busybox -- /bin/sh
144
150
` ` `
145
151
146
152
` ` ` console
0 commit comments