CLI Service Ports
Overview
One feature of running Edge Xpert in secure mode is that the ports of each microservice are not available for direct access by default.
If the user wishes to expose specific microservice ports for direct access, this can be supported by following one of the below methods.
Accessing the Services through the Container IP Address (Recommended)
After deploying Edge Xpert with edgexpert up --api-gateway
, you can look up the IP address of the specified service and test it using curl commands or API tools.
An example usage of this is to check if the core-data
is accessible.
You can look up specific service's port number by checking /etc/edgexpert/docker-compose-port-mapping.yml.
$ edgexpert up --api-gateway
$ edgexpert ip | grep core-data
Name |IP
---------------------------------------------
core-data |192.168.96.10
$ curl http://192.168.96.10:59880/api/v2/ping
{"apiVersion":"v2","timestamp":"Wed Oct 19 10:36:24 CST 2022","serviceName":"core-data"}
Since Podman does not bridge the internal network to the host network, so you can not invoke the API from the host network directly. Instead, you can invoke the API through the container which is attached to the internal network. Podman containers can resolve each other by name in the internal network, so you can use core-data
is accessible.
$ podman run --rm -it --network edgexpert_edgex-network curlimages/curl http://core-data:59880/api/v2/ping
{"apiVersion":"v2","timestamp":"Wed Oct 19 10:36:24 CST 2022","serviceName":"core-data"}
Using Docker Compose Override
For more information on Docker Compose Override, refer to Docker Compose Override.
To override the docker-compose file and expose the port of specified service, complete the following steps:
- Create the YAML files in your chosen local directory. For example, ~/local-compose/docker-compose-security.yml
- Open the local YAML file in an editor
-
Expose the port of specified service
This example demonstrates overriding the core-data's port number configuration with
59880
:version: '3.7' services: core-data: ports: - "59880:59880"
-
Save the local docker-compose-security.yml file and run Edge Xpert with local docker-compose-security file.
$ edgexpert up --api-gateway Overriding configuration with local docker-compose-security.yml
Using Configuration Files
For further information on the docker-compose YAML file see Configuration Files. Edge Xpert installs the docker-compose and Application Service YAML files to /etc/edgexpert.
An example usage of this is to expose the port of the core-data
.
$ sudo vi /etc/edgexpert
# choose docker-compose-security.yml and add the following information.
ports:
- "59880:59880"
$ edgexpert up --api-gateway
Note
If a later version of Edge Xpert is installed, it will overwrite your previous changes to the docker-compose files.
Using the Environment Variable
The SERVICE_PORT
environment variable can be used to override a service's default port.
An example usage of this is to change the default port of the xpert-manager
to 9091:
```yaml
version: '3.7'
services:
xpert-manager:
ports:
- "9091:9091"
environment:
SERVICE_PORT: 9091
```
Note
If the default port of an Edge Xpert service clashes or is in use by another service running on the host machine, for example perhaps the default port of 9090 used by xpert-manager
is already in use, it is necessary to modify the port mapping in the master docker-compose file under /etc/edgexpert from "9090:9090" to "9091:9090".
The default port SERVICE_PORT
change in not necessary in this case.