Class Service
- java.lang.Object
-
- software.amazon.jsii.JsiiObject
-
- software.constructs.Construct
-
- org.cdk8s.plus24.Resource
-
- org.cdk8s.plus24.Service
-
- All Implemented Interfaces:
IApiEndpoint
,IApiResource
,IResource
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
,software.constructs.IDependable
@Generated(value="jsii-pacmak/1.72.0 (build 4b8828b)", date="2022-12-15T15:42:36.435Z") @Stability(Stable) public class Service extends Resource
An abstract way to expose an application running on a set of Pods as a network service.With Kubernetes you don't need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.
For example, consider a stateless image-processing backend which is running with 3 replicas. Those replicas are fungible—frontends do not care which backend they use. While the actual Pods that compose the backend set may change, the frontend clients should not need to be aware of that, nor should they need to keep track of the set of backends themselves. The Service abstraction enables this decoupling.
If you're able to use Kubernetes APIs for service discovery in your application, you can query the API server for Endpoints, that get updated whenever the set of Pods in a Service changes. For non-native applications, Kubernetes offers ways to place a network port or load balancer in between your application and the backend Pods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Service.Builder
A fluent builder forService
.-
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
-
Nested classes/interfaces inherited from interface org.cdk8s.plus24.IApiEndpoint
IApiEndpoint.Jsii$Default
-
Nested classes/interfaces inherited from interface org.cdk8s.plus24.IApiResource
IApiResource.Jsii$Default
-
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
-
Nested classes/interfaces inherited from interface org.cdk8s.plus24.IResource
IResource.Jsii$Default
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Service(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
protected
Service(software.amazon.jsii.JsiiObjectRef objRef)
Service(software.constructs.Construct scope, String id)
Service(software.constructs.Construct scope, String id, ServiceProps props)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind(Number port)
Configure a port the service will bind to.void
bind(Number port, ServiceBindOptions options)
Configure a port the service will bind to.Ingress
exposeViaIngress(String path)
Expose a service via an ingress using the specified path.Ingress
exposeViaIngress(String path, ExposeServiceViaIngressOptions options)
Expose a service via an ingress using the specified path.protected org.cdk8s.ApiObject
getApiObject()
The underlying cdk8s API object.String
getClusterIP()
The IP address of the service and is usually assigned randomly by the master.String
getExternalName()
The externalName to be used for EXTERNAL_NAME types.Number
getPort()
Return the first port of the service.List<ServicePort>
getPorts()
Ports for this service.String
getResourceType()
The name of a resource type as it appears in the relevant API endpoint.ServiceType
getType()
Determines how the Service is exposed.void
select(IPodSelector selector)
Require this service to select pods matching the selector.void
selectLabel(String key, String value)
Require this service to select pods with this label.-
Methods inherited from class org.cdk8s.plus24.Resource
asApiResource, asNonApiResource, getApiGroup, getApiVersion, getKind, getMetadata, getName, getPermissions, getResourceName
-
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
-
-
-
-
Constructor Detail
-
Service
protected Service(software.amazon.jsii.JsiiObjectRef objRef)
-
Service
protected Service(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
-
Service
@Stability(Stable) public Service(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable ServiceProps props)
- Parameters:
scope
- This parameter is required.id
- This parameter is required.props
-
-
Service
@Stability(Stable) public Service(@NotNull software.constructs.Construct scope, @NotNull String id)
- Parameters:
scope
- This parameter is required.id
- This parameter is required.
-
-
Method Detail
-
bind
@Stability(Stable) public void bind(@NotNull Number port, @Nullable ServiceBindOptions options)
Configure a port the service will bind to.This method can be called multiple times.
- Parameters:
port
- The port definition. This parameter is required.options
-
-
bind
@Stability(Stable) public void bind(@NotNull Number port)
Configure a port the service will bind to.This method can be called multiple times.
- Parameters:
port
- The port definition. This parameter is required.
-
exposeViaIngress
@Stability(Stable) @NotNull public Ingress exposeViaIngress(@NotNull String path, @Nullable ExposeServiceViaIngressOptions options)
Expose a service via an ingress using the specified path.- Parameters:
path
- The path to expose the service under. This parameter is required.options
- Additional options.- Returns:
- The `Ingress` resource that was used.
-
exposeViaIngress
@Stability(Stable) @NotNull public Ingress exposeViaIngress(@NotNull String path)
Expose a service via an ingress using the specified path.- Parameters:
path
- The path to expose the service under. This parameter is required.- Returns:
- The `Ingress` resource that was used.
-
select
@Stability(Stable) public void select(@NotNull IPodSelector selector)
Require this service to select pods matching the selector.Note that invoking this method multiple times acts as an AND operator on the resulting labels.
- Parameters:
selector
- This parameter is required.
-
selectLabel
@Stability(Stable) public void selectLabel(@NotNull String key, @NotNull String value)
Require this service to select pods with this label.Note that invoking this method multiple times acts as an AND operator on the resulting labels.
- Parameters:
key
- This parameter is required.value
- This parameter is required.
-
getApiObject
@Stability(Stable) @NotNull protected org.cdk8s.ApiObject getApiObject()
The underlying cdk8s API object.- Specified by:
getApiObject
in classResource
- See Also:
- base.Resource.apiObject
-
getPort
@Stability(Stable) @NotNull public Number getPort()
Return the first port of the service.
-
getPorts
@Stability(Stable) @NotNull public List<ServicePort> getPorts()
Ports for this service.Use
bind()
to bind additional service ports.
-
getResourceType
@Stability(Stable) @NotNull public String getResourceType()
The name of a resource type as it appears in the relevant API endpoint.- Specified by:
getResourceType
in interfaceIApiResource
- Specified by:
getResourceType
in classResource
- See Also:
- https://kubernetes.io/docs/reference/access-authn-authz/rbac/#referring-to-resources
-
getType
@Stability(Stable) @NotNull public ServiceType getType()
Determines how the Service is exposed.
-
getClusterIP
@Stability(Stable) @Nullable public String getClusterIP()
The IP address of the service and is usually assigned randomly by the master.
-
getExternalName
@Stability(Stable) @Nullable public String getExternalName()
The externalName to be used for EXTERNAL_NAME types.
-
-