我正在尝试设置网络策略以仅允许从 aws 经典负载均衡器到 Pod 的入站流量。没有其他东西可以与包含任何 pod 副本的 pod 通信。我已经配置了以下但它不起作用。有什么我想念的想法吗?一旦我应用它,负载均衡器上的健康检查就会失败。
apiVersion: apps/v1
kind: Deployment
metadata:
name: a-b-c1
labels:
app: a-b-c1
spec:
replicas: 1
selector:
matchLabels:
app: a-b-c1
template:
metadata:
labels:
app: a-b-c1
spec:
containers:
- name: a-b-c1
image: image:latest
ports:
- name: http-server1
containerPort: 80
resources:
requests:
cpu: 0.5
---
kind: Service
apiVersion: v1
metadata:
name: a-b-c-elb1
labels:
app: a-b-c1
name: a-b-c1-elb
annotations:
service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
service.beta.kubernetes.io/aws-load-balancer-additional-resource-tags: "environment=eks"
spec:
ports:
- port: 80
targetPort: http-server1
selector:
app: a-b-c1
type: LoadBalancer
loadBalancerSourceRanges:
- 10.0.0.0/8
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-from-elb
spec:
podSelector:
matchLabels:
app: a-b-c1
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
name: a-b-c1-elb