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
+9-58Lines changed: 9 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ titleSuffix: Azure Kubernetes Service
4
4
description: Learn how to secure traffic that flows in and out of pods by using Kubernetes network policies in Azure Kubernetes Service (AKS)
5
5
services: container-service
6
6
ms.topic: article
7
-
ms.date: 03/29/2022
7
+
ms.date: 06/24/2022
8
8
9
9
---
10
10
@@ -60,71 +60,31 @@ First, let's create an AKS cluster that supports network policy.
60
60
>
61
61
> The network policy feature can only be enabled when the cluster is created. You can't enable network policy on an existing AKS cluster.
62
62
63
-
To use Azure Network Policy, you must use the [Azure CNI plug-in][azure-cni] and define your own virtual network and subnets. For more detailed information on how to plan out the required subnet ranges, see [configure advanced networking][use-advanced-networking]. Calico Network Policy could be used with either this same Azure CNI plug-in or with the Kubenet CNI plug-in.
63
+
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.
64
64
65
65
The following example script:
66
66
67
-
* Creates a virtual network and subnet.
68
-
* Creates an Azure Active Directory (Azure AD) service principal for use with the AKS cluster.
69
-
* Assigns *Contributor* permissions for the AKS cluster service principal on the virtual network.
70
-
* Creates an AKS cluster in the defined virtual network and enables network policy.
67
+
* Creates an AKS cluster with system-assigned identity and enables network policy.
71
68
* 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`.
72
69
73
-
Note that instead of using a service principal, you can use a managed identity for permissions. For more information, see [Use managed identities](use-managed-identity.md).
70
+
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).
74
71
75
-
Provide your own secure *SP_PASSWORD*. You can replace the *RESOURCE_GROUP_NAME* and *CLUSTER_NAME* variables:
72
+
### Create an AKS cluster for Azure network policies
73
+
74
+
You can replace the *RESOURCE_GROUP_NAME* and *CLUSTER_NAME* variables:
76
75
77
76
```azurecli-interactive
78
77
RESOURCE_GROUP_NAME=myResourceGroup-NP
79
78
CLUSTER_NAME=myAKSCluster
80
79
LOCATION=canadaeast
81
80
82
-
# Create a resource group
83
-
az group create --name $RESOURCE_GROUP_NAME --location $LOCATION
84
-
85
-
# Create a virtual network and subnet
86
-
az network vnet create \
87
-
--resource-group $RESOURCE_GROUP_NAME \
88
-
--name myVnet \
89
-
--address-prefixes 10.0.0.0/8 \
90
-
--subnet-name myAKSSubnet \
91
-
--subnet-prefix 10.240.0.0/16
92
-
93
-
# Create a service principal and read in the application ID
94
-
SP=$(az ad sp create-for-rbac --output json)
95
-
SP_ID=$(echo $SP | jq -r .appId)
96
-
SP_PASSWORD=$(echo $SP | jq -r .password)
97
-
98
-
# Wait 15 seconds to make sure that service principal has propagated
99
-
echo "Waiting for service principal to propagate..."
100
-
sleep 15
101
-
102
-
# Get the virtual network resource ID
103
-
VNET_ID=$(az network vnet show --resource-group $RESOURCE_GROUP_NAME --name myVnet --query id -o tsv)
104
-
105
-
# Assign the service principal Contributor permissions to the virtual network resource
106
-
az role assignment create --assignee $SP_ID --scope $VNET_ID --role Contributor
107
-
108
-
# Get the virtual network subnet resource ID
109
-
SUBNET_ID=$(az network vnet subnet show --resource-group $RESOURCE_GROUP_NAME --vnet-name myVnet --name myAKSSubnet --query id -o tsv)
110
-
```
111
-
112
-
### Create an AKS cluster for Azure network policies
113
-
114
-
Create the AKS cluster and specify the virtual network, service principal information, and *azure* for the network plugin and network policy.
81
+
Create the AKS cluster and specify *azure* for the network plugin and network policy.
115
82
116
83
```azurecli
117
84
az aks create \
118
85
--resource-group $RESOURCE_GROUP_NAME \
119
86
--name $CLUSTER_NAME \
120
87
--node-count 1 \
121
-
--generate-ssh-keys \
122
-
--service-cidr 10.0.0.0/16 \
123
-
--dns-service-ip 10.0.0.10 \
124
-
--docker-bridge-address 172.17.0.1/16 \
125
-
--vnet-subnet-id $SUBNET_ID \
126
-
--service-principal $SP_ID \
127
-
--client-secret $SP_PASSWORD \
128
88
--network-plugin azure \
129
89
--network-policy azure
130
90
```
@@ -137,7 +97,7 @@ az aks get-credentials --resource-group $RESOURCE_GROUP_NAME --name $CLUSTER_NAM
137
97
138
98
### Create an AKS cluster for Calico network policies
139
99
140
-
Create the AKS cluster and specify the virtual network, service principal information, *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.
100
+
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.
141
101
142
102
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]. To use Calico with Windows node pools, you also need to register the `Microsoft.ContainerService/EnableAKSWindowsCalico`.
0 commit comments