Class Service
- java.lang.Object
-
- software.amazon.jsii.JsiiObject
-
- software.constructs.Construct
-
- org.cdk8s.plus20.Resource
-
- org.cdk8s.plus20.Service
-
- All Implemented Interfaces:
IResource,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct
@Generated(value="jsii-pacmak/1.55.1 (build 07d2d90)", date="2022-04-02T02:38:57.581Z") @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 classService.BuilderA fluent builder forService.-
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
-
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
-
Nested classes/interfaces inherited from interface org.cdk8s.plus20.IResource
IResource.Jsii$Default
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedService(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)protectedService(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 voidaddDeployment(Deployment deployment)Associate a deployment to this service.voidaddDeployment(Deployment deployment, AddDeploymentOptions options)Associate a deployment to this service.voidaddSelector(String label, String value)Services defined using this spec will select pods according the provided label.IngressV1Beta1exposeViaIngress(String path)Expose a service via an ingress using the specified path.IngressV1Beta1exposeViaIngress(String path, ExposeServiceViaIngressOptions options)Expose a service via an ingress using the specified path.protected org.cdk8s.ApiObjectgetApiObject()The underlying cdk8s API object.StringgetClusterIP()The IP address of the service and is usually assigned randomly by the master.StringgetExternalName()The externalName to be used for EXTERNAL_NAME types.List<ServicePort>getPorts()Ports for this service.Map<String,String>getSelector()Returns the labels which are used to select pods for this service.ServiceTypegetType()Determines how the Service is exposed.voidserve(Number port)Configure a port the service will bind to.voidserve(Number port, ServicePortOptions options)Configure a port the service will bind to.-
Methods inherited from class org.cdk8s.plus20.Resource
getMetadata, getName
-
Methods inherited from class software.constructs.Construct
onPrepare, onSynthesize, onValidate, toString
-
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
-
addDeployment
@Stability(Stable) public void addDeployment(@NotNull Deployment deployment, @Nullable AddDeploymentOptions options)Associate a deployment to this service.If not targetPort is specific in the portOptions, then requests will be routed to the port exposed by the first container in the deployment's pods. The deployment's
labelSelectorwill be used to select pods.- Parameters:
deployment- The deployment to expose. This parameter is required.options- Optional settings for the port.
-
addDeployment
@Stability(Stable) public void addDeployment(@NotNull Deployment deployment)Associate a deployment to this service.If not targetPort is specific in the portOptions, then requests will be routed to the port exposed by the first container in the deployment's pods. The deployment's
labelSelectorwill be used to select pods.- Parameters:
deployment- The deployment to expose. This parameter is required.
-
addSelector
@Stability(Stable) public void addSelector(@NotNull String label, @NotNull String value)Services defined using this spec will select pods according the provided label.- Parameters:
label- The label key. This parameter is required.value- The label value. This parameter is required.
-
exposeViaIngress
@Stability(Stable) @NotNull public IngressV1Beta1 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 IngressV1Beta1 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.
-
serve
@Stability(Stable) public void serve(@NotNull Number port, @Nullable ServicePortOptions 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-
-
serve
@Stability(Stable) public void serve(@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.
-
getApiObject
@Stability(Stable) @NotNull protected org.cdk8s.ApiObject getApiObject()
The underlying cdk8s API object.- Specified by:
getApiObjectin classResource- See Also:
base.Resource.apiObject
-
getPorts
@Stability(Stable) @NotNull public List<ServicePort> getPorts()
Ports for this service.Use
serve()to expose additional service ports.
-
getSelector
@Stability(Stable) @NotNull public Map<String,String> getSelector()
Returns the labels which are used to select pods for this service.
-
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.
-
-