简体   繁体   English

Kubernetes - 环境变量作为 API url

[英]Kubernetes - env variables as API url

So I have an API that's the gateway for two other API's.所以我有一个 API,它是其他两个 API 的网关。 Using docker in wsl 2 (ubuntu), when I build my Gateway API.在构建网关 API 时,在 wsl 2 (ubuntu) 中使用 docker。

docker run -d -p 8080:8080 -e A_API_URL=$A_API_URL B_API_URL=$B_API_URL  registry:$(somePort)//gateway  

I have 2 environnement variables that are the API URI of the two API'S.我有 2 个环境变量,它们是两个 API 的 API URI。 I just dont know how to make this work in the config.我只是不知道如何在配置中完成这项工作。

 env:
    - name: A_API_URL
      value: <need help>
    - name: B_API_URL
      value: <need help>

I get 500 or 502 errors when accessing then in the network.然后在网络中访问时出现 500 或 502 错误。 I tried specifyng the value of the env var as:我尝试将 env var 的值指定为:

  • their respective service's name.他们各自的服务名称。
  • the complete URI (http://$(addr):$(port)完整的 URI (http://$(addr):$(port)
  • the relative path : /something/anotherSomething相对路径:/something/anotherSomething

Each API is deployed with a Deployment controller and a service I'm at a lost, any help is appreciated每个 API 都部署了一个部署控制器和一个我迷路的服务,任何帮助表示赞赏

You just have to hardwire them.你只需要硬连线它们。 Kubernetes doesn't know anything about your local machine. Kubernetes 对你的本地机器一无所知。 There are templating tools like Helm that could inject things like Bash is in your docker run example but generally not a good idea since if anyone other than you runs the same command, they could see different results.有像 Helm 这样的模板工具可以在你的docker run示例中注入像 Bash 这样的东西,但通常不是一个好主意,因为如果你以外的任何人运行相同的命令,他们可能会看到不同的结果。 The values should look like http://servicename.namespacename.svc.cluster.local:port/whatever .这些值应该类似于http://servicename.namespacename.svc.cluster.local:port/whatever So if the service is named foo in namespace default with port 8000 and path /api, http://foo.default.svc.cluster.local:8000/api .因此,如果服务在命名空间default中命名为foo ,端口为 8000,路径为 /api, http://foo.default.svc.cluster.local:8000/api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM