I have been in DevOps related jobs for past 6 years dealing mainly with Kubernetes in AWS and on-premise as well. I spent quite a lot …
:date_long | 1 min Read
networkPolicy
# allow incoming traffic to pod "run: np-test-1" to port 80 from everywhere
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: ingress-to-nptest
namespace: default
spec:
podSelector:
matchLabels:
run: np-test-1
policyTypes:
- Ingress
ingress:
- from:
ports:
- protocol: TCP
port: 80
cat policy.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: internal-policy
namespace: default
spec:
podSelector:
matchLabels:
name: internal
policyTypes:
- Egress
egress:
# MySQL rule
- to:
- podSelector:
matchLabels:
name: mysql
ports:
- protocol: TCP
port: 3306
# Payroll rule
- to:
- podSelector:
matchLabels:
name: payroll
ports:
- protocol: TCP
port: 8080