K8S中headless service 的port的作用是什么
时间: 2024-05-22 12:15:02 浏览: 254
Headless Service 是 Kubernetes 中一种特殊的服务类型,其不会像普通的 Service 一样为每个 Pod 分配一个唯一的 Cluster IP,也不会创建任何代理,而是直接返回云原生服务的 DNS 记录。这种服务类型通常用于需要直接与 Pod 交互的场景,比如通过 Pod 的 IP 直接访问服务,或者实现自己的服务发现机制等。Port 的作用 mainly 是设置 Headless Service 的网络端口。
相关问题
K8S中headless service 的port指的是什么地方的端口
Headless Service 的端口指的是 Pod 的端口,而非 Service 自身的端口。当 Service 配置为 Headless 类型时,会直接将 Pod 的 IP 返回给客户端,而不是通过集群中的 Service IP 进行负载均衡访问。因此,客户端需要指定 Pod 的端口进行访问。
K8s handless service
Kubernetes (K8s) provides a way to create and manage services that abstract away the underlying pods and ensure that requests are routed to the appropriate pod instances. When creating a Kubernetes service, you can specify a label selector that identifies the pods that should be included in the service.
A headless service is a special type of Kubernetes service that does not provide a cluster IP address to clients. Instead, it returns the IP addresses of the individual pods that are part of the service. This can be useful for certain types of applications, such as those that require direct access to the individual pods, or those that need to perform custom load balancing.
To create a headless service in Kubernetes, you can simply set the `clusterIP` field to `None` in the service specification. For example:
```
apiVersion: v1
kind: Service
metadata:
name: my-headless-service
spec:
clusterIP: None
selector:
app: my-app
ports:
- name: http
port: 80
targetPort: 8080
```
This will create a headless service named `my-headless-service` that selects pods with the label `app: my-app`, exposes port 80, and maps it to port 8080 on the pods. When clients query the DNS name of the service, they will receive a list of IP addresses corresponding to the pods that match the label selector.
阅读全文