1

我有一个使用 nginx 网络服务器提供静态内容的应用程序,这是实际nginx.conf文件的样子

upstream app_api {
    server web:8000;
}

server {

    listen 80;
    client_max_body_size 100M;

    location / {
        proxy_pass http://chp_api;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    proxy_read_timeout 3600;
    }

    location /staticfiles/ {
    alias /home/chp_api/web/staticfiles/;
    }
}

为了将其转换为 helm chart 并将 nginx 作为应用程序 namsespace 中的单独 pod 运行。我遵循了这段代码。这是我的nginx-config.yaml文件

{{- if .Values.nginx.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "app.fullname" . }}-nginxconfig
  labels:
    app.kubernetes.io/name: {{ include "app.fullname" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
  nginx.conf: |-
{{- if .Values.nginx.config.default }}

    upstream app_api {
        server web:8000;
    }

    server {
        listen 80;

        # set max upload size
        client_max_body_size 100M;

        location / {
            proxy_pass http://app_api;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_redirect off;
            proxy_read_timeout 3600;
        }

        location /staticfiles/ {
            alias /home/app_api/web/staticfiles/;
        }
    }
{{- else }}
{{ .Values.nginx.config.custom | indent 4 }}
{{- end }}
{{- end }}

nginx 的 values.yaml 文件看起来像

nginx:
  enabled: false
  image:
    repository: nginx
    tag: alpine
    pullPolicy: IfNotPresent

  config:
    default: true

  resources: {}

但是我没有看到为 nginx web 服务器创建了单独的 pod,除了应用程序的一个。请问我做错了什么,我是kubernetes和helm chart的新手。

4

1 回答 1

0

考虑到您是 k8s 和 Helm 的新手,并且提供的 repo 没有解释如何逐步创建部署,我建议您查看官方文档,在那里您可以了解如何部署和管理简单的 nginx 部署更远。

于 2021-10-28T13:11:45.880 回答