import { Construct } from 'constructs'; import { ResourceProps, Resource } from './base'; import * as cdk8s from 'cdk8s'; import { Deployment } from './deployment'; /** * (experimental) Properties for initialization of `Service`. * * @experimental */ export interface ServiceProps extends ResourceProps { /** * (experimental) The IP address of the service and is usually assigned randomly by the master. * * If an address is specified manually and is not in use by others, it * will be allocated to the service; otherwise, creation of the service will * fail. This field can not be changed through updates. Valid values are * "None", empty string (""), or a valid IP address. "None" can be specified * for headless services when proxying is not required. Only applies to types * ClusterIP, NodePort, and LoadBalancer. Ignored if type is ExternalName. * * @default - Automatically assigned. * @see https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies * @experimental */ readonly clusterIP?: string; /** * (experimental) A list of IP addresses for which nodes in the cluster will also accept traffic for this service. * * These IPs are not managed by Kubernetes. The user * is responsible for ensuring that traffic arrives at a node with this IP. A * common example is external load-balancers that are not part of the * Kubernetes system. * * @default - No external IPs. * @experimental */ readonly externalIPs?: string[]; /** * (experimental) Determines how the Service is exposed. * * More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types * * @default ServiceType.ClusterIP * @experimental */ readonly type?: ServiceType; /** * (experimental) The port exposed by this service. * * More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies * * @experimental */ readonly ports?: ServicePort[]; } /** * (experimental) 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 is ClusterIP. * * @experimental */ export declare enum ServiceType { /** * (experimental) Exposes the Service on a cluster-internal IP. * * Choosing this value makes the Service only reachable from within the cluster. * This is the default ServiceType * * @experimental */ CLUSTER_IP = "ClusterIP", /** * (experimental) Exposes the Service on each Node's IP at a static port (the NodePort). * * A ClusterIP Service, to which the NodePort Service routes, is automatically created. * You'll be able to contact the NodePort Service, from outside the cluster, * by requesting :. * * @experimental */ NODE_PORT = "NodePort", /** * (experimental) Exposes the Service externally using a cloud provider's load balancer. * * NodePort and ClusterIP Services, to which the external load balancer routes, * are automatically created. * * @experimental */ LOAD_BALANCER = "LoadBalancer", /** * (experimental) Maps the Service to the contents of the externalName field (e.g. foo.bar.example.com), by returning a CNAME record with its value. No proxying of any kind is set up. * * > Note: You need either kube-dns version 1.7 or CoreDNS version 0.0.8 or higher to use the ExternalName type. * * @experimental */ EXTERNAL_NAME = "ExternalName" } /** * (experimental) 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. * * @experimental */ export declare class Service extends Resource { /** * (experimental) The IP address of the service and is usually assigned randomly by the master. * * @experimental */ readonly clusterIP?: string; /** * (experimental) Determines how the Service is exposed. * * @experimental */ readonly type: ServiceType; /** * (experimental) The underlying cdk8s API object. * * @see base.Resource.apiObject * @experimental */ protected readonly apiObject: cdk8s.ApiObject; private readonly _externalIPs; private readonly _selector; private readonly _ports; /** * @experimental */ constructor(scope: Construct, id: string, props?: ServiceProps); /** * (experimental) Returns the labels which are used to select pods for this service. * * @experimental */ get selector(): Record; /** * (experimental) Ports for this service. * * Use `serve()` to expose additional service ports. * * @experimental */ get ports(): ServicePort[]; /** * (experimental) Associate a deployment to this service. * * 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. * * @param deployment The deployment to expose. * @param port The external port. * @experimental */ addDeployment(deployment: Deployment, port: number): void; /** * (experimental) Services defined using this spec will select pods according the provided label. * * @param label The label key. * @param value The label value. * @experimental */ addSelector(label: string, value: string): void; /** * (experimental) Configure a port the service will bind to. * * This method can be called multiple times. * * @param port The port definition. * @experimental */ serve(port: number, options?: ServicePortOptions): void; } /** * @experimental */ export declare enum Protocol { /** * @experimental */ TCP = "TCP", /** * @experimental */ UDP = "UDP", /** * @experimental */ SCTP = "SCTP" } /** * @experimental */ export interface ServicePortOptions { /** * (experimental) The name of this port within the service. * * This must be a DNS_LABEL. All * ports within a ServiceSpec must have unique names. This maps to the 'Name' * field in EndpointPort objects. Optional if only one ServicePort is defined * on this service. * * @experimental */ readonly name?: string; /** * (experimental) The port on each node on which this service is exposed when type=NodePort or LoadBalancer. * * Usually assigned by the system. If specified, it will be * allocated to the service if unused or else creation of the service will * fail. Default is to auto-allocate a port if the ServiceType of this Service * requires one. * * @default to auto-allocate a port if the ServiceType of this Service * requires one. * @see https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport * @experimental */ readonly nodePort?: number; /** * (experimental) The IP protocol for this port. * * Supports "TCP", "UDP", and "SCTP". Default is TCP. * * @default Protocol.TCP * @experimental */ readonly protocol?: Protocol; /** * (experimental) The port number the service will redirect to. * * @default - The value of `port` will be used. * @experimental */ readonly targetPort?: number; } /** * (experimental) Definition of a service port. * * @experimental */ export interface ServicePort extends ServicePortOptions { /** * (experimental) The port number the service will bind to. * * @experimental */ readonly port: number; }