Kubernetes Networking in Azure Kubernetes Service (AKS)

This document provides a comprehensive guide to understanding and configuring networking for Azure Kubernetes Service (AKS) clusters. Effective network configuration is crucial for the communication, security, and performance of your containerized applications.

Core Networking Concepts in AKS

AKS leverages several Azure networking components and Kubernetes native networking features. Understanding these interplays is key to managing your cluster's network:

1. Virtual Networks (VNets) and Subnets

AKS clusters are deployed within an Azure Virtual Network. This provides an isolated and secure network environment for your cluster's nodes and pods. You can either let AKS create a VNet for you or deploy your AKS cluster into an existing VNet.

2. Azure CNI Network Plugin

AKS supports two primary network plugins:

3. Ingress Controllers

Ingress controllers manage external access to services in a cluster, typically HTTP and HTTPS. AKS offers:

You can install an Ingress controller using Helm or during cluster creation.

4. Network Security Groups (NSGs)

NSGs are applied to subnets or network interfaces to filter network traffic. AKS automatically manages NSGs for its control plane and node subnets to allow necessary traffic for cluster operation.

Tip: When using Azure CNI, you can manually configure NSGs for your node subnet to restrict or allow traffic to pods.

5. Azure Firewall

For advanced network security and centralized management, you can integrate AKS with Azure Firewall to control egress traffic from your cluster.

Common Networking Scenarios

Exposing Applications

You can expose your applications in AKS using several Kubernetes service types:

Network Policies

Network Policies are Kubernetes resources that control the traffic flow at the IP address or port level (OSI layer 3 or 4) between pods. They are implemented by a network plugin that supports them, such as Azure CNI.

Example Network Policy to allow ingress from specific pods:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-specific-ingress
spec:
  podSelector:
    matchLabels:
      app: my-backend
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: my-frontend
    ports:
    - protocol: TCP
      port: 8080

Private Clusters

For enhanced security, you can create AKS clusters with private API server endpoints, meaning the control plane is not exposed to the public internet. This requires careful network configuration for access.

Best Practices for AKS Networking

For detailed configuration steps and advanced scenarios, please refer to the official Azure Kubernetes Service documentation.