Class 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.

    • 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.
      • 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.

      • 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.