This query is regarding Question no:2 in Mock-2, I have created same networkpo . . .

Kasim Shaik:
This query is regarding Question no:2 in Mock-2, I have created same networkpolicy but it fails when I validate it. only difference is policyTypes

kind: NetworkPolicy
apiVersion: <http://networking.k8s.io/v1|networking.k8s.io/v1>
metadata:
  name: allow-app1-app2
  namespace: apps-xyz
spec:
  podSelector:
    matchLabels:
      tier: backend
      role: db
  ingress:
  - from:
    - podSelector:
        matchLabels:
          name: app1
          tier: frontend
    - podSelector:
        matchLabels:
          name: app2
          tier: frontend


apiVersion: <http://networking.k8s.io/v1|networking.k8s.io/v1>
kind: NetworkPolicy
metadata:
  name: allow-app1-app2
  namespace: apps-xyz
spec:
  podSelector:
    matchLabels:
      role: db
      tier: backend
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
           app: name1
           tier: frontend
    - podSelector:
        matchLabels:
           app: name2
           tier: frontend

Tej_Singh_Rana:
Hello, @Kasim Shaik
So you haven’t specify policyTypes and validation failed?

Kasim Shaik:
my networkpolicy file has policyTypes section, but the answers given in /var/answer/ folder, it does not have policyTypes

Kasim Shaik:
First section of my snippet collected from answer2.md and second section written by me

Tej_Singh_Rana:
For ingress rule, we don’t need to specify policyTypes.
> If no policyTypes are specified on a NetworkPolicy then by default Ingress will always be set
Reference:-
https://kubernetes.io/docs/concepts/services-networking/network-policies/#networkpolicy-resource

Diegoflores:
Your matchlabels are wrong.
Should be name=app1 and name=app2 as in the a answer snippet

Kasim Shaik:
thanks @Diegoflores , I did not notice I gave wrong labels