Skip to content

Kubernetes Endpoints Object

The Endpoints object (often abbreviated as Endpoints) is a Kubernetes resource that represents a list of network endpoints—specifically IP addresses and ports—that implement a [[Kubernetes Services|Service]].^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md]

This resource is fundamentally defined by its API version v1 and kind Endpoints.^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md] Its primary function is to act as a bridge between a Service definition and the actual network locations of the Pods or external resources that handle the traffic.

Structure and Fields

The core data structure of an Endpoints object consists of subsets.^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md] Each subset contains a list of network addresses, composed of the following key fields:

  • addresses: A list of IP addresses (e.g., 114.32.146.154) pointing to the targets.^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md]
  • ports: A list of port definitions that map the service port to the target port, including the protocol (e.g., TCP) and the port number (e.g., 3306).^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md]

Use Cases

Introducing External Services

Endpoints are crucial for integrating external services (such as an external database) into the Kubernetes cluster network.^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md] This pattern is typically implemented using a [[Headless Service]] (a Service with clusterIP: None).

In this scenario: 1. A Service is defined without a selector and with clusterIP: None.^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md] 2. A separate Endpoints object with a matching name is created manually to point to the external IP address.^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md] 3. This allows internal Pods to access the external resource using the standard Kubernetes DNS naming convention (e.g., service-name.namespace.svc.cluster.local).^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md]

Example

The following configuration demonstrates a Headless Service and a corresponding Endpoints object used to expose an external MySQL instance:

apiVersion: v1
kind: Service
metadata:
  name: mysql-svc
  namespace: default
spec:
  clusterIP: None
  ports:
    - name: default-ep
      port: 3306
      protocol: TCP
      targetPort: 3306
  type: ClusterIP
---
apiVersion: v1
kind: Endpoints
metadata:
  name: mysql-ep
  namespace: default
subsets:
  - addresses:
      - ip: 114.32.146.154
    ports:
      - name: mysql
        port: 3306
        protocol: TCP
^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md]

  • [[Kubernetes Services]]
  • [[Headless Service]]
  • Kubernetes

Sources

^[400-devops__06-Kubernetes__out-network__k8s中引入外部服务.md]