使用单个入口控制器调用多个服务
use single ingress controller for calling multiple services
我正在使用 helm 图表来部署不同的服务。
我已经参数化了我的图表,所以对于每项服务,我只需传递新的应用程序名称,它就会创建新的服务和相关内容。
所有这些服务都驻留在不同的命名空间中。
我已经创建了入口控制器,我想通过为每个服务添加新规则来将其用于所有服务。
我测试了一项服务的部署,它成功运行,但是当我尝试部署其余服务时它给我错误:
rendered manifests contain a resource that already exists. Unable to continue with install: Ingress "dev-ingress" in namespace "dev" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: missing key "meta.helm.sh/release-name": must be set to
我想了解实现此目的的理想流程。
- 我可以在不同的命名空间和用户一个入口控制器中创建服务吗?
- 如何配置我的参数化 helm 图表以在同一个入口中部署服务并创建新规则?
这是我的图表 -
Service.yaml
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.metadata.name }}-svc
labels:
{{- include "helmcharts.labels" . | nindent 4 }}
spec:
ports:
- name: http
protocol: TCP
port: 80
selector:
{{- include "helmcharts.selectorLabels" . | nindent 4 }}
Ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: dev-ingress
{{- if .Values.ingress.management.annotations }}
annotations:
{{ toYaml .Values.ingress.management.annotations | indent 4 }}
{{- end }}
spec:
rules:
- http:
paths:
- backend:
serviceName: {{ .Values.metadata.name }}-svc
servicePort: 80
path: /{{ .Values.env.path }}
Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.metadata.name }}-deployment
labels:
{{- include "helmcharts.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
strategy:
type: Recreate
{{- end }}
selector:
matchLabels:
{{- include "helmcharts.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "helmcharts.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "helmcharts.serviceAccountName" . }}
automountServiceAccountToken: false
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Values.env.containerName }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default
.Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: 80
protocol: "TCP"
values.yaml
metadata:
name: #{App-Name}#
env:
name: dev
initial: d
containerName: #{Container-Name}#
path: #{App}#-dev
ingress:
management:
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-name: "route"
nginx.ingress.kubernetes.io/session-cookie-hash: "sha1"
这是一个社区 Wiki 答案,发布是为了提高可见性,因此请随时对其进行编辑并添加您认为重要的任何其他详细信息。
OP 在评论中确认已根据用户 meaningqo in his 提供的建议解决了此问题:
your ingress controller is able to watch multiple diferent ingress
ressources. so there is no need for having one ingress that gets added
more rules when you add new applications. basically, just change the
name of the ingress in your helm-charts and you should be good to go –
meaningqo
solution provided by meaninggqo worked for me –
megha
我正在使用 helm 图表来部署不同的服务。 我已经参数化了我的图表,所以对于每项服务,我只需传递新的应用程序名称,它就会创建新的服务和相关内容。
所有这些服务都驻留在不同的命名空间中。
我已经创建了入口控制器,我想通过为每个服务添加新规则来将其用于所有服务。
我测试了一项服务的部署,它成功运行,但是当我尝试部署其余服务时它给我错误:
rendered manifests contain a resource that already exists. Unable to continue with install: Ingress "dev-ingress" in namespace "dev" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: missing key "meta.helm.sh/release-name": must be set to
我想了解实现此目的的理想流程。
- 我可以在不同的命名空间和用户一个入口控制器中创建服务吗?
- 如何配置我的参数化 helm 图表以在同一个入口中部署服务并创建新规则?
这是我的图表 -
Service.yaml
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.metadata.name }}-svc
labels:
{{- include "helmcharts.labels" . | nindent 4 }}
spec:
ports:
- name: http
protocol: TCP
port: 80
selector:
{{- include "helmcharts.selectorLabels" . | nindent 4 }}
Ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: dev-ingress
{{- if .Values.ingress.management.annotations }}
annotations:
{{ toYaml .Values.ingress.management.annotations | indent 4 }}
{{- end }}
spec:
rules:
- http:
paths:
- backend:
serviceName: {{ .Values.metadata.name }}-svc
servicePort: 80
path: /{{ .Values.env.path }}
Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.metadata.name }}-deployment
labels:
{{- include "helmcharts.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
strategy:
type: Recreate
{{- end }}
selector:
matchLabels:
{{- include "helmcharts.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "helmcharts.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "helmcharts.serviceAccountName" . }}
automountServiceAccountToken: false
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Values.env.containerName }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default
.Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: 80
protocol: "TCP"
values.yaml
metadata:
name: #{App-Name}#
env:
name: dev
initial: d
containerName: #{Container-Name}#
path: #{App}#-dev
ingress:
management:
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-name: "route"
nginx.ingress.kubernetes.io/session-cookie-hash: "sha1"
这是一个社区 Wiki 答案,发布是为了提高可见性,因此请随时对其进行编辑并添加您认为重要的任何其他详细信息。
OP 在评论中确认已根据用户 meaningqo in his
your ingress controller is able to watch multiple diferent ingress ressources. so there is no need for having one ingress that gets added more rules when you add new applications. basically, just change the name of the ingress in your helm-charts and you should be good to go – meaningqo
solution provided by meaninggqo worked for me – megha