> For the complete documentation index, see [llms.txt](https://docs.cybus.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cybus.io/2-8-0/cybus-helm-charts/connectware-agent-helm-chart/service-ports.md). Agents can also search and read this documentation through its [MCP server](https://docs.cybus.io/~gitbook/mcp).

# Configuring Agent Service Ports for the connectware-agent Helm Chart

Configure the ports of the Kubernetes Service of an agent so that clients reach a server that runs in the agent.

The `connectware-agent` Helm chart creates one Kubernetes Service per agent. By default, this Service has the ports 443 and 8443. An agent that only connects to devices and to Connectware does not need more ports.

Some agents also run a server, for example a custom agent that accepts TCP connections on port 4840. To let clients in the same cluster connect, add the server port to the agent's Service with the `service.ports` Helm value.

For clients outside the cluster, see [Making an Agent Server Reachable Through Connectware](#making-an-agent-server-reachable-through-connectware).

{% hint style="info" %}
`service.ports` requires `connectware-agent` Helm chart 3.5.0 or later.
{% endhint %}

## Service Port Properties

Each entry in `service.ports` describes one port of the agent's Service.

| Property     | Type                  | Required     | Default | Description                                                        |
| ------------ | --------------------- | ------------ | ------- | ------------------------------------------------------------------ |
| `name`       | `string`              | **Required** |         | Name of the port. Use lowercase letters, digits, and hyphens.      |
| `port`       | `integer`             | **Required** |         | Port that the Service exposes.                                     |
| `targetPort` | `integer` or `string` | Optional     | `port`  | Port in the agent container that receives the traffic.             |
| `protocol`   | `string`              | Optional     | `TCP`   | Protocol of the port. Allowed values are `TCP`, `UDP`, and `SCTP`. |

## Default Service Ports

Without configuration, every agent Service has the following ports:

| `name`      | `port` | `targetPort` | `protocol` |
| ----------- | ------ | ------------ | ---------- |
| `https`     | 443    | 8443         | `TCP`      |
| `https-alt` | 8443   | 8443         | `TCP`      |

{% hint style="warning" %}
Ports 443 and 8443 come from the default value of `service.ports`. A `service.ports` list that you set replaces the default list completely, so to add port 4840, you set a list with 443, 8443, and 4840. If you leave out 443 and 8443, the Service no longer has them. Keep `targetPort: 8443` for port 443. The list must contain at least one port.
{% endhint %}

## Adding Ports for All Agents

To add a port to the Service of every agent, set `protocolMapperAgentDefaults.service.ports` in the `values.yaml` file of the `connectware-agent` Helm chart:

{% code title="values.yaml" lineNumbers="true" %}

```yaml
protocolMapperAgentDefaults:
  service:
    ports:
      - name: https
        port: 443
        targetPort: 8443
      - name: https-alt
        port: 8443
        targetPort: 8443
      - name: tcp-4840
        port: 4840
```

{% endcode %}

## Adding Ports for a Specific Agent

To add a port only to the Service of one agent, set `service.ports` for that agent in `protocolMapperAgents` in the `values.yaml` file of the `connectware-agent` Helm chart. The list of the agent replaces the list in `protocolMapperAgentDefaults`. Other agents keep the list from `protocolMapperAgentDefaults`, or the chart default if you did not set one.

{% code title="values.yaml" lineNumbers="true" %}

```yaml
protocolMapperAgents:
  - name: ${AGENT_NAME}
    # ...keep the existing configuration of the agent...
    service:
      ports:
        - name: https
          port: 443
          targetPort: 8443
        - name: https-alt
          port: 8443
          targetPort: 8443
        - name: tcp-4840
          port: 4840
```

{% endcode %}

Replace `${AGENT_NAME}` with the name of the agent.

## Applying the Change

Apply the change to the `connectware-agent` Helm chart:

{% code lineNumbers="true" %}

```bash
helm upgrade -n ${AGENT_NAMESPACE} ${AGENT_INSTALLATION_NAME} oci://repo.cybus.io/charts/connectware-agent \
  --version ${AGENT_CHART_VERSION} -f values.yaml
```

{% endcode %}

Replace the following placeholders:

* `${AGENT_NAMESPACE}` and `${AGENT_INSTALLATION_NAME}`: the namespace and name of your `connectware-agent` installation.
* `${AGENT_CHART_VERSION}`: the version of the `connectware-agent` Helm chart that you run, 3.5.0 or later. Without `--version`, Helm installs the latest chart version.

## Result

To check that the agent's Service has the new port, run the following command:

{% code lineNumbers="true" %}

```bash
kubectl get services -n ${AGENT_NAMESPACE}
```

{% endcode %}

The `PORT(S)` column of the agent's Service lists `4840/TCP`. The name of the agent's Service ends with the `name` of the agent in `protocolMapperAgents`. See [Controlling Kubernetes Object Names](https://docs.cybus.io/2-8-0/cybus-helm-charts/connectware-agent-helm-chart/kubernetes-object-names.md). If metrics are enabled, the list also shows a Service whose name ends with `-metrics`. Use the Service without this suffix.

Clients in the same cluster connect to the Service name and the port, for example `${AGENT_SERVICE_NAME}.${AGENT_NAMESPACE}:4840`. Replace `${AGENT_SERVICE_NAME}` with the name of the agent's Service.

## Making an Agent Server Reachable Through Connectware

Use this setup when clients outside the cluster need to reach the server in the agent.

A client connects to Connectware on an external port. connectware-ingress forwards the connection to a TCP port between 40000 and 40100, and a TCP [Cybus::IngressRoute](https://docs.cybus.io/2-8-0/data-flows/service-commissioning-files/resources/cybus-ingressroute.md) forwards that port to the agent's Service. This path forwards TCP only. `service.ports` also accepts `UDP` and `SCTP`, but connectware-ingress does not forward them, so keep `protocol: TCP`, the default.

The examples in this section use the following ports. The table shows where you set each one.

| Hop                                              | Port  | Where you set it                                                         |
| ------------------------------------------------ | ----- | ------------------------------------------------------------------------ |
| Client to Connectware                            | 4840  | `port` in `connectwareIngress.service.ports`                             |
| connectware-ingress to the `Cybus::IngressRoute` | 40001 | `targetPort` in `connectwareIngress.service.ports` and `connectwarePort` |
| `Cybus::IngressRoute` to the agent Service       | 4840  | `port` in the agent's `service.ports` and `containerPort`                |
| Agent Service to the agent container             | 4840  | `targetPort` in the agent's `service.ports`, which defaults to `port`    |

Before you start, make sure that you have the following:

* An agent installed with `connectware-agent` Helm chart 3.5.0 or later, in the same Kubernetes cluster as Connectware. The agent's Service is only reachable inside the cluster, so agents in a different cluster cannot use this setup.
* The server port on the agent's Service, as described in [Adding Ports for a Specific Agent](#adding-ports-for-a-specific-agent) and [Applying the Change](#applying-the-change).
* The `values.yaml` file of the `connectware` Helm chart. See [Extracting the values.yaml File](https://docs.cybus.io/pages/9eO61zn93AIRXNzCVc87#extracting-the-values.yaml-file).
* A port between 40000 and 40100 that no other TCP `Cybus::IngressRoute` uses. If two TCP routes use the same port, connectware-ingress forwards only one of them.

{% stepper %}
{% step %}

### Expose the Port on connectware-ingress

1. In the `values.yaml` file of the `connectware` Helm chart, add an entry to `connectwareIngress.service.ports`. Set `port` to the port that clients use, and `targetPort` to a port between 40000 and 40100. This list also replaces its defaults, so keep the existing entries. See [Configuring Exposed Ports](https://docs.cybus.io/2-8-0/cybus-helm-charts/connectware-helm-chart/load-balancer.md#configuring-exposed-ports).

{% code title="values.yaml" lineNumbers="true" %}

```yaml
connectwareIngress:
  service:
    ports:
      # ...keep the existing entries...
      - name: tcp-4840
        port: 4840
        targetPort: 40001
```

{% endcode %}

2. Apply the change to the `connectware` Helm chart. See [Applying Helm Configuration Changes](https://docs.cybus.io/2-8-0/cybus-helm-charts/working-with-cybus-helm-charts.md#applying-helm-configuration-changes).
   {% endstep %}

{% step %}

### Create the Ingress Route

1. In a service commissioning file, create a TCP `Cybus::IngressRoute` with the following properties:
   * `container`: the name of the agent's Service.
   * `containerPort`: the `port` of the agent's Service entry. If the entry has a different `targetPort`, use `port` anyway.
   * `connectwarePort`: the `targetPort` from the previous step.

{% code title="service-commissioning-file.yaml" lineNumbers="true" %}

```yaml
description: Forwards TCP port 4840 to a server in an agent

metadata:
  name: Agent Server Route
  version: 1.0.0

resources:
  agentServerRoute:
    type: Cybus::IngressRoute
    properties:
      type: tcp
      container: ${AGENT_SERVICE_NAME}
      containerPort: 4840
      connectwarePort: 40001
```

{% endcode %}

Replace `${AGENT_SERVICE_NAME}` with the name of the agent's Service, which you looked up in [Result](#result). If the agent runs in a different namespace from Connectware, append the namespace, as in `${AGENT_SERVICE_NAME}.${AGENT_NAMESPACE}`.

2. Install the service. See [Installing Services](https://docs.cybus.io/2-8-0/data-flows/services/managing/installing.md).
   {% endstep %}

{% step %}

### Connect a Client

Connect a client to `${CONNECTWARE_HOST}:4840`. Replace `${CONNECTWARE_HOST}` with the host name or IP address of your Connectware installation. If the client connects, the route works end to end.
{% endstep %}
{% endstepper %}

## Reference

For the full list of Helm values, see the [Helm Chart Reference](https://docs.cybus.io/2-8-0/reference/helm-chart-reference.md#connectware-agent-helm-chart-values-reference).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.cybus.io/2-8-0/cybus-helm-charts/connectware-agent-helm-chart/service-ports.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
