我正在使用修改后的 yaml 檔案安裝入口 nginx
kubectl apply -f deploy.yaml
yaml 檔案只是原始部署檔案,但添加了用于部署的 hostPorts:
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
所以這對我有用。但我想使用 helm安裝入口 nginx:
helm upgrade --install ingress-nginx ingress-nginx \
--repo https://kubernetes.github.io/ingress-nginx \
--namespace ingress-nginx --create-namespace
是否可以hostPort使用 helm ( -f values.yml) 添加值?我需要添加hostPort,Deployment.spec.template.containers.ports但是撰寫正確的 values.yml 檔案有兩個問題:
值.yml
# How to access the deployment?
spec:
template:
containers:
ports: # How to add field with existing containerPort value of each element in the array?
uj5u.com熱心網友回復:
兩種查找方法:
您可以仔細查看 helm 圖表本身https://github.com/kubernetes/ingress-nginx/blob/main/charts/ingress-nginx
在這里您可以找到部署規范https://github.com/kubernetes/ingress-nginx/blob/main/charts/ingress-nginx/templates/controller-deployment.yaml
在它下面,你可以看到,有啟用
hostPorthttps://github.com/kubernetes/ingress-nginx/blob/main/charts/ingress-nginx/templates/controller-deployment.yaml#L113的條件(正確的一個)總是挖掘
values.yamlhttps://github.com/kubernetes/ingress-nginx/blob/main/charts/ingress-nginx/values.yaml#L90和圖表檔案https://github.com/kubernetes/ingress-nginx/blob/main/charts/ingress-nginx/README.md#:~:text=controller.hostPort.enabled
uj5u.com熱心網友回復:
首先,您已經hostPort擁有values.yaml。請參閱以下片段:
## 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, 443 and 8443
## Disabled by default
hostPort:
# -- Enable 'hostPort' or not
enabled: true
ports:
# -- 'hostPort' http port
http: 80
# -- 'hostPort' https port
https: 443
# -- 'hostPort' webhook port
webhook: 8443
畢竟 - 如您所知 - 您可以通過helm.
helm install -f values.yaml
您也可以hostPort在部署檔案中找到。這是模板之一(controller-deployment.yaml):
在此檔案中,您可以找到三個外觀hostPort(值controller.hostPort.enabled- 負責啟用或禁用主機埠)。
這里:
{{- if $.Values.controller.hostPort.enabled }}
hostPort: {{ index $.Values.controller.hostPort.ports $key | default $value }}
{{- end }}
在這里:
{{- 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 }}
也可以看看:
- Github 上的 ingress-nginx檔案
- nginx檔案
- NGINX - Helm 圖表
- Helm檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/425773.html
標籤:nginx Kubernetes kubernetes-helm 掌舵3
上一篇:驗證資料時出錯:[ValidationError(CronJob.spec.jobTemplate.spec.template.spec):io.k8s.api.core.v1.PodSpec中的未知
下一篇:無法訪問在AKS上部署的應用程式
