S&N Network Policies Flashcards
How is the network flow configured by default in Kubernetes, about what pod can communicate with what other pod?
- All Allow
- every pod can communicate with each other pod in the same cluster
What do network policies enable
Allow you to specify, what pod can communicate with what other pod
- for instance if an application pod is only allowed to communicate with a database via api service but not directly
What is a Network policy in Kubernetes?
Another object in kubernetes namespace.
- linked to pods
- define rules within
- like for a db pod: only allow ingress traffic from the api pod on port 3306
- blocks all other traffic
How do we link Network Policies to pods?
Using labels and selectors
How do you specify a Network policy?
apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: db-policy spec: podSelector: matchLabels: role: db policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: name: api-pod ports: - protocol: TCP port: 3306
What happens when inside the network policy definition there are no policyTypes defined?
- no restriction on data traffic
- even if ingress or egress for connected pods are defined
What solutions support network policies?
- calico
- romana
- weave-net
BUT NOT
- Flannel
When you define Network policy and ingress/egress restrictions, how are responses handled? How do they need to be considered?
Responses are always included in declared allowances.
When ingress traffic is allowed, responses to requests are also allowed.
Only the direction where the traffic goes needs to be considered in policyTypes
How can we restrict what namespaces are allowed by the network policy?
ingress: - from: - podSelector: matchLabels: name: api-pod namespaceSelector: matchLabels: name: prod ports: - protocol: TCP port: 3306
What happens if you only use a namespaceSelector inside a Network Policy definition?
- only pods inside the namespace are allowed to communicate with the pod
- other namespaces are not allowed
How can we allow connections to servers not inside the cluster, like a backup server, that we know the ip address of?
ingress: - from: - ipBlock: cidr: 192.168.5.10/32
What is special about the -from section of a network policy definition file?
Contains rules that are to be applied.
A rule starts with ‘-‘. Allowed traffic needs to adhere to all criteria within at least one rule
How do you define a egress network policy?
spec: podSelector: matchLabels: role: db policyTypes: - egress egress: - to: - ipBlock: cidr: 192.168.4.10/32 ports: - protocol: TCP port: 80