Skip to content

Commit 07a3927

Browse files
authored
Merge pull request #202881 from CocoWang-wql/patch-9
update network policy doc
2 parents 7bed598 + d214b3d commit 07a3927

File tree

1 file changed

+9
-58
lines changed

1 file changed

+9
-58
lines changed

articles/aks/use-network-policies.md

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ titleSuffix: Azure Kubernetes Service
44
description: Learn how to secure traffic that flows in and out of pods by using Kubernetes network policies in Azure Kubernetes Service (AKS)
55
services: container-service
66
ms.topic: article
7-
ms.date: 03/29/2022
7+
ms.date: 06/24/2022
88

99
---
1010

@@ -60,71 +60,31 @@ First, let's create an AKS cluster that supports network policy.
6060
>
6161
> The network policy feature can only be enabled when the cluster is created. You can't enable network policy on an existing AKS cluster.
6262
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.
6464

6565
The following example script:
6666

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.
7168
* 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`.
7269

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).
7471

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:
7675

7776
```azurecli-interactive
7877
RESOURCE_GROUP_NAME=myResourceGroup-NP
7978
CLUSTER_NAME=myAKSCluster
8079
LOCATION=canadaeast
8180
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.
11582
11683
```azurecli
11784
az aks create \
11885
--resource-group $RESOURCE_GROUP_NAME \
11986
--name $CLUSTER_NAME \
12087
--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 \
12888
--network-plugin azure \
12989
--network-policy azure
13090
```
@@ -137,7 +97,7 @@ az aks get-credentials --resource-group $RESOURCE_GROUP_NAME --name $CLUSTER_NAM
13797

13898
### Create an AKS cluster for Calico network policies
13999

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.
141101

142102
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`.
143103

@@ -179,16 +139,7 @@ az aks create \
179139
--resource-group $RESOURCE_GROUP_NAME \
180140
--name $CLUSTER_NAME \
181141
--node-count 1 \
182-
--generate-ssh-keys \
183-
--service-cidr 10.0.0.0/16 \
184-
--dns-service-ip 10.0.0.10 \
185-
--docker-bridge-address 172.17.0.1/16 \
186-
--vnet-subnet-id $SUBNET_ID \
187-
--service-principal $SP_ID \
188-
--client-secret $SP_PASSWORD \
189142
--windows-admin-username $WINDOWS_USERNAME \
190-
--vm-set-type VirtualMachineScaleSets \
191-
--kubernetes-version 1.20.2 \
192143
--network-plugin azure \
193144
--network-policy calico
194145
```

0 commit comments

Comments
 (0)