簡體   English   中英

如何為 AKS 中的出口流量保留 pod IP 地址?

[英]How to preserve pod IP address for egress traffic in AKS?

在 Azure Kubernetes (AKS) 中,如果 pod 在集群外發送流量,它會被 Natted 到節點 IP 地址。 例如,如果 pod nettools(來自節點 aks-agentpool-35359625-1)將流量發送到集群外部的 Azure 目的地,它會被 nat 到 10.240.0.35。 有沒有辦法保留原始來源( 10.240.0.48 )?

使用聯網插件 azure 和透明聯網模式運行的集群

/AKS/cluster1 $ kubectl get nodes -o wide 
kubectl get pods -o wide
NAME                       STATUS   ROLES   AGE     VERSION    INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
aks-agentpool-35359625-0   Ready    agent   6h13m   v1.15.10   10.240.0.66   <none>        Ubuntu 16.04.6 LTS   4.15.0-1071-azure   docker://3.0.10+azure
aks-agentpool-35359625-1   Ready    agent   6h13m   v1.15.10   10.240.0.35   <none>        Ubuntu 16.04.6 LTS   4.15.0-1071-azure   docker://3.0.10+azure
aks-agentpool-35359625-2   Ready    agent   6h13m   v1.15.10   10.240.0.4    <none>        Ubuntu 16.04.6 LTS   4.15.0-1071-azure   docker://3.0.10+azure
/AKS/cluster1 $ kubectl get pods -o wide
NAME       READY   STATUS    RESTARTS   AGE   IP            NODE                       NOMINATED NODE   READINESS GATES
nettools   1/1     Running   0          21m   10.240.0.48   aks-agentpool-35359625-1   <none>           <none>

/AKS/cluster1 $ az aks show -g $rg --name $cluster --query "networkProfile"
{
  "dnsServiceIp": "10.0.0.10",
  "dockerBridgeCidr": "172.17.0.1/16",
  "loadBalancerProfile": null,
  "loadBalancerSku": "Basic",
  "networkMode": "transparent",
  "networkPlugin": "azure",
  "networkPolicy": null,
  "outboundType": "UDR",
  "podCidr": null,
  "serviceCidr": "10.0.0.0/16"
}

你實際上不能這樣做,每次銷毀一個 Pod 並創建一個新 Pod 時,都會為其分配一個新的 IP。 Pod 是短暫的,它們的 IP 也是如此。

我相信要實現您正在尋找的東西,您需要使用服務。

Kubernetes 中的服務是“將在一組 Pod 上運行的應用程序公開為網絡服務的抽象方式”。 k8s 文檔

同樣,您可以通過其ZA12A3079E14CED46E6BA52B8A90B21AZ訪問POD和Z30136395F0187979792198317C11831EA4Z的端口和端口。你的應用程序上的一切都將開始失敗。

如果您公開您的 Deployment 或 Pod,則創建的 Service 也將具有 IP,並且無論您的 Pod 被銷毀多少次,因為您仍然可以通過 Service IP 訪問它(當然,當新的Pod 已啟動並正在運行,但我認為您明白了)。

您可以編輯 azure-ip-masq-agent configmap 以添加您不希望它被偽裝的目標私有 IP CIDR。

kubectl get pods --namespace kube-system -l "k8s-app=azure-ip-masq-agent" -o wide

kubectl describe configmap azure-ip-masq-agent-config --namespace kube-system

# Add x.x.x.x/x to the nonMasq CIDRs
kubectl edit configmap azure-ip-masq-agent-config --namespace kube-system

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM