@Generated(value="jsii-pacmak/1.41.0 (build a274beb)", date="2021-10-28T21:51:42.912Z") @Stability(value=Stable) public class Service extends Resource
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
Service.Builder
A fluent builder for
Service. |
software.amazon.jsii.JsiiObject.InitializationModeIResource.Jsii$Default| Modifier | Constructor and Description |
|---|---|
|
Service(software.constructs.Construct scope,
String id) |
|
Service(software.constructs.Construct scope,
String id,
ServiceProps props) |
protected |
Service(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) |
protected |
Service(software.amazon.jsii.JsiiObjectRef objRef) |
| Modifier and Type | Method and Description |
|---|---|
void |
addDeployment(Deployment deployment)
Associate a deployment to this service.
|
void |
addDeployment(Deployment deployment,
AddDeploymentOptions options)
Associate a deployment to this service.
|
void |
addSelector(String label,
String value)
Services defined using this spec will select pods according the provided label.
|
IngressV1Beta1 |
exposeViaIngress(String path)
Expose a service via an ingress using the specified path.
|
IngressV1Beta1 |
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.
|
List<ServicePort> |
getPorts()
Ports for this service.
|
Map<String,String> |
getSelector()
Returns the labels which are used to select pods for this service.
|
ServiceType |
getType()
Determines how the Service is exposed.
|
void |
serve(Number port)
Configure a port the service will bind to.
|
void |
serve(Number port,
ServicePortOptions options)
Configure a port the service will bind to.
|
getMetadata, getNameonPrepare, onSynthesize, onValidate, toStringjsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetprotected Service(software.amazon.jsii.JsiiObjectRef objRef)
protected Service(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
@Stability(value=Stable)
public Service(@NotNull
software.constructs.Construct scope,
@NotNull
String id,
@Nullable
ServiceProps props)
scope - This parameter is required.id - This parameter is required.props - @Stability(value=Stable)
public Service(@NotNull
software.constructs.Construct scope,
@NotNull
String id)
scope - This parameter is required.id - This parameter is required.@Stability(value=Stable)
public void addDeployment(@NotNull
Deployment deployment,
@Nullable
AddDeploymentOptions options)
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 labelSelector will be used to select pods.
deployment - The deployment to expose. This parameter is required.options - Optional settings for the port.@Stability(value=Stable)
public void addDeployment(@NotNull
Deployment deployment)
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 labelSelector will be used to select pods.
deployment - The deployment to expose. This parameter is required.@Stability(value=Stable)
public void addSelector(@NotNull
String label,
@NotNull
String value)
label - The label key. This parameter is required.value - The label value. This parameter is required.@Stability(value=Stable) @NotNull public IngressV1Beta1 exposeViaIngress(@NotNull String path, @Nullable ExposeServiceViaIngressOptions options)
path - The path to expose the service under. This parameter is required.options - Additional options.@Stability(value=Stable) @NotNull public IngressV1Beta1 exposeViaIngress(@NotNull String path)
path - The path to expose the service under. This parameter is required.@Stability(value=Stable)
public void serve(@NotNull
Number port,
@Nullable
ServicePortOptions options)
This method can be called multiple times.
port - The port definition. This parameter is required.options - @Stability(value=Stable)
public void serve(@NotNull
Number port)
This method can be called multiple times.
port - The port definition. This parameter is required.@Stability(value=Stable) @NotNull protected org.cdk8s.ApiObject getApiObject()
getApiObject in class Resourcebase.Resource.apiObject@Stability(value=Stable) @NotNull public List<ServicePort> getPorts()
Use serve() to expose additional service ports.
@Stability(value=Stable) @NotNull public Map<String,String> getSelector()
@Stability(value=Stable) @NotNull public ServiceType getType()
@Stability(value=Stable) @Nullable public String getClusterIP()
@Stability(value=Stable) @Nullable public String getExternalName()
Copyright © 2021. All rights reserved.