【问题标题】:How to preserve pod IP address for egress traffic in AKS?如何为 AKS 中的出口流量保留 pod IP 地址?
【发布时间】:2020-04-19 03:32:47
【问题描述】:

在 Azure Kubernetes (AKS) 中,如果 pod 将流量发送到集群之外,它会被 Natted 到节点 IP 地址。例如,如果 pod nettools(来自节点 aks-agentpool-35359625-1)将流量发送到集群外部的 Azure 目标,它会被 natted 到 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"
}

【问题讨论】:

  • 为什么?有什么意义?
  • 简短答案 - 用于故障排除。
  • 这对故障排除有何帮助? xyproblem.info
  • 它将消除 NAT。

标签: azure kubernetes


【解决方案1】:

您可以编辑 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

【讨论】:

    【解决方案2】:

    你实际上不能这样做,每次销毁一个 Pod 并创建一个新 Pod 时,都会为其分配一个新 IP。 Pod 是短暂的,它们的 IP 也是如此。

    我相信要实现您的目标,您需要使用服务。

    Kubernetes 中的服务是一种“将在一组 Pod 上运行的应用程序公开为网络服务的抽象方式”。 (k8s documentation)

    同样,您可以通过 Kubernetes 提供给它的 IP 和端口访问您的 pod,但这不是一个好的做法,因为 Pod 可能会死掉,并且会创建另一个(如果由 Deployment/ReplicaSet 控制)新 IP,您的应用程序上的所有内容都将开始失败。

    如果您公开您的 Deployment 或 Pod,则创建的 Service 也会有一个 IP,并且无论您的 Pod 被销毁多少次,因为您仍然可以通过 Service IP 访问它(当然当新 Pod 启动并运行时,但我想你明白了)。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-11
    • 2018-05-23
    • 2015-09-08
    • 2014-07-05
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多