How to enable multiple ports/values in the YAMl file? | Microservices


(Sebs Sa) #1

Hey,

I am quite inexperienced with dockers, but mostly used this form:

ports:
- “1250:1250”
- “1251:1251”
- “1252:1252”
- “1253:1253”
- “1254:1254”
- “5701:5701”

now I’ve tried to apply that to the iofog template.

ports:
  - internal: 1250
external: 1250
  - internal: 1251
external: 1251
   ....
   ....

I guess that worked.


Now I would like to know how to create environment variables. I tried :

env:
  - key: HOST
value: 127.0.0.1
  - key: BACKEND_PORT
value: 1250
   ....

but here I get the error message :

line 17: mapping values are not allowed in this context

Does anyone have any ideas? Thank you very much in advance.
Seb


(Saeid) #2

Hi @SebsSa,

It seems to be a YAML formatting issue. Here is an example for deploying microservices with ports and environment variables:

apiVersion: 'iofog.org/v1'
kind: Application
metadata:
  name: 'HealthcareWearable'
spec:
  microservices:
    - name: "heart-rate-viewer"
      agent:
        name: "agent-name"
      images:
        arm: "edgeworx/healthcare-heart-rate-ui:arm"
        x86: "edgeworx/healthcare-heart-rate-ui:x86"
      container:
        rootHostAccess: false
        ports:
          - external: 5000
            internal: 80
        env:
          - key: "BASE_URL"
            value: "http://localhost:8080/data"
      config:
        test: 54

If you still have thew issue, please post the yaml file that you’re using to deploy the microservices so we can take a look.

Thanks,
Saeid


(Sebs Sa) #3

Hello,
Oh, I’m afraid I was a little unclear on that.
Yes, I found this example too and tried to follow it.
But in this example only one port and one variable is set, I would like to have several.

This is my yaml:

apiVersion: iofog.org/v1
kind: Application
metadata:
  name: appl
spec:
  microservices:
  - name: "appli-core"
    agent:
      name: rogue-1
    images: # Microservice docker images
      arm: "xx/xxx:latest"
      x86: "xx/xxx:latest"
    ports:
      - internal: 1250
        external: 1250
      - internal: 1251
        external: 1251
      - internal: 1252
        external: 1252
      - internal: 1253
        external: 1253
      - internal: 1254
        external: 1254
      - internal: 5701
         external: 5701
    env:
      - key: HOST
        value: 127.0.0.1
      - key: BACKEND_PORT
        value: 1250
      - key: CONTROL_PUB_PORT
        value: 1251
      - key: CONTROL_SUB_PORT
        value: 1252
      - key: DATA_PUB_PORT
        value: 1253
      - key: DATA_SUB_PORT
        value: 1254
      - key: BACKEND_HOST
        value: core1
      - key: HAZELCAST_PORT
        value: 5701'

(Saeid) #4

It should deploy all the env vars and ports, 3 issues in your yaml tho:

  • ports and env must be under container
  • the last external port has an extra space before
  • the last value has a ' after the value

Please try this:

- name: "appli-core"
  agent:
    name: rogue-1
  images: # Microservice docker images
    arm: "xx/xxx:latest"
    x86: "xx/xxx:latest"
  container:
    ports:
      - internal: 1250
        external: 1250
      - internal: 1251
        external: 1251
      - internal: 1252
        external: 1252
      - internal: 1253
        external: 1253
      - internal: 1254
        external: 1254
      - internal: 5701
        external: 5701
    env:
      - key: HOST
        value: 127.0.0.1
      - key: BACKEND_PORT
        value: 1250
      - key: CONTROL_PUB_PORT
        value: 1251
      - key: CONTROL_SUB_PORT
        value: 1252
      - key: DATA_PUB_PORT
        value: 1253
      - key: DATA_SUB_PORT
        value: 1254
      - key: BACKEND_HOST
        value: core1
      - key: HAZELCAST_PORT
        value: 5701

Thanks,
Saeid


(Sebs Sa) #5

Okay thanks, I definitely had some typos in there :confused:

Look like this now :

echo '---
apiVersion: iofog.org/v1
kind: Application
metadata:
  name: sfsc
spec:
  microservices:
  - name: "sfsc-core"
  agent:
    name: rogue-1
  images:
      arm: "xx/xx:linux-armv7"   **#Edit: Available in Dockerhub**
  container:
    ports:
      - internal: 1250
        external: 1250
      - internal: 1251
        external: 1251
      - internal: 1252
        external: 1252
      - internal: 1253
        external: 1253
      - internal: 1254
        external: 1254
      - internal: 5701
        external: 5701
    env:
      - key: HOST
        value: 127.0.0.1
      - key: BACKEND_PORT
        value: 1250
      - key: CONTROL_PUB_PORT
        value: 1251
      - key: CONTROL_SUB_PORT
        value: 1252
      - key: DATA_PUB_PORT
        value: 1253
      - key: DATA_SUB_PORT
        value: 1254
      - key: BACKEND_HOST
        value: core1
      - key: HAZELCAST_PORT
        value: 5701' > /tmp/quick-start-app.yaml
iofogctl deploy -f /tmp/quick-start-app.yaml

Unfortunately, I still get a few mistakes.

✘ Failed to unmarshal input file.
yaml: unmarshal errors:
line 1: field agent not found in type apps.Application
line 3: field container not found in type apps.Application
line 34: field images not found in type apps.Application
Make sure to use camel case field names. E.g. keyFile: ~/.ssh/id_rsa

My current setup looks like this (agent (rouge-1) is located on a Raspi3)
I have successfully tested it with the “HealthcareWearable-Application”!

Thanks for helping.
Seb


(Saeid) #6

Looks like an indentation issue (from line 9 where you specified the agent).
Please try this:

echo '---
apiVersion: iofog.org/v1
kind: Application
metadata:
  name: sfsc
spec:
  microservices:
    - name: sfsc-core
      agent:
        name: rogue-1
      images:
        arm: 'xx/xx:linux-armv7'
      container:
        ports:
          - internal: 1250
            external: 1250
          - internal: 1251
            external: 1251
          - internal: 1252
            external: 1252
          - internal: 1253
            external: 1253
          - internal: 1254
            external: 1254
          - internal: 5701
            external: 5701
        env:
          - key: HOST
            value: 127.0.0.1
          - key: BACKEND_PORT
            value: 1250
          - key: CONTROL_PUB_PORT
            value: 1251
          - key: CONTROL_SUB_PORT
            value: 1252
          - key: DATA_PUB_PORT
            value: 1253
          - key: DATA_SUB_PORT
            value: 1254
          - key: BACKEND_HOST
            value: core1
          - key: HAZELCAST_PORT
            value: 5701' > /tmp/quick-start-app.yaml

(Sebs Sa) #7

One more Error to go

✘ Failed to unmarshal input file.
yaml: unmarshal errors:
line 4: field container not found in type apps.Microservice
Make sure to use camel case field names. E.g. keyFile: ~/.ssh/id_rsa


(Saeid) #8

Sorry, my bad.
Try this:

echo '---
apiVersion: iofog.org/v1
kind: Application
metadata:
  name: sfsc
spec:
  microservices:
    - name: sfsc-core
      agent:
        name: rogue-1
      images:
        arm: 'xx/xx:linux-armv7'
      ports:
        - internal: 1250
          external: 1250
        - internal: 1251
          external: 1251
        - internal: 1252
          external: 1252
        - internal: 1253
          external: 1253
        - internal: 1254
          external: 1254
        - internal: 5701
          external: 5701
      env:
        - key: HOST
          value: 127.0.0.1
        - key: BACKEND_PORT
          value: 1250
        - key: CONTROL_PUB_PORT
          value: 1251
        - key: CONTROL_SUB_PORT
          value: 1252
        - key: DATA_PUB_PORT
          value: 1253
        - key: DATA_SUB_PORT
          value: 1254
        - key: BACKEND_HOST
          value: core1
        - key: HAZELCAST_PORT
          value: 5701' > /tmp/quick-start-app.yaml

(Sebs Sa) #9

It works ! Thank you very much.
Looks like I’ll have to be more accurate !