You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/aks/operator-best-practices-network.md
+52-53Lines changed: 52 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,118 +1,116 @@
1
1
---
2
-
title: Best practices for network resources
2
+
title: Best practices for network resources in Azure Kubernetes Service (AKS)
3
3
titleSuffix: Azure Kubernetes Service
4
-
description: Learn the cluster operator best practices for virtual network resources and connectivity in Azure Kubernetes Service (AKS)
4
+
description: Learn the cluster operator best practices for virtual network resources and connectivity in Azure Kubernetes Service (AKS).
5
5
ms.topic: conceptual
6
-
ms.date: 03/10/2021
6
+
ms.date: 06/22/2023
7
7
8
8
---
9
9
10
10
# Best practices for network connectivity and security in Azure Kubernetes Service (AKS)
11
11
12
-
As you create and manage clusters in Azure Kubernetes Service (AKS), you provide network connectivity for your nodes and applications. These network resources include IP address ranges, load balancers, and ingress controllers. To maintain a high quality of service for your applications, you need to strategize and configure these resources.
12
+
As you create and manage clusters in Azure Kubernetes Service (AKS), you provide network connectivity for your nodes and applications. These network resources include IP address ranges, load balancers, and ingress controllers.
13
13
14
14
This best practices article focuses on network connectivity and security for cluster operators. In this article, you learn how to:
15
15
16
16
> [!div class="checklist"]
17
+
>
17
18
> * Compare the kubenet and Azure Container Networking Interface (CNI) network modes in AKS.
18
19
> * Plan for required IP addressing and connectivity.
19
20
> * Distribute traffic using load balancers, ingress controllers, or a web application firewall (WAF).
20
21
> * Securely connect to cluster nodes.
21
22
22
23
## Choose the appropriate network model
23
24
24
-
> **Best practice guidance**
25
-
>
25
+
> **Best practice guidance**
26
+
>
26
27
> Use Azure CNI networking in AKS for integration with existing virtual networks or on-premises networks. This network model allows greater separation of resources and controls in an enterprise environment.
27
28
28
29
Virtual networks provide the basic connectivity for AKS nodes and customers to access your applications. There are two different ways to deploy AKS clusters into virtual networks:
29
30
30
-
***Azure CNI networking**
31
-
32
-
Deploys into a virtual network and uses the [Azure CNI][cni-networking] Kubernetes plugin. Pods receive individual IPs that can route to other network services or on-premises resources.
33
-
***Kubenet networking**
31
+
***Azure CNI networking**: Deploys into a virtual network and uses the [Azure CNI][cni-networking] Kubernetes plugin. Pods receive individual IPs that can route to other network services or on-premises resources.
32
+
***Kubenet networking**: Azure manages the virtual network resources as the cluster is deployed and uses the [kubenet][kubenet] Kubernetes plugin.
34
33
35
-
Azure manages the virtual network resources as the cluster is deployed and uses the [kubenet][kubenet] Kubernetes plugin.
36
-
37
-
38
-
For production deployments, both kubenet and Azure CNI are valid options.
34
+
Azure CNI and kubenet are both valid options for production deployments.
39
35
40
36
### CNI Networking
41
37
42
-
Azure CNI is a vendor-neutral protocol that lets the container runtime make requests to a network provider. It assigns IP addresses to pods and nodes, and provides IP address management (IPAM) features as you connect to existing Azure virtual networks. Each node and pod resource receives an IP address in the Azure virtual network - no need for extra routing to communicate with other resources or services.
38
+
Azure CNI is a vendor-neutral protocol that lets the container runtime make requests to a network provider. It assigns IP addresses to pods and nodes, and provides IP address management (IPAM) features as you connect to existing Azure virtual networks. Each node and pod resource receives an IP address in the Azure virtual network. There's no need for extra routing to communicate with other resources or services.
43
39
44
40

45
41
46
42
Notably, Azure CNI networking for production allows for separation of control and management of resources. From a security perspective, you often want different teams to manage and secure those resources. With Azure CNI networking, you connect to existing Azure resources, on-premises resources, or other services directly via IP addresses assigned to each pod.
47
43
48
-
When you use Azure CNI networking, the virtual network resource is in a separate resource group to the AKS cluster. Delegate permissions for the AKS cluster identity to access and manage these resources. The cluster identity used by the AKS cluster must have at least [Network Contributor](../role-based-access-control/built-in-roles.md#network-contributor) permissions on the subnet within your virtual network.
44
+
When you use Azure CNI networking, the virtual network resource is in a separate resource group to the AKS cluster. Delegate permissions for the AKS cluster identity to access and manage these resources. The cluster identity used by the AKS cluster must have at least [Network Contributor](../role-based-access-control/built-in-roles.md#network-contributor) permissions on the subnet within your virtual network.
49
45
50
46
If you wish to define a [custom role](../role-based-access-control/custom-roles.md) instead of using the built-in Network Contributor role, the following permissions are required:
By default, AKS uses a managed identity for its cluster identity. However, you are able to use a service principal instead. For more information about:
55
-
* AKS service principal delegation, see [Delegate access to other Azure resources][sp-delegation].
56
-
* Managed identities, see [Use managed identities](use-managed-identity.md).
By default, AKS uses a managed identity for its cluster identity. However, you can use a service principal instead.
52
+
53
+
* For more information about AKS service principal delegation, see [Delegate access to other Azure resources][sp-delegation].
54
+
* For more information about managed identities, see [Use managed identities](use-managed-identity.md).
57
55
58
-
As each node and pod receives its own IP address, plan out the address ranges for the AKS subnets. Keep in mind:
59
-
* The subnet must be large enough to provide IP addresses for every node, pods, and network resource that you deploy.
60
-
* With both kubenet and Azure CNI networking, each node running has default limits to the number of pods.
61
-
* Avoid using IP address ranges that overlap with existing network resources.
62
-
* Necessary to allow connectivity to on-premises or peered networks in Azure.
63
-
* To handle scale out events or cluster upgrades, you need extra IP addresses available in the assigned subnet.
64
-
* This extra address space is especially important if you use Windows Server containers, as those node pools require an upgrade to apply the latest security patches. For more information on Windows Server nodes, see [Upgrade a node pool in AKS][nodepool-upgrade].
56
+
As each node and pod receives its own IP address, plan out the address ranges for the AKS subnets. Keep the following criteria in mind:
57
+
58
+
* The subnet must be large enough to provide IP addresses for every node, pod, and network resource you deploy.
59
+
* With both kubenet and Azure CNI networking, each running node has default limits to the number of pods.
60
+
* Avoid using IP address ranges that overlap with existing network resources.
61
+
* It's necessary to allow connectivity to on-premises or peered networks in Azure.
62
+
* To handle scale out events or cluster upgrades, you need extra IP addresses available in the assigned subnet.
63
+
* This extra address space is especially important if you use Windows Server containers, as those node pools require an upgrade to apply the latest security patches. For more information on Windows Server nodes, see [Upgrade a node pool in AKS][nodepool-upgrade].
65
64
66
65
To calculate the IP address required, see [Configure Azure CNI networking in AKS][advanced-networking].
67
66
68
-
When creating a cluster with Azure CNI networking, you specify other address ranges for the cluster, such as the Docker bridge address, DNS service IP, and service address range. In general, make sure these address ranges:
69
-
* Don't overlap each other.
70
-
* Don't overlap with any networks associated with the cluster, including any virtual networks, subnets, on-premises and peered networks.
67
+
When creating a cluster with Azure CNI networking, you specify other address ranges for the cluster, such as the Docker bridge address, DNS service IP, and service address range. In general, make sure these address ranges don't overlap each other or any networks associated with the cluster, including any virtual networks, subnets, on-premises and peered networks.
71
68
72
69
For the specific details around limits and sizing for these address ranges, see [Configure Azure CNI networking in AKS][advanced-networking].
73
70
74
71
### Kubenet networking
75
72
76
-
Although kubenet doesn't require you to set up the virtual networks before the cluster is deployed, there are disadvantages to waiting:
73
+
Although kubenet doesn't require you to set up the virtual networks before deploying the cluster, there are disadvantages to waiting, such as:
77
74
78
75
* Since nodes and pods are placed on different IP subnets, User Defined Routing (UDR) and IP forwarding routes traffic between pods and nodes. This extra routing may reduce network performance.
79
76
* Connections to existing on-premises networks or peering to other Azure virtual networks can be complex.
80
77
81
-
Since you don't create the virtual network and subnets separately from the AKS cluster, Kubenet is ideal for:
82
-
* Small development or test workloads.
78
+
Since you don't create the virtual network and subnets separately from the AKS cluster, Kubenet is ideal for the following scenarios:
79
+
80
+
* Small development or test workloads.
83
81
* Simple websites with low traffic.
84
82
* Lifting and shifting workloads into containers.
85
83
86
84
For most production deployments, you should plan for and use Azure CNI networking.
87
85
88
-
You can also [configure your own IP address ranges and virtual networks using kubenet][aks-configure-kubenet-networking]. Like Azure CNI networking, these address ranges shouldn't overlap each other and shouldn't overlap with any networks associated with the cluster (virtual networks, subnets, on-premises and peered networks).
86
+
You can also [configure your own IP address ranges and virtual networks using kubenet][aks-configure-kubenet-networking]. Like Azure CNI networking, these address ranges shouldn't overlap each other or any networks associated with the cluster (virtual networks, subnets, on-premises and peered networks).
89
87
90
88
For the specific details around limits and sizing for these address ranges, see [Use kubenet networking with your own IP address ranges in AKS][aks-configure-kubenet-networking].
91
89
92
90
## Distribute ingress traffic
93
91
94
-
> **Best practice guidance**
95
-
>
92
+
> **Best practice guidance**
93
+
>
96
94
> To distribute HTTP or HTTPS traffic to your applications, use ingress resources and controllers. Compared to an Azure load balancer, ingress controllers provide extra features and can be managed as native Kubernetes resources.
97
95
98
-
While an Azure load balancer can distribute customer traffic to applications in your AKS cluster, it's limited in understanding that traffic. A load balancer resource works at layer 4, and distributes traffic based on protocol or ports.
96
+
While an Azure load balancer can distribute customer traffic to applications in your AKS cluster, it's limited in understanding that traffic. A load balancer resource works at *layer 4* and distributes traffic based on protocol or ports.
99
97
100
-
Most web applications using HTTP or HTTPS should use Kubernetes ingress resources and controllers, which work at layer 7. Ingress can distribute traffic based on the URL of the application and handle TLS/SSL termination. Ingress also reduces the number of IP addresses you expose and map.
98
+
Most web applications using HTTP or HTTPS should use Kubernetes ingress resources and controllers, which work at *layer 7*. Ingress can distribute traffic based on the URL of the application and handle TLS/SSL termination. Ingress also reduces the number of IP addresses you expose and map.
101
99
102
100
With a load balancer, each application typically needs a public IP address assigned and mapped to the service in the AKS cluster. With an ingress resource, a single IP address can distribute traffic to multiple applications.
103
101
104
102

105
103
106
-
There are two components for ingress:
104
+
There are two components for ingress:
107
105
108
-
* An ingress *resource*
109
-
* An ingress *controller*
106
+
1. An ingress *resource*
107
+
2. An ingress *controller*
110
108
111
109
### Ingress resource
112
110
113
-
The *ingress resource* is a YAML manifest of `kind: Ingress`. It defines the host, certificates, and rules to route traffic to services running in your AKS cluster.
111
+
The *ingress resource* is a YAML manifest of `kind: Ingress`. It defines the host, certificates, and rules to route traffic to services running in your AKS cluster.
114
112
115
-
The following example YAML manifest would distribute traffic for *myapp.com* to one of two services, *blogservice* or *storeservice*. The customer is directed to one service or the other based on the URL they access.
113
+
The following example YAML manifest distributes traffic for *myapp.com* to one of two services, *blogservice* or *storeservice*, and directs the customer to one service or the other based on the URL they access.
116
114
117
115
```yaml
118
116
apiVersion: networking.k8s.io/v1
@@ -163,34 +161,35 @@ There are many scenarios for ingress, including the following how-to guides:
163
161
>
164
162
> To scan incoming traffic for potential attacks, use a web application firewall (WAF) such as [Barracuda WAF for Azure][barracuda-waf] or Azure Application Gateway. These more advanced network resources can also route traffic beyond just HTTP and HTTPS connections or basic TLS termination.
165
163
166
-
Typically, an ingress controller is a Kubernetes resource in your AKS cluster that distributes traffic to services and applications. The controller runs as a daemon on an AKS node, and consumes some of the node's resources, like CPU, memory, and network bandwidth. In larger environments, you'll want to:
164
+
Typically, an ingress controller is a Kubernetes resource in your AKS cluster that distributes traffic to services and applications. The controller runs as a daemon on an AKS node, and consumes some of the node's resources, like CPU, memory, and network bandwidth. In larger environments, you may want to consider the following:
165
+
167
166
* Offload some of this traffic routing or TLS termination to a network resource outside of the AKS cluster.
168
167
* Scan incoming traffic for potential attacks.
169
168
170
169

171
170
172
-
For that extra layer of security, a web application firewall (WAF) filters the incoming traffic. With a set of rules, the Open Web Application Security Project (OWASP) watches for attacks like cross-site scripting or cookie poisoning. [Azure Application Gateway][app-gateway] (currently in preview in AKS) is a WAF that integrates with AKS clusters, locking in these security features before the traffic reaches your AKS cluster and applications.
171
+
For that extra layer of security, a web application firewall (WAF) filters the incoming traffic. With a set of rules, the Open Web Application Security Project (OWASP) watches for attacks like cross-site scripting or cookie poisoning. [Azure Application Gateway][app-gateway] (currently in preview in AKS) is a WAF that integrates with AKS clusters, locking in these security features before the traffic reaches your AKS cluster and applications.
173
172
174
173
Since other third-party solutions also perform these functions, you can continue to use existing investments or expertise in your preferred product.
175
174
176
175
Load balancer or ingress resources continually run in your AKS cluster and refine the traffic distribution. App Gateway can be centrally managed as an ingress controller with a resource definition. To get started, [create an Application Gateway Ingress controller][app-gateway-ingress].
177
176
178
177
## Control traffic flow with network policies
179
178
180
-
> **Best practice guidance**
179
+
> **Best practice guidance**
181
180
>
182
181
> Use network policies to allow or deny traffic to pods. By default, all traffic is allowed between pods within a cluster. For improved security, define rules that limit pod communication.
183
182
184
183
Network policy is a Kubernetes feature available in AKS that lets you control the traffic flow between pods. You allow or deny traffic to the pod based on settings such as assigned labels, namespace, or traffic port. Network policies are a cloud-native way to control the flow of traffic for pods. As pods are dynamically created in an AKS cluster, required network policies can be automatically applied.
185
184
186
-
To use network policy, enable the feature when you create a new AKS cluster. You can't enable network policy on an existing AKS cluster. Plan ahead to enable network policy on the necessary clusters.
185
+
To use network policy, enable the feature when you create a new AKS cluster. You can't enable network policy on an existing AKS cluster. Plan ahead to enable network policy on the necessary clusters.
187
186
188
187
>[!NOTE]
189
-
>Network policy should only be used for Linux-based nodes and pods in AKS.
188
+
>Network policy should only be used for Linux-based nodes and pods in AKS.
190
189
191
-
You create a network policy as a Kubernetes resource using a YAML manifest. Policies are applied to defined pods, with ingress or egress rules defining traffic flow.
190
+
You create a network policy as a Kubernetes resource using a YAML manifest. Policies are applied to defined pods, with ingress or egress rules defining traffic flow.
192
191
193
-
The following example applies a network policy to pods with the *app: backend* label applied to them. The ingress rule only allows traffic from pods with the *app: frontend* label:
192
+
The following example applies a network policy to pods with the *app: backend* label applied to them. The ingress rule only allows traffic from pods with the *app: frontend* label.
194
193
195
194
```yaml
196
195
kind: NetworkPolicy
@@ -212,15 +211,15 @@ To get started with policies, see [Secure traffic between pods using network pol
212
211
213
212
## Securely connect to nodes through a bastion host
214
213
215
-
> **Best practice guidance**
214
+
> **Best practice guidance**
216
215
>
217
216
> Don't expose remote connectivity to your AKS nodes. Create a bastion host, or jump box, in a management virtual network. Use the bastion host to securely route traffic into your AKS cluster to remote management tasks.
218
217
219
218
You can complete most operations in AKS using the Azure management tools or through the Kubernetes API server. AKS nodes are only available on a private network and aren't connected to the public internet. To connect to nodes and provide maintenance and support, route your connections through a bastion host, or jump box. Verify this host lives in a separate, securely-peered management virtual network to the AKS cluster virtual network.
220
219
221
220

222
221
223
-
The management network for the bastion host should be secured, too. Use an [Azure ExpressRoute][expressroute] or [VPN gateway][vpn-gateway] to connect to an on-premises network, and control access using network security groups.
222
+
You should also secure the management network for the bastion host. Use an [Azure ExpressRoute][expressroute] or [VPN gateway][vpn-gateway] to connect to an on-premises network and control access using network security groups.
0 commit comments