Skip to content

Commit c212767

Browse files
committed
replace depercated commands with new commands
1 parent db64ecd commit c212767

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

content/en/docs/tasks/administer-cluster/declare-network-policy.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The above list is sorted alphabetically by product name, not by recommendation o
3333
To see how Kubernetes network policy works, start off by creating an `nginx` deployment.
3434

3535
```console
36-
kubectl run nginx --image=nginx --replicas=2
36+
kubectl create deployment nginx --image=nginx
3737
```
3838
```none
3939
deployment.apps/nginx created
@@ -62,7 +62,6 @@ service/nginx 10.100.0.16 <none> 80/TCP 33s
6262
6363
NAME READY STATUS RESTARTS AGE
6464
pod/nginx-701339712-e0qfq 1/1 Running 0 35s
65-
pod/nginx-701339712-o00ef 1/1 Running 0 35s
6665
```
6766

6867
## 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
7271
Start a busybox container, and use `wget` on the `nginx` service:
7372

7473
```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
7675
```
7776

7877
```console
@@ -97,14 +96,21 @@ metadata:
9796
spec:
9897
podSelector:
9998
matchLabels:
100-
run: nginx
99+
app: nginx
101100
ingress:
102101
- from:
103102
- podSelector:
104103
matchLabels:
105104
access: "true"
106105
```
107106
107+
{{< note >}}
108+
109+
In the case, the label `app=nginx` is automatically added.
110+
111+
{{< /note >}}
112+
113+
108114
## Assign the policy to the service
109115

110116
Use kubectl to create a NetworkPolicy from the above nginx-policy.yaml file:
@@ -121,7 +127,7 @@ networkpolicy.networking.k8s.io/access-nginx created
121127
If we attempt to access the nginx Service from a pod without the correct labels, the request will now time out:
122128

123129
```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
125131
```
126132

127133
```console
@@ -140,7 +146,7 @@ wget: download timed out
140146
Create a pod with the correct labels, and you'll see that the request is allowed:
141147

142148
```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
144150
```
145151

146152
```console

0 commit comments

Comments
 (0)