<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Headless Service VS ClusterIP :: Ay Docs</title>
    <link>https://ops.docs.72602.space/using/k8s/headless/index.html</link>
    <description>Headless Service vs ClusterIP 详解 这是 Kubernetes 中两种常见的 Service 类型,它们在服务发现和负载均衡方面有本质区别。&#xA;🎯 核心区别总结 维度 ClusterIP Headless Service ClusterIP 值 有固定的虚拟 IP None (无 ClusterIP) DNS 解析 返回 Service IP 直接返回 Pod IP 列表 负载均衡 ✅ kube-proxy 自动负载均衡 ❌ 客户端自行选择 Pod 适用场景 无状态服务 有状态服务、服务发现 典型用例 Web 应用、API 服务 数据库集群、Kafka、Zookeeper 📋 ClusterIP Service (默认类型) 定义 ClusterIP 是 Kubernetes 默认的 Service 类型,会分配一个虚拟 IP(Cluster IP),作为访问后端 Pod 的统一入口。&#xA;YAML 示例 apiVersion: v1 kind: Service metadata: name: my-web-service spec: type: ClusterIP # 默认类型,可以省略 selector: app: web ports: - protocol: TCP port: 80 # Service 端口 targetPort: 8080 # Pod 端口 工作原理 ┌─────────────────────────────────────────┐ │ ClusterIP Service │ │ (虚拟 IP: 10.96.100.50) │ └────────────┬────────────────────────────┘ │ kube-proxy 负载均衡 │ ┌───────┴───────┬──────────┐ ▼ ▼ ▼ Pod-1 Pod-2 Pod-3 10.244.1.5 10.244.2.8 10.244.3.12 (app=web) (app=web) (app=web) DNS 解析行为 # 在集群内部查询 DNS nslookup my-web-service.default.svc.cluster.local # 输出: # Name: my-web-service.default.svc.cluster.local # Address: 10.96.100.50 ← 返回 Service 的虚拟 IP # 客户端访问这个 IP curl http://my-web-service:80 # 请求会被 kube-proxy 自动转发到后端 Pod # 默认使用 iptables 或 IPVS 做负载均衡 特点 ✅ 统一入口:客户端只需知道 Service IP,不关心后端 Pod&#xA;✅ 自动负载均衡:kube-proxy 自动在多个 Pod 间分发流量&#xA;✅ 服务发现简单:通过 DNS 获取稳定的 Service IP&#xA;✅ 屏蔽 Pod 变化:Pod 重启或扩缩容,Service IP 不变&#xA;✅ 会话保持:可配置 sessionAffinity: ClientIP</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate></lastBuildDate>
    <atom:link href="https://ops.docs.72602.space/using/k8s/headless/index.xml" rel="self" type="application/rss+xml" />
  </channel>
</rss>