我在获取基本NetworkPolicy
资源以阻止Azure Kubernetes服务(AKS)实例上的所有入口流量时遇到麻烦。通过azure
网络插件(即Azure CNI)来设置AKS。
我们的问题是,随着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上,我仍然可以同时连接到服务端点和Pod IP地址(如kubectl get pods --output=wide --namespace=hello-namespace-2
中所示)。在同一VNet中的Azure VM上,我也可以直接连接到IP地址。
名称空间,StatefulSet,服务,入口和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这样的网络控制器?
任何对此行为的见解都将受到赞赏。
谢谢!
答案 0 :(得分:0)
1。 Network policy options in AKS
Azure提供了两种实施网络策略的方法。创建AKS群集时,请选择网络策略选项。创建群集后无法更改策略选项:
两个实现都使用Linux IPTables来执行指定的策略。策略被转换为允许和禁止IP对的集合。然后将这些对编程为IPTable过滤器规则。
2。 Differences between Azure and Calico policies and their capabilities
3。 Create an AKS cluster and enable network policy
要使用Azure网络策略,必须使用Azure CNI plug-in并定义自己的虚拟网络和子网。有关如何规划所需子网范围的更多详细信息,请参见configure advanced networking。
Calico网络策略可以与此相同的Azure CNI插件或Kubenet CNI插件一起使用。
4。。我个人从未使用过Azure CNI plug-in。始终使用
创建集群az aks create --resource-group <RG> --name <NAME> --network-policy calico
请查看示例:
a。 Tutorial: Calico Network Policies with Azure Kubernetes Service