Reputation: 14800
The Problem
I've defined a kubernetes egress
rule from pod test-1
to a specific pod test-2
, but this rule blocks also blocks traffic from test-1
to test-2
:
test-1
and test-2
egress
traffic from test-1
to test-2
test-2
from test-1
by curl test-2
. But this call is blocked!Both selectors return the expected pod:
kubectl describe networkpolicies test-1-policy
kubectl get pod --selector app.kubernetes.io/name=test-1
kubectl get pod --selector app.kubernetes.io/name=test-2
When I remove the networkpolicy
the connect by curl test-2
works.
My Question: What did I miss?
Here's how to reproduce the problem
deployment.yaml
(see below)kubectl apply -f deployment.yaml
kubectl exec --stdin --tty $(kubectl get pod -l app.kubernetes.io/name=test-1 -o jsonpath="{.items[0].metadata.name}") -- /bin/bash
curl test-2
=> request is blockedkubectl delete networkpolicy test-1-policy
Here's the complete yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
labels:
app.kubernetes.io/name: test-1
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: test-1
template:
metadata:
labels:
app.kubernetes.io/name: test-1
spec:
containers:
- name: nginx
image: nginx
ports:
- name: http
containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
labels:
app.kubernetes.io/name: test-2
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: test-2
template:
metadata:
labels:
app.kubernetes.io/name: test-2
spec:
containers:
- name: nginx
image: nginx
ports:
- name: http
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: test-1
labels:
app.kubernetes.io/name: test-1
spec:
type: ClusterIP
ports:
- port: 80
targetPort: http
name: http
selector:
app.kubernetes.io/name: test-1
---
apiVersion: v1
kind: Service
metadata:
name: test-2
labels:
app.kubernetes.io/name: test-2
spec:
type: ClusterIP
ports:
- port: 80
targetPort: http
name: http
selector:
app.kubernetes.io/name: test-2
---
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: test-1-policy
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: test-1
policyTypes:
- Ingress
- Egress
ingress: []
egress:
- to:
- podSelector:
matchLabels:
app.kubernetes.io/name: test-2
ports:
- port: 80
protocol: TCP
Upvotes: 1
Views: 1045
Reputation: 14800
The dns egress
rule is missing:
When you add the egress
rules for port 53
everything works as expected:
egress:
- ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
Upvotes: 2