Skip to content

K8sService

K8sService creates a Kubernetes Service in the target cluster. Services provide stable network endpoints for pods, supporting internal cluster DNS, load-balanced access, and external exposure.

Property Type Required Description
port number Service port
targetPort number Pod port to route to (defaults to port)
protocol string Protocol (TCP, UDP, SCTP; defaults to TCP)
name string Port name (required for multi-port services)
nodePort number Static node port (for NodePort type)
Property Type Required Description
cluster KubernetesCluster | string Target cluster
namespace K8sNamespace | string Namespace to create the Service in
dependsOn string[] Explicit dependency ordering
serviceType 'ClusterIP' | 'NodePort' | 'LoadBalancer' | 'ExternalName' Service type (defaults to ClusterIP)
selector Record<string, string> Label selector for pod targeting
selectorRef K8sDeployment | K8sStatefulSet Reference to a Deployment or StatefulSet (auto-generates selector)
ports K8sServicePort[] Port mappings
// Using selectorRef to target a deployment
const apiService = new K8sService({
name: 'api',
cluster: myCluster,
namespace: myNamespace,
serviceType: 'ClusterIP',
selectorRef: apiDeployment,
ports: [
{ port: 80, targetPort: 8080, name: 'http' },
{ port: 443, targetPort: 8443, name: 'https' },
],
})
// External load balancer
const ingressGateway = new K8sService({
name: 'gateway',
cluster: myCluster,
serviceType: 'LoadBalancer',
selector: { app: 'gateway' },
ports: [{ port: 443, protocol: 'TCP', name: 'https' }],
})
Provider Supported
Kubernetes
Hetzner
DigitalOcean
AWS
GCP