Network traffic analysis in context of Azure Kubernetes Services managed cluster could be a complex task as it could involve installation of third-party products on the cluster’s Node, manually capturing network traffic with or without the necessary filters and exporting the results to an external destination in order to be analyzed. NSG FlowLogs combined with Traffic Analytics will simplify the process and would provide a significant support in troubleshooting network connectivity. A default installation of AKS cluster will provide a Network Security Group automatically configured by the AKS Resource Provider with the default rules for Inbound and Outbound traffic and also with the future services exposed from within the cluster. It is created by default in Infrastructure resource group (by default prefixed with MC_ ) and have the naming convention of aks — nodepool-name— nsg.
Activating the Flow Logs on the respective NSG is a straightforward process. We’ll open the Network Security Group Resource -> Monitoring -> NSF flow logs panel which will bring us in the default page. As we currently do not have a resource created, it will show us an empty list.
We choose the Create button, this will show us the first configuration panel for the resource, from the + Sign will select the NSG that we will monitor and will provide an existing or new Storage Account that will hosts the records in a Container. Also the retention day value should be provided in the same configuration panel.
On the second configuration panel, we choose the Version 2 of Flow Logs and also will activate the Enable Traffic Analytics button. After optional step of Tagging we choose to create the resource. Once with the Traffic Analytics selection, we will provide also a Log Analytics Workspace where our flow logging data will be saved. In a matter of seconds, we can see the resource created in our NSG Flow Logs page:
Once the NSG Flow Logs is linked to Log Analytics Workspace, we will go to Network Watcher -> Logs -> Traffic Analytics section in Azure Portal.
On top of the Traffic Analytics Panel we choose our resources, including the Resource Group where our NSG is located and also the Time Interval for results. It will provide a Dashboard with multiple values as follows:
- Number of flows
- Deployed Region and Vnet
- Total number of NSG monitored
Also the traffic distribution is included in the Report with the following:
- Total traffic
- Malicious traffic
- Frequent conversation flows.
For a raw capture of traffic, we can get the json output from the configured Storage Account. It will automatically create a container as follows:
In a hierarchical form created form Subscription → Resource Group -> Microsoft Network -> Network Security Group -> NodePool name -> year -> month -> day -> hour will be provided a Json formatted file. For a simple visualization of the file we can use the jq utility on the Linux side:
cat nsgflow.json | jq
The complete documentation for the format of the NSG Flow Logs can be found at the following Microsoft documentation.
Traffic Analytics logs are sent to Log Analytics Workspace through a custom logging table. You can access the respective session from the link provided in the dashboard as follows:
There are three provided custom tables with the following schemas: