Kratika:
Hi! Scenario for example:
We need to create a network policy from namespace A to Namespace B where there is no pods available and no labels available for namespaces except default label like “http://kubernetes.io/metadata.name|kubernetes.io/metadata.name”, How do you achieve this?
Can any one please provide me the spec for the same as am stuck with this one?
Adeola Adefolaju:
I think you may need to label the namespaces. $ k label ns A project=test and $ k label ns B project=test
Kratika:
Thanks for the response @Adeola Adefolaju and @Marko Eremija
But how do you create network policy as network policy is asking for podSelector where there is no pod Exists
Marko Eremija:
IIRC, podSelector
can be an empty dictionary
Marko Eremija:
i.e. podSelector: {}
Adeola Adefolaju:
Try this:
Adeola Adefolaju:
But you must have created the namespaces and their labels before creating the netpol
Adeola Adefolaju:
@unnivkn could you help confirm please? Thank you.
Kratika:
@Adeola Adefolaju in the given spec I don’t see source namespace or any label for the same right?
Adeola Adefolaju:
yes because I created it before creating the yaml, sorry. $ k create ns a and $ k create ns b. Then label them: $ k label ns a project=test and $ k label ns b project=test
Adeola Adefolaju:
You can also confirm.
k get ns --show-labels
Kratika:
Spec:
podSelector: {}
namespaceSelector:
matchLabels:
project: test
policyTypes:
Do you mean to say policy will come just like above if we apply label as you suggested? @Adeola Adefolaju @unnivkn
unnivkn:
Hi @Kratika may I know from where you got this question… first of all, this question not looks a standard one to me… however, what ever the guys told above looks good to me… I always recommend to take the standard netpol template from the doc & modify it as per our requirement. fyI: https://kubernetes.io/docs/concepts/services-networking/network-policies/