Default Config is not set - or the Port to be more precise

Hello, I am trying to create a K8s Helm Chart for n8n, (will publish the code here)

in https://github.com/n8n-io/n8n/blob/master/packages/cli/config/index.ts I see there are defaults set but when I start the container n8n complains:

UserSettings got generated and saved to: /home/node/.n8n/config
2020-11-25T16:08:05.785351185Z (node:6) UnhandledPromiseRejectionWarning: Error: There was an error: options.port should be >= 0 and < 65536. Received NaN.
2020-11-25T16:08:05.785421438Z     at Object.error (/usr/local/lib/node_modules/n8n/node_modules/@oclif/errors/lib/index.js:26:15)
2020-11-25T16:08:05.785431156Z     at Start.error (/usr/local/lib/node_modules/n8n/node_modules/@oclif/command/lib/command.js:60:23)
2020-11-25T16:08:05.785436947Z     at /usr/local/lib/node_modules/n8n/dist/commands/start.js:134:22
2020-11-25T16:08:05.785442618Z (node:6) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2020-11-25T16:08:05.785456193Z (node:6) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The port seems to be NaN but I expected the default port 5678 to be the set like it is described in https://github.com/n8n-io/n8n/blob/master/packages/cli/config/index.ts

I uses N8N_CONFIG_FILES but I do see the behavior event if env N8N_CONFIG_FILES isn’t set.

N8N_CONFIG_FILES = /n8n-config/config.json

cat /n8n-config/config.json 

{
  "host": "workflow.app.8gears.com",
  "port": "5678"
}

Welcome to the community @Vad1mo!

Here another user which had the same problem:

Think has to do with naming. If you call the service (can not remember the correct k8s right now) “n8n” it will automatically create a variable “<SERVICE_NAME>_PORT” so “N8N_PORT” which is the same environment variable n8n uses internally. That messes stuff up. If you give it another name that should solve that problem.

ahh I see now the problem

K8s sets its own set of env vars. So if the application is named “n8n” in kubernetes then k8s set the env var APPNAME_PORT resulting in N8N_PORT=tcp://10.37.21.70:80 which causes the error.

data # env
N8N_SERVICE_HOST=10.37.21.70
KUBERNETES_SERVICE_PORT=443
KUBERNETES_PORT=tcp://10.32.0.1:443
N8N_CONFIG_FILES=/n8n-config/config.json
NODE_VERSION=12.19.1
HOSTNAME=n8n-6f795bf465-gnl7k
YARN_VERSION=1.22.5
SHLVL=2
HOME=/root
N8N_PORT=tcp://10.37.21.70:80
N8N_SERVICE_PORT=80
N8N_ENCRYPTION_KEY=iam not a secret
N8N_PORT_80_TCP_ADDR=10.37.21.70
NODE_ICU_DATA=/usr/local/lib/node_modules/full-icu
N8N_PORT_80_TCP_PORT=80
TERM=xterm
N8N_PORT_80_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_ADDR=10.32.0.1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_PROTO=tcp
N8N_PORT_80_TCP=tcp://10.37.21.70:80
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT_443_TCP=tcp://10.32.0.1:443
KUBERNETES_SERVICE_HOST=10.32.0.1
N8N_SERVICE_PORT_HTTP=80
PWD=/data

So I change the name of the application or hard code the port and overwrite it.

Exactly, any should work.