[Private AKS 구성]

https://learn.microsoft.com/ko-kr/azure/aks/limit-egress-traffic#required-ports-and-addresses-for-aks-clusters

[아키텍처]

Untitled

  1. Azure CLI에서 변수 선언 및 리소스 그룹 생성

    PREFIX="lsc"
    RG="${PREFIX}-rg"
    LOC="koreacentral"
    PLUGIN=azure
    AKSNAME="${PREFIX}"
    VNET_NAME="${PREFIX}-vnet"
    AKSSUBNET_NAME="aks-subnet"
    
    # DO NOT CHANGE FWSUBNET_NAME - This is currently a requirement for Azure Firewall.
    FWSUBNET_NAME="AzureFirewallSubnet"
    FWNAME="${PREFIX}-fw"
    FWPUBLICIP_NAME="${PREFIX}-fwpublicip"
    FWIPCONFIG_NAME="${PREFIX}-fwconfig"
    FWROUTE_TABLE_NAME="${PREFIX}-fwrt"
    FWROUTE_NAME="${PREFIX}-fwrn"
    FWROUTE_NAME_INTERNET="${PREFIX}-fwinternet"
    

    Untitled

  2. 가상 네트워크 및 서브넷 생성

    # Dedicated virtual network with AKS subnet
    az network vnet create \\
        --resource-group $RG \\
        --name $VNET_NAME \\
        --location $LOC \\
        --address-prefixes 10.42.0.0/16 \\
        --subnet-name $AKSSUBNET_NAME \\
        --subnet-prefix 10.42.1.0/24
    
    # Dedicated subnet for Azure Firewall (Firewall name can't be changed)
    az network vnet subnet create \\
        --resource-group $RG \\
        --vnet-name $VNET_NAME \\
        --name $FWSUBNET_NAME \\
        --address-prefix 10.42.2.0/24
    
  3. UDR을 사용하여 Azure Firewall 만들기, 설정

    Untitled

    3-1) Public IP 생성 (Azure Firewall Front IP로 사용)

    az network public-ip create -g $RG -n $FWPUBLICIP_NAME -l $LOC --sku "Standard"
    

    3-2) Azure Firewall CLI 확장 등록

    az extension add --name azure-firewall
    

    3-3) Azure Firewall 생성 및 DNS 프록시 설정

    az network firewall create -g $RG -n $FWNAME -l $LOC --enable-dns-proxy true
    

    3-4) Azure Firewall IP 구성

    az network firewall ip-config create -g $RG -f $FWNAME -n $FWIPCONFIG_NAME --public-ip-address $FWPUBLICIP_NAME --vnet-name $VNET_NAME
    

    Untitled

  4. 홉을 사용하여 Azure Firewall에 대한 UDR 만들기

    az network route-table create -g $RG -l $LOC --name $FWROUTE_TABLE_NAME
    
    az network route-table route create -g $RG --name $FWROUTE_NAME --route-table-name $FWROUTE_TABLE_NAME --address-prefix 0.0.0.0/0 --next-hop-type VirtualAppliance --next-hop-ip-address $FWPRIVATE_IP
    
    az network route-table route create -g $RG --name $FWROUTE_NAME_INTERNET --route-table-name $FWROUTE_TABLE_NAME --address-prefix $FWPUBLIC_IP/32 --next-hop-type Internet
    

    Untitled

  5. 방화벽 규칙 추가

  1. AKS에 UDR 연결
  1. UDR 아웃바운드 형식의 AKS클러스터를 기존 네트워크에 배포

    Untitled

    • 배포할 서브넷 대상 지정

    SUBNETID=$(az network vnet subnet show -g $RG --vnet-name $VNET_NAME --name $AKSSUBNET_NAME --query id -o tsv)
    
  2. 시스템 할당 ID로 AKS 클러스터 만들기

    az aks create -g $RG -n $AKSNAME -l $LOC \\
      --node-count 3 \\
      --network-plugin azure \\
      --outbound-type userDefinedRouting \\
      --vnet-subnet-id $SUBNETID \\
      --api-server-authorized-ip-ranges $FWPUBLIC_IP
    

    Untitled

  3. 사용자 할당 ID 만들기

    az identity create --name myIdentity --resource-group myResourceGroup
    
  4. API 서버에 대한 개발자 액세스 사용

    CURRENT_IP=$(dig @resolver1.opendns.com ANY myip.opendns.com +short)
    
    az aks update -g $RG -n $AKSNAME --api-server-authorized-ip-ranges CURRENT_IP/32
    

    Untitled