Service (Internal Traffic)
In short, there are three things you need to know:
- Containers in the same component will be started within a Kubernetes pod which allows these containers to communicate via
localhost. - If you want containers to communicate across components (cluster-internal traffic), you need to define services for these components.
- If you want to connect a domain to a service (external internet traffic), you need to configure an ingress for this service.
To allow other containers to access this component within the cluster-internal network (2.), you can configure the service section for the component:
containers:- image: dscr.io/${DEVSPACE_USERNAME}/databaseservice: ports: - port: 3000Now, the component is accessible via:
[HELM_RELEASE_NAME]:3000 # e.g. database:3000ports
The ports option is mandatory and expects an array of port definitions.
port
The port option is mandatory and expect an integer with a port number. The service will be available on this port.
containerPort
The containerPort option is optional and tells the service to forward the traffic from the service port (defined in port) to a different containerPort of a pod.
Default for containerPort
containerPort: [same as `port` option]name
The name option is optional and allows you to customize the name of the port.
Default for name
By default the port name will be "port-0", "port-1" etc.
name: port-0nodePort
The nodePort option is optional and tells the service to expose the service at a static node port.
Applicable to NodePort service type.
protocol
The protocol option is optional and expects a string that defines the network protocol for this service port.
Default for protocol
protocol: TCPtype
The type option is optional and expects a string that defines the type of the service.
Default for type
type: ClusterIPexternalIPs
The externalIPs option is optional and expects an array of IP addresses for the service.
name
The name option is optional and expects a string that defines the name of the service.
Default for name
name: [HELM_RELEASE_NAME]labels
The labels option is optional and expects an array of additional Kubernetes labels for the service.
annotations
The annotations option is optional and expects an array of additional Kubernetes annotations for the service.