Hello,
I have a question about this question in the network policy Lab : “Learn-By-Doing Kubernetes Network Policies”
in the section : Namespace-Based Isolation with Kubernetes Network Policies i have create 3 network policies that will :
- Deploy an
deny-all-ingress
that blacklists all traffic in the cluster. - Allow ingress traffic from frontend pods to middleware
- Allow ingress traffic from middleware to the mysql pod
Here is my networkpolicies :
controlplane ~ ✖ ls
deny-all-traffic.yaml frontend-to-middleware.yaml middleware-to-mysql.yaml
controlplane ~ ➜ cat deny-all-traffic.yaml
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-all-ingress
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
ingress: []
controlplane ~ ➜ cat frontend-to-middleware.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: frontend-to-middleware
namespace: production
spec:
podSelector:
matchLabels:
app: middleware
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: production
- podSelector:
matchLabels:
app: frontend
ports:
- protocol: TCP
port: 80
controlplane ~ ➜ cat middleware-to-mysql.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: middleware-to-mysql
namespace: production
spec:
podSelector:
matchLabels:
app: mysql
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: production
- podSelector:
matchLabels:
app: middleware
ports:
- protocol: TCP
port: 3306
In the check button and this is right , he is telling me that the traffic is allowed between frontend pods and mysql svc and i have already deployed an deny policy
I hope that you will tell me if i’am wrong in that or i’m missing something
Thank you