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
+6-37Lines changed: 6 additions & 37 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
@@ -65,14 +65,12 @@ To use Azure Network Policy, you must use the [Azure CNI plug-in][azure-cni] and
65
65
The following example script:
66
66
67
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.
68
+
* Creates an AKS cluster in the defined virtual network with system-assigned identity and enables network policy.
71
69
* 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
70
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).
71
+
Note that 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
72
75
-
Provide your own secure *SP_PASSWORD*. You can replace the *RESOURCE_GROUP_NAME* and *CLUSTER_NAME* variables:
73
+
You can replace the *RESOURCE_GROUP_NAME* and *CLUSTER_NAME* variables:
76
74
77
75
```azurecli-interactive
78
76
RESOURCE_GROUP_NAME=myResourceGroup-NP
@@ -90,41 +88,20 @@ az network vnet create \
90
88
--subnet-name myAKSSubnet \
91
89
--subnet-prefix 10.240.0.0/16
92
90
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
91
# Get the virtual network subnet resource ID
109
92
SUBNET_ID=$(az network vnet subnet show --resource-group $RESOURCE_GROUP_NAME --vnet-name myVnet --name myAKSSubnet --query id -o tsv)
110
93
```
111
94
112
95
### Create an AKS cluster for Azure network policies
113
96
114
-
Create the AKS cluster and specify the virtual network, service principal information, and *azure* for the network plugin and network policy.
97
+
Create the AKS cluster and specify the virtual network and *azure* for the network plugin and network policy.
115
98
116
99
```azurecli
117
100
az aks create \
118
101
--resource-group $RESOURCE_GROUP_NAME \
119
102
--name $CLUSTER_NAME \
120
103
--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
104
--vnet-subnet-id $SUBNET_ID \
126
-
--service-principal $SP_ID \
127
-
--client-secret $SP_PASSWORD \
128
105
--network-plugin azure \
129
106
--network-policy azure
130
107
```
@@ -137,7 +114,7 @@ az aks get-credentials --resource-group $RESOURCE_GROUP_NAME --name $CLUSTER_NAM
137
114
138
115
### Create an AKS cluster for Calico network policies
139
116
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.
117
+
Create the AKS cluster and specify the virtual network, *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
118
142
119
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