我在获取基本NetworkPolicy
资源来阻止 Azure Kubernetes 服务 (AKS) 实例上的所有入口流量时遇到了一些问题。AKS 设置有azure
网络插件(即 Azure CNI)。
我们的问题是,通过 VNet 对等本地网络,AKS 工作负载现在暴露给来自内部网络的不良行为者。所以我们有一个入口控制器,但想让它成为所有非系统工作负载的唯一入口点。
这是NetworkPolicy
资源:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: hello-node-network-policy
namespace: hello-namespace-2
spec:
podSelector: {}
policyTypes:
- Ingress
ingress: []
在不同命名空间中的 Pod 上,我仍然可以连接到 Service 端点和 Pod IP 地址(如 中所示kubectl get pods --output=wide --namespace=hello-namespace-2
)。在同一 VNet 中的 Azure VM 上,我也可以直接连接到 IP 地址。
Namespace、StatefulSet、Service、Ingress 和 NetworkPolicy 定义如下。
apiVersion: v1
kind: Namespace
metadata:
name: hello-namespace-2
labels:
ingress-allowed: "allowed"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
creationTimestamp: null
labels:
app: hello-node
name: hello-node
namespace: hello-namespace-2
spec:
serviceName: hello-node
replicas: 1
selector:
matchLabels:
app: hello-node
template:
metadata:
creationTimestamp: null
labels:
app: hello-node
spec:
containers:
- image: k8s.gcr.io/echoserver:1.4
name: echoserver
resources: {}
---
apiVersion: v1
kind: Service
metadata:
name: hello-node-service
namespace: hello-namespace-2
spec:
type: ClusterIP
selector:
app: hello-node
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: hello-node-ingress
namespace: hello-namespace-2
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- host: hello-namespace-2
http:
paths:
- path: /hello-node(/|$)(.*)
backend:
serviceName: hello-node-service
servicePort: 80
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: hello-node-network-policy
namespace: hello-namespace-2
spec:
podSelector: {}
policyTypes:
- Ingress
ingress: []
这就像没有安装网络控制器一样,我认为 Azure CNI 的azure
网络插件代表了它。我们是否必须明确安装像 Calico 这样的网络控制器?
非常感谢对此行为的任何见解。
谢谢!