Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: k8s service discovery error: not found environment variable KUBERNETES_SERVICE_HOST #6830

Closed
spinachomes opened this issue Apr 12, 2022 · 6 comments · Fixed by #6869
Closed
Assignees
Labels
good first issue Good for newcomers

Comments

@spinachomes
Copy link

Current Behavior

k8s discovery can't get KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT from ENV

but in pod I can echo KUBERNETES_SERVICE_HOST var.

image

Expected Behavior

No response

Error Logs

2022/04/12 07:22:00 [error] 48#48: init_worker_by_lua error: /usr/local/apisix/apisix/discovery/kubernetes/init.lua:342: not found environment variable KUBERNETES_SERVICE_HOST
stack traceback:
[C]: in function 'error'
/usr/local/apisix/apisix/discovery/kubernetes/init.lua:342: in function 'init_worker'
/usr/local/apisix/apisix/discovery/init.lua:35: in function 'init_worker'
/usr/local/apisix/apisix/init.lua:109: in function 'http_init_worker'
init_worker_by_lua:2: in main chunk

Steps to Reproduce

1.install apisix use helm apisix-helm-chart
2.add discovery:kubernetes: { } in apisix configmap
3.k logs -f po

Environment

  • APISIX version (run apisix version):2.13.0
  • Operating system (run uname -a):Linux hecs-x-large-4-linux-20200603165605 3.10.0-1160.53.1.el7.x86_64 change: added doc of how to load plugin. #1 SMP Fri Jan 14 13:59:45 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  • OpenResty / Nginx version (run openresty -V or nginx -V):
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):
@tokers
Copy link
Contributor

tokers commented Apr 12, 2022

@spinachomes By default, APISIX doesn't recognize extra environment variables, please add this env to https://github.com/apache/apisix/blob/master/conf/config-default.yaml#L172.

@tokers
Copy link
Contributor

tokers commented Apr 12, 2022

@spinachomes By default, APISIX doesn't recognize extra environment variables, please add this env to https://github.com/apache/apisix/blob/master/conf/config-default.yaml#L172.

By the way, if this way helps you to resolve the problem, could you also help to optimize the doc of kubernetes discovery?

@spacewander
Copy link
Member

We can inject the env variable when k8s service discovery is enabled?

for name, value in pairs(exported_vars) do

@spacewander spacewander added the good first issue Good for newcomers label Apr 13, 2022
@zhixiongdu027
Copy link
Contributor

We can inject the env variable when k8s service discovery is enabled?

for name, value in pairs(exported_vars) do

maybe i can get it done this weekend

@spinachomes
Copy link
Author

@spinachomes By default, APISIX doesn't recognize extra environment variables, please add this env to https://github.com/apache/apisix/blob/master/conf/config-default.yaml#L172.

By the way, if this way helps you to resolve the problem, could you also help to optimize the doc of kubernetes discovery?

thanks, I will try

@zhixiongdu027
Copy link
Contributor

We can inject the env variable when k8s service discovery is enabled?

for name, value in pairs(exported_vars) do

maybe i can get it done this weekend

Sorry, I received a temporary assignment from my boss and I need to take up weekend time.
So this work may be delayed for a few days, maybe you can cancel the assign first

@spacewander

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants