Endpoints

简要概述

属于组:“corev1”

{Group: corev1.GroupName, Kind: "Endpoints"}

代码路径:

staging/src/k8s.io/api/core/v1/types.go

当一个 POD 发生重启时,如果是 Endpoint 资源,它在 etcd 中的结构是一整块数据,则需全量更新,如果是 EndpointSlice 资源,则仅更新其中一小块,因为它在 etcd 中是分成几块内容。

配置示例

apiVersion: v1
kind: Endpoints
metadata:
  name: platform-mysql
  namespace: biz-prod-qe2bu3
subsets:
- addresses:
  - ip: 172.27.2.78
  - ip: 172.27.2.79
  - ip: 172.27.2.80
  ports:
  - port: 6033

数据结构

Endpoints

staging/src/k8s.io/api/core/v1/types.go
// Endpoints is a collection of endpoints that implement the actual service. Example:
//   Name: "mysvc",
//   Subsets: [
//     {
//       Addresses: [{"ip": "10.10.1.1"}, {"ip": "10.10.2.2"}],
//       Ports: [{"name": "a", "port": 8675}, {"name": "b", "port": 309}]
//     },
//     {
//       Addresses: [{"ip": "10.10.3.3"}],
//       Ports: [{"name": "a", "port": 93}, {"name": "b", "port": 76}]
//     },
//  ]
type Endpoints struct {
    metav1.TypeMeta `json:",inline"`
    // Standard object's metadata.
    // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    // +optional
    metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

    // The set of all endpoints is the union of all subsets. Addresses are placed into
    // subsets according to the IPs they share. A single address with multiple ports,
    // some of which are ready and some of which are not (because they come from
    // different containers) will result in the address being displayed in different
    // subsets for the different ports. No address will appear in both Addresses and
    // NotReadyAddresses in the same subset.
    // Sets of addresses and ports that comprise a service.
    // +optional
    Subsets []EndpointSubset `json:"subsets,omitempty" protobuf:"bytes,2,rep,name=subsets"`
}

EndpointSubset

staging/src/k8s.io/api/core/v1/types.go
// EndpointSubset is a group of addresses with a common set of ports. The
// expanded set of endpoints is the Cartesian product of Addresses x Ports.
// For example, given:
//   {
//     Addresses: [{"ip": "10.10.1.1"}, {"ip": "10.10.2.2"}],
//     Ports:     [{"name": "a", "port": 8675}, {"name": "b", "port": 309}]
//   }
// The resulting set of endpoints can be viewed as:
//     a: [ 10.10.1.1:8675, 10.10.2.2:8675 ],
//     b: [ 10.10.1.1:309, 10.10.2.2:309 ]
type EndpointSubset struct {
    // IP addresses which offer the related ports that are marked as ready. These endpoints
    // should be considered safe for load balancers and clients to utilize.
    // +optional
    Addresses []EndpointAddress `json:"addresses,omitempty" protobuf:"bytes,1,rep,name=addresses"`
    // IP addresses which offer the related ports but are not currently marked as ready
    // because they have not yet finished starting, have recently failed a readiness check,
    // or have recently failed a liveness check.
    // +optional
    NotReadyAddresses []EndpointAddress `json:"notReadyAddresses,omitempty" protobuf:"bytes,2,rep,name=notReadyAddresses"`
    // Port numbers available on the related IP addresses.
    // +optional
    Ports []EndpointPort `json:"ports,omitempty" protobuf:"bytes,3,rep,name=ports"`
}

EndpointAddress

staging/src/k8s.io/api/core/v1/types.go
// EndpointAddress is a tuple that describes single IP address.
// +structType=atomic
type EndpointAddress struct {
    // The IP of this endpoint.
    // May not be loopback (127.0.0.0/8), link-local (169.254.0.0/16),
    // or link-local multicast ((224.0.0.0/24).
    // IPv6 is also accepted but not fully supported on all platforms. Also, certain
    // kubernetes components, like kube-proxy, are not IPv6 ready.
    // TODO: This should allow hostname or IP, See #4447.
    IP string `json:"ip" protobuf:"bytes,1,opt,name=ip"`
    // The Hostname of this endpoint
    // +optional
    Hostname string `json:"hostname,omitempty" protobuf:"bytes,3,opt,name=hostname"`
    // Optional: Node hosting this endpoint. This can be used to determine endpoints local to a node.
    // +optional
    NodeName *string `json:"nodeName,omitempty" protobuf:"bytes,4,opt,name=nodeName"`
    // Reference to object providing the endpoint.
    // +optional
    TargetRef *ObjectReference `json:"targetRef,omitempty" protobuf:"bytes,2,opt,name=targetRef"`
}

EndpointPort

staging/src/k8s.io/api/core/v1/types.go
// EndpointPort is a tuple that describes a single port.
// +structType=atomic
type EndpointPort struct {
    // The name of this port.  This must match the 'name' field in the
    // corresponding ServicePort.
    // Must be a DNS_LABEL.
    // Optional only if one port is defined.
    // +optional
    Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`

    // The port number of the endpoint.
    Port int32 `json:"port" protobuf:"varint,2,opt,name=port"`

    // The IP protocol for this port.
    // Must be UDP, TCP, or SCTP.
    // Default is TCP.
    // +optional
    Protocol Protocol `json:"protocol,omitempty" protobuf:"bytes,3,opt,name=protocol,casttype=Protocol"`

    // The application protocol for this port.
    // This field follows standard Kubernetes label syntax.
    // Un-prefixed names are reserved for IANA standard service names (as per
    // RFC-6335 and http://www.iana.org/assignments/service-names).
    // Non-standard protocols should use prefixed names such as
    // mycompany.com/my-custom-protocol.
    // +optional
    AppProtocol *string `json:"appProtocol,omitempty" protobuf:"bytes,4,opt,name=appProtocol"`
}

Protocol

// Protocol defines network protocols supported for things like container ports.
type Protocol string

const (
    // ProtocolTCP is the TCP protocol.
    ProtocolTCP Protocol = "TCP"
    // ProtocolUDP is the UDP protocol.
    ProtocolUDP Protocol = "UDP"
    // ProtocolSCTP is the SCTP protocol.
    ProtocolSCTP Protocol = "SCTP"
)

ObjectReference

// ObjectReference contains enough information to let you inspect or modify the referred object.
// ---
// New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs.
//  1. Ignored fields.  It includes many fields which are not generally honored.  For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage.
//  2. Invalid usage help.  It is impossible to add specific help for individual usage.  In most embedded usages, there are particular
//     restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted".
//     Those cannot be well described when embedded.
//  3. Inconsistent validation.  Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen.
//  4. The fields are both imprecise and overly precise.  Kind is not a precise mapping to a URL. This can produce ambiguity
//     during interpretation and require a REST mapping.  In most cases, the dependency is on the group,resource tuple
//     and the version of the actual struct is irrelevant.
//  5. We cannot easily change it.  Because this type is embedded in many locations, updates to this type
//     will affect numerous schemas.  Don't make new APIs embed an underspecified API type they do not control.
// Instead of using this type, create a locally provided and used type that is well-focused on your reference.
// For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 .
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +structType=atomic
type ObjectReference struct {
    // Kind of the referent.
    // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
    // +optional
    Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"`
    // Namespace of the referent.
    // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
    // +optional
    Namespace string `json:"namespace,omitempty" protobuf:"bytes,2,opt,name=namespace"`
    // Name of the referent.
    // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
    // +optional
    Name string `json:"name,omitempty" protobuf:"bytes,3,opt,name=name"`
    // UID of the referent.
    // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids
    // +optional
    UID types.UID `json:"uid,omitempty" protobuf:"bytes,4,opt,name=uid,casttype=k8s.io/apimachinery/pkg/types.UID"`
    // API version of the referent.
    // +optional
    APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,5,opt,name=apiVersion"`
    // Specific resourceVersion to which this reference is made, if any.
    // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency
    // +optional
    ResourceVersion string `json:"resourceVersion,omitempty" protobuf:"bytes,6,opt,name=resourceVersion"`

    // If referring to a piece of an object instead of an entire object, this string
    // should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2].
    // For example, if the object reference is to a container within a pod, this would take on a value like:
    // "spec.containers{name}" (where "name" refers to the name of the container that triggered
    // the event) or if no container name is specified "spec.containers[2]" (container with
    // index 2 in this pod). This syntax is chosen only to have some well-defined way of
    // referencing a part of an object.
    // TODO: this design is not final and this field is subject to change in the future.
    // +optional
    FieldPath string `json:"fieldPath,omitempty" protobuf:"bytes,7,opt,name=fieldPath"`
}



最后修改 2023.02.01: feat: 更新目录结构 (c2ad751)