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/use-network-policies.md
+64-56Lines changed: 64 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,32 +12,32 @@ ms.date: 06/24/2022
12
12
13
13
When you run modern, microservices-based applications in Kubernetes, you often want to control which components can communicate with each other. The principle of least privilege should be applied to how traffic can flow between pods in an Azure Kubernetes Service (AKS) cluster. Let's say you likely want to block traffic directly to back-end applications. The *Network Policy* feature in Kubernetes lets you define rules for ingress and egress traffic between pods in a cluster.
14
14
15
-
This article shows you how to install the network policy engine and create Kubernetes network policies to control the flow of traffic between pods in AKS. Network policy could be used for Linux-based or Windows-based nodes and pods in AKS.
15
+
This article shows you how to install the Network Policy engine and create Kubernetes network policies to control the flow of traffic between pods in AKS. Network Policy could be used for Linux-based or Windows-based nodes and pods in AKS.
16
16
17
17
## Before you begin
18
18
19
19
You need the Azure CLI version 2.0.61 or later installed and configured. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][install-azure-cli].
20
20
21
-
## Overview of network policy
21
+
## Overview of Network Policy
22
22
23
23
All pods in an AKS cluster can send and receive traffic without limitations, by default. To improve security, you can define rules that control the flow of traffic. Back-end applications are often only exposed to required front-end services, for example. Or, database components are only accessible to the application tiers that connect to them.
24
24
25
-
Network Policy is a Kubernetes specification that defines access policies for communication between Pods. Using Network Policies, you define an ordered set of rules to send and receive traffic and apply them to a collection of pods that match one or more label selectors.
25
+
Network Policy is a Kubernetes specification that defines access policies for communication between Pods. Using network policies, you define an ordered set of rules to send and receive traffic and apply them to a collection of pods that match one or more label selectors.
26
26
27
-
These network policy rules are defined as YAML manifests. Network policies can be included as part of a wider manifest that also creates a deployment or service.
27
+
These Network Policy rules are defined as YAML manifests. Network Policies can be included as part of a wider manifest that also creates a deployment or service.
28
28
29
29
## Network policy options in AKS
30
30
31
-
Azure provides two ways to implement network policy. You choose a network policy option when you create an AKS cluster. The policy option can't be changed after the cluster is created:
31
+
Azure provides two ways to implement Network Policy. You choose a Network Policy option when you create an AKS cluster. The policy option can't be changed after the cluster is created:
32
32
33
-
* Azure's own implementation, called *Azure Network Policies*.
33
+
* Azure's own implementation, called *Azure Network Policy Manager(NPM)*.
34
34
**Calico Network Policies*, an open-source network and network security solution founded by [Tigera][tigera].
35
35
36
-
Azure Network Policy for Linux uses Linux *IPTables* and Azure Network Policy for Windows uses *HNS ACLPolicies* to enforce the specified policies. Policies are translated into sets of allowed and disallowed IP pairs. These pairs are then programmed as IPTable/HNS ACLPolicy filter rules.
36
+
Azure NPM for Linux uses Linux *IPTables* and Azure NPM for Windows uses *Host Network Service(HNS) ACLPolicies* to enforce the specified policies. Policies are translated into sets of allowed and disallowed IP pairs. These pairs are then programmed as IPTable/HNS ACLPolicy filter rules.
37
37
38
-
## Differences between Azure and Calico policies and their capabilities
38
+
## Differences between Azure NPM and Calico Network Policy and their capabilities
| Supported platforms | Linux, Windows Server 2022 | Linux, Windows Server 2019 and 2022 |
43
43
| Supported networking options | Azure CNI | Azure CNI (Linux, Windows Server 2019 and 2022) and kubenet (Linux) |
@@ -48,53 +48,36 @@ Azure Network Policy for Linux uses Linux *IPTables* and Azure Network Policy fo
48
48
49
49
## Limitations:
50
50
51
-
* NPNetwork Policy does not support IPv6. Otherwise, Network Policy fully supports the Network Policy spec in Linux.
52
-
* In Windows, Network Policy does not support the following:
51
+
*Azure Network Policy Manager(NPM) does not support IPv6. Otherwise, Azure NPM fully supports the network policy spec in Linux.
52
+
* In Windows, Azure NPM does not support the following:
53
53
* named ports
54
54
* SCTP protocol
55
55
* negative match label or namespace selectors (e.g. all labels except "debug=true")
56
-
* potential latency issues for policy application
57
56
* "except" CIDR blocks (a CIDR with exceptions)
58
57
59
58
>[!NOTE]
60
-
> * The limitations listed above does have alternatives to it.
61
-
> * Network Policy pod logs will record an error if an unsupported policy is created.
59
+
> * Azure NPM pod logs will record an error if an unsupported policy is created.
62
60
63
-
## Create an AKS cluster and enable network policy
61
+
## Create an AKS cluster and enable Network Policy
64
62
65
63
To see network policies in action, let's create an AKS cluster that supports network policy and then work on adding policies.
66
64
67
65
> [!IMPORTANT]
68
66
>
69
67
> The network policy feature can only be enabled when the cluster is created. You can't enable network policy on an existing AKS cluster.
70
68
71
-
To use Azure Network Policy, you must use the [Azure CNI plug-in][azure-cni]. Calico Network Policy could be used with either this same Azure CNI plug-in or with the Kubenet CNI plug-in.
69
+
To use Azure NPM, you must use the [Azure CNI plug-in][azure-cni]. Calico Network Policy could be used with either this same Azure CNI plug-in or with the Kubenet CNI plug-in.
72
70
73
71
The following example script:
74
72
75
-
* Creates an AKS cluster with system-assigned identity and enables network policy.
76
-
* The _Azure Network_ policy option is used. To use Calico as the network policy option instead, use the `--network-policy calico` parameter. Note: Calico could be used with either `--network-plugin azure` or `--network-plugin kubenet`.
73
+
* Creates an AKS cluster with system-assigned identity and enables Network Policy.
74
+
* The _Azure NPM_option is used. To use Calico as the Network Policy option instead, use the `--network-policy calico` parameter. Note: Calico could be used with either `--network-plugin azure` or `--network-plugin kubenet`.
77
75
78
76
Instead of using a system-assigned identity, you can also use a user-assigned identity. For more information, see [Use managed identities](use-managed-identity.md).
79
77
80
-
### Preview Flag for Windows Sever 2022
78
+
### Create an AKS cluster with Azure NPM enabled - Linux only
81
79
82
-
To enable Azure Network Policy on Windows Server 2022 node pools, please execute the following commands prior to creating a cluster:
83
-
84
-
```azurecli
85
-
az extension add --name aks-preview
86
-
az extension update --name aks-preview
87
-
az feature register --namespace Microsoft.ContainerService --name AKSWindows2022Preview
88
-
az feature register --namespace Microsoft.ContainerService --name WindowsNetworkPolicyPreview
89
-
az provider register -n Microsoft.ContainerService
90
-
```
91
-
> [!IMPORTANT]
92
-
> At this time, Azure network policies with Windows nodes is available on Windows Server 2022 only
93
-
>
94
-
95
-
### Create an AKS cluster with Azure Network Policy
96
-
97
-
In this section, we will work on creating a cluster with Azure Network Policy enabled.
80
+
In this section, we will work on creating a cluster with Linux node pools and Azure NPM enabled.
98
81
99
82
To begin, you should replace the values for *$RESOURCE_GROUP_NAME* and *$CLUSTER_NAME* variables.
100
83
@@ -104,17 +87,9 @@ $CLUSTER_NAME=myAKSCluster
104
87
$LOCATION=canadaeast
105
88
```
106
89
107
-
In case, you are planning to create Windows Server 2022 node pools, you will need to replace values for *$WINDOWS_USERNAME*, *$WINDOWS_PASSWORD* and *$k8S_VERSION* variables in addition to the ones mentioned above.
108
-
109
-
```azurecli-interactive
110
-
$WINDOWS_USERNAME=myWindowsUserName
111
-
$WINDOWS_PASSWORD=myWindowsPassword
112
-
$k8S_VERSION=myk8sVersion
113
-
```
114
-
115
-
Create the AKS cluster and specify *azure* for the network plugin and network policy.
90
+
Create the AKS cluster and specify *azure* for the `network-plugin` and `network-policy`.
116
91
117
-
Use the following command for cluster running with **only Linux** node pools:
92
+
Use the following command for a cluster running with **Linux** node pools:
118
93
```azurecli
119
94
az aks create \
120
95
--resource-group $RESOURCE_GROUP_NAME \
@@ -123,6 +98,34 @@ az aks create \
123
98
--network-plugin azure \
124
99
--network-policy azure
125
100
```
101
+
102
+
### Create an AKS cluster with Azure NPM enabled - Windows Server 2022 (Preview)
103
+
104
+
In this section, we will work on creating a cluster with Windows node pools and Azure NPM enabled.
105
+
106
+
Please execute the following commands prior to creating a cluster:
107
+
108
+
```azurecli
109
+
az extension add --name aks-preview
110
+
az extension update --name aks-preview
111
+
az feature register --namespace Microsoft.ContainerService --name AKSWindows2022Preview
112
+
az feature register --namespace Microsoft.ContainerService --name WindowsNetworkPolicyPreview
113
+
az provider register -n Microsoft.ContainerService
114
+
115
+
> [!NOTE]
116
+
> At this time, Azure NPM with Windows nodes is available on Windows Server 2022 only
117
+
>
118
+
119
+
Now, you should replace the values for *$RESOURCE_GROUP_NAME*, *$CLUSTER_NAME*, *$WINDOWS_USERNAME*, *$WINDOWS_PASSWORD* and *$k8S_VERSION* variables.
120
+
121
+
```azurecli-interactive
122
+
$RESOURCE_GROUP_NAME=myResourceGroup-NP
123
+
$CLUSTER_NAME=myAKSCluster
124
+
$WINDOWS_USERNAME=myWindowsUserName
125
+
$WINDOWS_PASSWORD=myWindowsPassword
126
+
$k8S_VERSION=myk8sVersion
127
+
$LOCATION=canadaeast
128
+
```
126
129
Use the following command for cluster running with **Windows Server 2022** node pools:
127
130
128
131
```azurecli
@@ -138,15 +141,15 @@ az aks create \
138
141
--node-count 1
139
142
```
140
143
141
-
It takes a few minutes to create the cluster. When the cluster is ready, configure `kubectl` to connect to your Kubernetes cluster by using the [az aks get-credentials][az-aks-get-credentials] command. This command downloads credentials and configures the Kubernetes CLI to use them:
144
+
> [!NOTE]
145
+
> You can still add Linux node pools to the cluster created using the above command, by default.
146
+
>
142
147
143
-
```azurecli-interactive
144
-
az aks get-credentials --resource-group $RESOURCE_GROUP_NAME --name $CLUSTER_NAME
145
-
```
148
+
[!INCLUDE [preview features callout](./includes/preview/preview-callout.md)]
146
149
147
150
### Create an AKS cluster for Calico network policies
148
151
149
-
Create the AKS cluster and specify *azure* for the network plugin, and *calico* for the network policy. Using *calico* as the network policy enables Calico networking on both Linux and Windows node pools.
152
+
Create the AKS cluster and specify *azure* for the network plugin, and *calico* for the Network Policy. Using *calico* as the Network Policy enables Calico networking on both Linux and Windows node pools.
150
153
151
154
If you plan on adding Windows node pools to your cluster, include the `windows-admin-username` and `windows-admin-password` parameters with that meet the [Windows Server password requirements][windows-server-password].
152
155
@@ -187,11 +190,16 @@ When the cluster is ready, configure `kubectl` to connect to your Kubernetes clu
187
190
```azurecli-interactive
188
191
az aks get-credentials --resource-group $RESOURCE_GROUP_NAME --name $CLUSTER_NAME
189
192
```
190
-
### Verify Network Policy Setup
193
+
## Verify Network Policy Setup
194
+
195
+
It takes a few minutes to create the cluster. When the cluster is ready, configure `kubectl` to connect to your Kubernetes cluster by using the [az aks get-credentials][az-aks-get-credentials] command. This command downloads credentials and configures the Kubernetes CLI to use them:
191
196
192
-
Now that we have created a cluster, lets create a sample application and set traffic rules.
197
+
```azurecli-interactive
198
+
az aks get-credentials --resource-group $RESOURCE_GROUP_NAME --name $CLUSTER_NAME
199
+
```
200
+
To begin verification of network policy, we will create a sample application and set traffic rules.
193
201
194
-
First, let's create a namespace called *demo* to run the example pods:
202
+
Firstly, let's create a namespace called *demo* to run the example pods:
195
203
196
204
```console
197
205
kubectl create namespace demo
@@ -228,15 +236,15 @@ NAME READY STATUS RESTARTS AGE IP NODE NOMIN
228
236
server 1/1 Running 0 30s 10.224.0.72 akswin22000001 <none> <none>
229
237
```
230
238
231
-
####Test Connectivity without Network Policy
239
+
### Test Connectivity without Network Policy
232
240
233
241
In the client's shell, verify connectivity with the server by executing the following command. Replace *server-ip* by IP found in the output from executing previous command. There will be no output if the connection is successful:
In this article, we created a namespace, two pods and applied a network policy. To clean up these resources, use the [kubectl delete][kubectl-delete] command and specify the resource name:
296
+
In this article, we created a namespace, two pods and applied a Network Policy. To clean up these resources, use the [kubectl delete][kubectl-delete] command and specify the resource name:
Copy file name to clipboardExpand all lines: articles/virtual-network/kubernetes-network-policies.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,7 +78,7 @@ See a [configuration for these alerts](#setup-alerts-for-alertmanager) below.
78
78
2. Correlate cluster counts (e.g. ACLs) to execution times.
79
79
3. Get the human-friendly name of an ipset in a given iptables rule (e.g. "azure-npm-487392" represents "podlabel-role:database").
80
80
81
-
### All Supported Metrics
81
+
### All supported metrics
82
82
The following is the list of supported metrics. Any `quantile` label has possible values `0.5`, `0.9`, and `0.99`. Any `had_error` label has possible values `false` and `true`, representing whether the operation succeeded or failed.
83
83
84
84
| Metric Name | Description | Prometheus Metric Type | Labels |
0 commit comments