Error with documentation ?? NetworkPolicy?

I walked through the code in a 3 node K8 cluster and doesn’t seem like I am able to block the flow of traffic using networkpolicy on a deployment pod.

Here is the the output from the exercise.

[email protected]:~$ kubectl get deployment,svc,networkpolicy
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   X.X.X.X    <none>        443/TCP   20d
[email protected]:~$
[email protected]:~$
[email protected]:~$ kubectl create deployment nginx --image=nginx
deployment.apps/nginx created
[email protected]:~$ kubectl expose deployment nginx --port=80
service/nginx exposed
[email protected]:~$ kubectl run busybox --rm -ti --image=busybox -- /bin/sh
If you don't see a command prompt, try pressing enter.
/ # wget --spider --timeout=1 nginx
Connecting to nginx (X.X.X.X:80)
remote file exists
/ # exit
Session ended, resume using 'kubectl attach busybox -c busybox -i -t' command when the pod is running
pod "busybox" deleted
[email protected]:~$
[email protected]:~$
[email protected]:~$ vi network-policy.yaml
[email protected]:~$ cat network-policy.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: access-nginx
spec:
  podSelector:
    matchLabels:
      app: nginx
  ingress:
  - from:
    - podSelector:
        matchLabels:
          access: "true"

[email protected]:~$
[email protected]:~$
[email protected]:~$ kubectl apply -f network-policy.yaml
networkpolicy.networking.k8s.io/access-nginx created
[email protected]:~$
[email protected]:~$
[email protected]:~$ kubectl run busybox --rm -ti --image=busybox -- /bin/sh
If you don't see a command prompt, try pressing enter.
/ # wget --spider --timeout=1 nginx
Connecting to nginx (10.100.97.229:80)
remote file exists. <<<<  THIS SHOULD NOT WORK 

I followed all the steps as is, but it seems like I am unable to block the traffic even with networkpolicy defined.

Can someone please help and let me know if I am doing something dumb here?

Source: Docker Questions

LEAVE A COMMENT