首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将nginx配置为kubernetes secret?

将nginx配置为kubernetes secret?
EN

Stack Overflow用户
提问于 2020-04-09 15:56:22
回答 1查看 325关注 0票数 0

我使用lua-resty-openidc作为入口控制器。现在,nginx.conf被硬编码在我的图像中,如下所示:

代码语言:javascript
运行
复制
    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可配置,例如

代码语言:javascript
运行
复制
    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密钥,其中包含他们项目的特定配置?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-09 20:11:53

您需要在运行时从模板化版本呈现nginx.conf (正如Juliano的评论所提到的那样)。为此,您的Dockerfile可能如下所示:

代码语言:javascript
运行
复制
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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61116420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档