【问题标题】:Extend helm upgrade cmd to add some field values扩展 helm upgrade cmd 以添加一些字段值
【发布时间】:2022-02-18 18:50:12
【问题描述】:

我正在使用修改后的 yaml 文件安装 ingress nginx

kubectl apply -f deploy.yaml

yaml 文件只是 original deploy file,但添加了用于部署的主机端口:

ports:
  - name: http
    containerPort: 80
    protocol: TCP
  - name: https
    containerPort: 443
    protocol: TCP
  - name: webhook
    containerPort: 8443
    protocol: TCP

变成:

ports:
  - name: http
    containerPort: 80
    protocol: TCP
    hostPort: 80 #<-- added
  - name: https
    containerPort: 443
    protocol: TCP
    hostPort: 443 #<-- added
  - name: webhook
    containerPort: 8443
    protocol: TCP
    hostPort: 8443 #<-- added

所以这对我有用。但我想install ingress nginx 使用 helm:

helm upgrade --install ingress-nginx ingress-nginx \
  --repo https://kubernetes.github.io/ingress-nginx \
  --namespace ingress-nginx --create-namespace

是否可以使用 helm (-f values.yml) 添加 hostPort 值?我需要在Deployment.spec.template.containers.ports中添加hostPort,但是我有两个问题要编写正确的values.yml文件:

values.yml

# How to access the deployment?
spec:
  template:
    containers:
      ports: # How to add field with existing containerPort value of each element in the array?

【问题讨论】:

    标签: nginx kubernetes kubernetes-helm helm3


    【解决方案1】:
    【解决方案2】:

    首先,您已经在 values.yaml 中有hostPort。见following fragment

      ## Use host ports 80 and 443
      ## Disabled by default
      hostPort:
        # -- Enable 'hostPort' or not
        enabled: false
        ports:
          # -- 'hostPort' http port
          http: 80
          # -- 'hostPort' https port
          https: 443
    

    你应该在values.yaml中开启它:

      ## Use host ports 80 and 443
      ## Disabled by default
      hostPort:
        # -- Enable 'hostPort' or not
        enabled: true
    

    毕竟 - 如您所知 - 您可以通过 helm 安装您的入口。

    helm install -f values.yaml
    

    关于 webhook - 请参阅 here


    您也可以在部署文件中找到hostPortHere 是模板之一(controller-deployment.yaml):

    在此文件中,您可以找到hostPort 的三个外观(值controller.hostPort.enabled - 负责启用或禁用主机端口)。

    Here:

                  {{- if $.Values.controller.hostPort.enabled }}
                  hostPort: {{ index $.Values.controller.hostPort.ports $key | default $value }}
                  {{- end }}
    

    here:

              {{- range $key, $value := .Values.tcp }}
                - name: {{ $key }}-tcp
                  containerPort: {{ $key }}
                  protocol: TCP
                  {{- if $.Values.controller.hostPort.enabled }}
                  hostPort: {{ $key }}
                  {{- end }}
              {{- end }}
              {{- range $key, $value := .Values.udp }}
                - name: {{ $key }}-udp
                  containerPort: {{ $key }}
                  protocol: UDP
                  {{- if $.Values.controller.hostPort.enabled }}
                  hostPort: {{ $key }}
                  {{- end }}
              {{- end }}
    

    另见:

    1. ingress-nginx Documentation on Github
    2. nginx Documentation
    3. NGINX - Helm Charts
    4. Helm Documentation

    【讨论】:

    • 值中不存在 8443 的主机端口。只有 80 和 443 像你描述的那样工作。
    • 对不起,我已经更新了asnwer。
    猜你喜欢
    • 2013-12-11
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 2018-03-21
    相关资源
    最近更新 更多