For question on ingress: to create network policy, if question only mentions about creating policy for incoming traffic to a pod (ingress), does that mean we dont mention egress at all (so its blocked) or we assume its allowed and allow all egress?
Same for egress ques- if outgoing traffic from a pod has restrictions, should we assume incoming needs to be allowed?
Let me clear my question with these 2 questions that i came across: In Solution 2, all egress is allowed even if ques only mentions about ingress traffic.
I hope this makes sense. If not, i can try to ask in a different way.
Ques1.
egress ques
create a NetworkPolicy called np-backend in Namespace project-snake. It should allow the backend-* Pods only to:
connect to db1-* Pods on port 1111
connect to db2-* Pods on port 2222
soln:
spec:
podSelector: # pod to which policy is applied to
matchLabels:
app: backend
policyTypes:
- Egress # policy is only about Egress
egress:
- # first rule
to: # first condition “to”
- podSelector:
matchLabels:
app: db1
ports: # second condition “port”
- protocol: TCP
port: 1111
- # second rule
to: # first condition “to”
- podSelector:
matchLabels:
app: db2
ports: # second condition “port”
- protocol: TCP
port: 2222
Ques2:
Ingress Q
restricted pod so a network policy called cyan-np-cka28-trb has been created in the same namespace to apply some restrictions on this pod.
Expectation: This app should only be accessible from the cyan-white-cka28-trb1 pod.
Soln::
here solution added egress and allowed all. shouldn’t we ‘only’ include ingress rules in our policy? why even include egress here when question does not mention it?
(pls ignore mistakes in indentation as my ques is just focusing on what shd be included and what not)
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: default
podSelector:
matchLabels:
app: cyan-white-cka28-trb
- namespaceSelector:
- ports:
- port: 80
protocol: TCP
- port: 80
egress:
- ports:
- port: 80
protocol: TCP
to: - ipBlock:
cidr: 0.0.0.0/0
- port: 80