我使用lua-resty-openidc作为入口控制器。现在,nginx.conf被硬编码在我的图像中,如下所示:
server {
server_name _;
listen 80;
location /OAuth2Client {
access_by_lua_block {
local opts = {
discovery = "/.well-known/openid-configuration",
redirect_uri = "/authorization-code/callback",
client_id = "clientID",
client_secret = "clientSecret",
scope = "openid profile somethingElse",
}
...
}
proxy_pass http://clusterIp/OAuth2Client;
}
}由于Nginx不接受环境变量,有没有一个简单的方法可以让我的nginx.conf可配置,例如
server {
server_name ${myServerName};
listen ${myServerPort};
location /${specificProjectRoot} {
access_by_lua_block {
local opts = {
discovery = "${oidc-provider-dev-url}/.well-known/openid-configuration",
redirect_uri = "${specificProjectRoot}/authorization-code/callback",
client_id = "${myClientId}",
client_secret = "${myClientSecret}",
scope = "${myScopes}",
}
...
}
proxy_pass http://${myClusterIP}/${specificProjectRoot};
}
}这样,无论团队在什么名称空间中,都可以重用我的图像,只需提供一个kubernetes密钥,其中包含他们项目的特定配置?
发布于 2020-04-09 20:11:53
您需要在运行时从模板化版本呈现nginx.conf (正如Juliano的评论所提到的那样)。为此,您的Dockerfile可能如下所示:
FROM nginx
COPY nginx.conf.template /etc/nginx/
CMD ["/bin/bash", "-c", "envsubst < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && exec nginx -g 'daemon off;'"]请注意,它会将nginx.conf.template复制到您的映像中,这将是带有变量的模板化配置,其形式为${MY_SERVER_NAME},其中MY_SERVER_NAME通过您的Kubernetes清单,从您的配置映射或秘密,或者以您喜欢的任何方式为injected into your pod as an environment variable。
https://stackoverflow.com/questions/61116420
复制相似问题