共用方式為


Windows Server 上 AKS 中的 Proxy 伺服器設定

適用於:Windows Server 上的 AKS

本文說明如何在 Windows Server 上設定 AKS 的 Proxy 設定。 如果您的網路需要使用 Proxy 伺服器來連線到因特網,本文會逐步引導您使用 AksHci PowerShell 模組在 AKS 中設定 Proxy 支援的步驟。 這些步驟會根據 Proxy 伺服器是否需要驗證而有所不同。

注意

如果您想要搭配 Azure Arc 使用 Kubernetes 和 Azure 服務,請確定您也會將現有的 Kubernetes 叢集連線至 Azure Arc所示的 URL 新增至您的允許清單。

使用下列選項設定部署之後,您就可以在 Windows Server 上安裝 AKS 主機,並使用 PowerShell 建立 Kubernetes 叢集

開始之前

請確定您已符合系統需求中的所有必要條件。

Proxy 伺服器組態資訊

AKS 部署的 Proxy 伺服器組態包含下列設定:

  • HTTP URL 和埠,例如 http://proxy.corp.contoso.com:8080
  • HTTPS URL 和埠,例如 https://proxy.corp.contoso.com:8443
  • (可選)用於 Proxy 伺服器驗證的有效憑證。
  • (選擇性)如果您的 Proxy 伺服器設定為攔截 SSL 流量,則需要有效的憑證鏈。 此憑證鏈結會匯入所有 AKS 控制平面和工作節點,以及管理叢集,以建立與代理伺服器的受信任連線。

排除私人子網無法傳送至 Proxy 的排除清單

下表包含您必須使用 -noProxy 中的 New-AksHciProxySetting參數排除的位址清單。

IP 位址 排除原因
localhost127.0.0.1 localhost 流量
.svc 內部 Kubernetes 服務流量,其中 .svc 代表通配符名稱。 這就像是在說 *.svc,但在此架構中沒有使用任何元素。
10.0.0.0/8 專用網位址空間。
172.16.0.0/12 私人網路位址空間 - Kubernetes 服務 CIDR。
192.168.0.0/16 私人網路位址空間 - Kubernetes Pod CIDR。
.contoso.com`` | You might want to exempt your enterprise namespace (.contoso.com) from being directed through the proxy. To exclude all addresses in a domain, you must add the domain to the noProxylist. Use a leading period rather than a wildcard (\*) character. In the example, the addresses.contoso.comexcludes addressesprefix1.contoso.com, prefix2.contoso.com,等等。

noProxy 的預設值為 localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16。 雖然這些預設值適用於許多網路,但您可能需要將更多子網範圍和/或名稱新增至豁免清單。 例如,您可能想要豁免企業命名空間(.contoso.com)不被導向至代理伺服器。 您可以在 noProxy 清單中指定值來達成此目的。

使用全機器 Proxy 設定來設定 Windows Server 叢集的 Proxy

如果您的 Windows Server 叢集上已經有整個機器的代理伺服器設定,這些設定可能會取代任何 AKS 特定的代理伺服器設定,並在安裝期間導致失敗。

若要偵測您是否擁有全計算機的 Proxy 設定,請在每個實體叢集節點上執行下列腳本:

$http_proxy = [System.Environment]::GetEnvironmentVariable("HTTP_PROXY", "Machine")
$https_proxy = [System.Environment]::GetEnvironmentVariable("HTTPS_PROXY", "Machine")
$no_proxy = [System.Environment]::GetEnvironmentVariable("NO_PROXY", "Machine")

if ($http_proxy -or $https_proxy) {
    if (-not $no_proxy) {
        Write-Host "Problem Detected! A machine-wide proxy server is configured, but no proxy exclusions are configured"
    }
}

在偵測到問題的每個實體叢集主機上設定全機器 Proxy 排除專案。

執行下列 PowerShell 腳本,並將 $no_proxy 參數字串替換為適合您環境的 NO_PROXY 排除字串。 如需有關如何正確配置 noProxy 清單以適應您的環境的資訊,請參閱 將私人子網從傳送至代理的清單中排除

$no_proxy = "localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.contoso.com"
[Environment]::SetEnvironmentVariable("NO_PROXY", $no_proxy, "Machine")
$env:NO_PROXY = [System.Environment]::GetEnvironmentVariable("NO_PROXY", "Machine")

注意

建議您在故障轉移叢集中的所有節點上使用相同的 Proxy 設定。 在故障轉移叢集中的不同實體節點上有不同的 Proxy 設定可能會導致非預期的結果或安裝問題。 此外,具有通配符的IP位址,例如 172。*, 無效。 IP 位址必須位於適當的 CIDR 表示法中(172.0.0.0/8)。

安裝 AksHci PowerShell 模組

在叢集中的每個實體節點上設定系統 Proxy 設定,並確定所有節點都能存取系統需求中所述的 URL 和埠。

如果您使用遠端 PowerShell,則必須使用 CredSSP。

在執行下列命令之前,請先關閉所有開啟的 PowerShell 視窗:

Install-Module -Name AksHci -Repository PSGallery

如果您的環境使用 Proxy 伺服器來存取因特網,您可能需要在安裝 AKS 之前,將 Proxy 參數新增至 Install-Module 命令。 如需詳細資訊,請參閱 Install-Module 檔

當您下載 AksHci PowerShell 模組時,我們也會下載向 Azure 註冊 AKS 主機以計費所需的 Az PowerShell 模組。

設定 AKS 主機以用於具有基本身份驗證的代理伺服器

如果您的 Proxy 伺服器需要驗證,請以系統管理員身分開啟 PowerShell,然後執行下列命令以取得認證並設定組態詳細數據:

$proxyCred = Get-Credential
$proxySetting=New-AksHciProxySetting -name "corpProxy" -http http://contosoproxy:8080 -https https://contosoproxy:8443 -noProxy localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.contoso.com -credential $proxyCredential

為 Proxy 伺服器設定 AKS 主機,而不需驗證

如果您的 Proxy 伺服器不需要驗證,請執行下列命令:

$proxySetting=New-AksHciProxySetting -name "corpProxy" -http http://contosoproxy:8080 -https https://contosoproxy:8443 -noProxy localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.contoso.com

使用受信任的憑證為 Proxy 伺服器設定 AKS 主機

如果您的 Proxy 伺服器需要 Proxy 用戶端信任憑證,請在執行 Set-AksHciConfig時指定憑證檔案。 憑證檔案的格式為 Base-64編碼的 X.509。 這可讓您在整個堆疊中建立並信任憑證。

重要

如果您的 Proxy 需要實體節點信任憑證,請務必先將憑證鏈結匯入每個節點上的適當證書存儲,再繼續進行。 請遵循部署程序,使用所需的憑證來進行 Proxy 驗證並註冊節點。

$proxySetting=New-AksHciProxySetting -name "corpProxy" -http http://contosoproxy:8080 -https https://contosoproxy:8443 -noProxy localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.contoso.com -credential $proxyCredential

注意

Proxy 憑證必須以個人資訊交換 (PFX) 檔格式或字串的形式提供,並包含根授權單位鏈結,以使用憑證進行驗證或 SSL 通道設定。

下一步

您現在可以繼續在 Windows Server 叢集上安裝 AKS,方法是執行 Set-AksHciConfig ,後面接著 Install-AksHci