Files
nexus/wiki/concepts/Host-Network-Mode.md

51 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Host Network Mode"
type: concept
tags:
- Kubernetes
- Networking
- Pod-Networking
- AWS
- EKS
sources:
- ctp-topic-39-implementing-eks-in-the-aws-lab-landing-zone
last_updated: 2026-04-28
---
## Overview
Host Network Mode 是 Kubernetes Pod 规范中的一种网络配置选项(`hostNetwork: true`),使 Pod 共享宿主机的网络命名空间,直接使用宿主机的网络接口和 IP 地址,而不是通过 Kubernetes 的虚拟网络。
## Definition
在 Pod spec 中设置 `hostNetwork: true`Pod 将:
- 使用宿主机的网络命名空间
- 直接获得宿主机网络接口上的 IP 地址
- 可以绑定宿主机的端口(如 80、443
- 可直接访问宿主机所在网络上的资源
## Use Case: EKS Lab Landing Zone
在 AWS Lab Landing Zone 的 EKS 部署中Octane 等 IP 密集型应用需要大量可用 IP。通过自定义网络模式Pod 无需通过 VPC CNI 分配 IP而是直接使用宿主机网络的 IP 地址,从而绕开 AWS Lab 环境 IP 地址池受限的问题。
```yaml
spec:
hostNetwork: true
containers:
- name: octane
image: octane:latest
```
## Trade-offs
| 优点 | 缺点 |
|------|------|
| 突破 Pod IP 数量限制 | Pod 之间端口冲突风险 |
| 直接访问宿主机网络资源 | 安全性降低Pod 可访问宿主机所有网络) |
| 简化网络路径 | 违反 Kubernetes 网络隔离原则 |
| 适合特殊网络需求场景 | 难以在不同环境中移植 |
## Related Concepts
- [[Amazon-EKS]]:使用 Host Network Mode 的容器编排平台
- [[IPAM]]IP 地址管理,与 Host Network Mode 在 IP 分配上形成互补
- [[Kubernetes-Tagging]]Pod 标记策略
## Related Sources
- [[ctp-topic-39-implementing-eks-in-the-aws-lab-landing-zone]]