How to explicitely define an Endpoint of an Kubernetes Service
I am not exactly sure if what You mean but i think what You are looking for is ability to expose services externally.
You can expose Your services like Rook/Ceph Dashboard with "Publishing Services" (service types that expose internal services externally).
As quoted from kubernetes documentation:
For some parts of your application (for example, frontends) you may want to expose a Service onto an external IP address, that’s outside of your cluster.
Kubernetes
ServiceTypes
allow you to specify what kind of Service you want. The default isClusterIP
.
Type
values and their behaviors are:
ClusterIP
: Exposes the Service on a cluster-internal IP. Choosing this value makes the Service only reachable from within the cluster. This is the defaultServiceType
.NodePort
: Exposes the Service on each Node’s IP at a static port (theNodePort
). AClusterIP
Service, to which theNodePort
Service routes, is automatically created. You’ll be able to contact theNodePort
Service, from outside the cluster, by requesting<NodeIP>:<NodePort>
.LoadBalancer
: Exposes the Service externally using a cloud provider’s load balancer.NodePort
andClusterIP
Services, to which the external load balancer routes, are automatically created.ExternalName
: Maps the Service to the contents of theexternalName
field (e.g.foo.bar.example.com
), by returning aCNAME
record with its value. No proxying of any kind is set up.
Here is an example from documentation.
You can also define the Services
with yaml manifests like this:
apiVersion: v1kind: Servicemetadata: name: examplelbspec: type: LoadBalancer selector: app: asd ports: - name: koala port: 22223 targetPort: 22225 nodePort: 31913 - name: grisly port: 22224 targetPort: 22226 nodePort: 31914 - name: polar port: 22225 targetPort: 22227 nodePort: 31915
This makes pods with label: app: asd
have following ports exposed with patterninternal port 22223
exposed on 31913
.
$ kubectl get svc examplelbNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEexamplelb LoadBalancer 10.111.8.204 <pending> 22223:31913/TCP,22224:31914/TCP,22225:31915/TCP 7d2h
If service with type LoadBalancer
has External-IP pending you can still access all those ports on each node as NodePort
.
Hope this helps.
I'll refer to your question:
How is it possible to define my own endpoint?
You'll have to:
1 ) Create a Service without a Pod selector:
apiVersion: v1kind: Servicemetadata: name: my-servicespec: ports: - protocol: TCP port: 8080 targetPort: 9376
(At this point, no auto-generated Endpoints will be created by K8S because it can't decide to which pods those Endpoints should be referring).
2 ) Crate an Endpoints
object and map it to the desired network address and port where the external resource is running:
apiVersion: v1kind: Endpointsmetadata: name: my-servicesubsets: - addresses: - ip: 192.0.2.45 ports: - port: 9376
(*) Notice that there should be a match between the service name and the name of the Endpoints object.