All pods in the AKS cluster can send and receive traffic without limitations, by default. To improve security, you can define rules that control the flow of traffic.
Network Policy is a Kubernetes specification that defines access policies for communication between pods. Using network Policy, you can define an ordered set of rules to send and receive traffic.
To learn more about it, refer to the official documentation of Microsoft on network policy.
This section gives an overview on how to configure Network Policy rules:
If linkerd, ingress-nginx and keda are installed in custom namespaces, please allow traffic from those namespaces.
CASE 1: To add any other external namespace apart from the default one. Follow the below steps:
Step 1: Go to values.yaml and edit the same.
xxxxxxxxxx
vi values.yaml
Step 2: Go to networkPolicy under the global section in values.yaml.
xxxxxxxxxx
global:
networkPolicy:
enabled: true
namespaceValue:
- kube-system
- linkerd
- ingress-nginx
Step 3: Set the global.networkPolicy.enabled value to true.
Step 4: Now add the required external namespace value at global.networkPolicy.namespaceValue section. Make sure that the format should be in the list.
CASE 2: To allow external pods running in infoworks namespace to reach infoworks services. Follow the following steps:
Step 1: Go to values.yaml and edit the same.
xxxxxxxxxx
vi values.yaml
Step 2: Go to networkPolicy under the global section in values.yaml.
xxxxxxxxxx
global:
networkPolicy:
enabled: true
namespaceValue:
- kube-system
- linkerd
externalPodKeyVal:
enabled: true
rules:
- key: app1
val:
- val1
- val2
Step 3: Set the global.networkPolicy.externalPodKeyVal.enabled value to true.
Step 4: Now in the global.networkPolicy.externalPodKeyVal.rules section add the key-value pair of pods.
The 1st pod has a key-value pair as app1:val1 and the 2nd pod has a key-value pair as app1:val2. Add these following values according to the example shown above. Add as many pods key-val required but make sure to follow the syntax as above.
CASE 3: To allow specific pods from an external namespace to reach Infoworks without permitting connectivity to all pods in the external namespace, follow these steps:
Step 1: Go to values.yaml and edit the same.
xxxxxxxxxx
vi values.yaml
Step 2: Go to networkPolicy under the global section in values.yaml.
xxxxxxxxxx
global:
networkPolicy:
enabled: true
namespaceValue:
- kube-system
- linkerd
externalNamespaceKeyVal:
enabled: true
rules:
- key: namespace2
podKeyval:
- key: app.kubernetes.io/name
val:
- ingress-nginx
Step 3: Set the global.networkPolicy.externalNamespaceKeyVal.enabled value to true.
Step 4: Now in the global.networkPolicy.externalNamespaceKeyVal.rules section add the key-value pair of pods.
This step is required only when the AKS cluster doesn't have Network Policy enabled. To verify the same, follow the Approach mentioned here. |
Disable Network Policy for the following scenario:
Step 1: If the AKS cluster does not have Network Policy enabled.
Follow the following Steps to Disable Network Policy:
Step 1: Go to values.yaml and Edit the same.
xxxxxxxxxx
vi values.yaml
Step 2: Go to networkPolicy under the global section in values.yaml
xxxxxxxxxx
global:
networkPolicy:
enabled: true
namespaceValue:
- kube-system
- linkerd
Step 3: Set the global.networkPolicy.enabled value to false.
xxxxxxxxxx
global:
networkPolicy:
enabled: false
Steps to verify whether network policies are enabled in an Azure Kubernetes Service (AKS) cluster.
xxxxxxxxxx
resourceGroupName=<resource-group-name>
aksClusterName=<aks-cluster-name>
# Get AKS cluster Network Profile information
az aks show --resource-group $resourceGroupName --name $aksClusterName --query "networkProfile"
Expected Output
Step 1: Open the Azure portal, go to the AKS service, and select your AKS cluster.
Step 2: In the left sidebar, under "Settings", click on "Networking".
Step 3: Look for the "Network Profile" section.
Step 4: If it says "Azure" or another network policy provider (eg. Calico), the network policies are enabled.