我正在研究 Azure 中的 kubernetes 集群的新更新。但是,我不知道该怎么做。我已经能够构建一个像这样的入口 Controller :
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "test.fullname" . -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "test.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ .port }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ .port }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
我的值(value)观如下:
replicaCount: 1
image:
repository: test01.azurecr.io/test
tag: update1
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 2000
targetPort: http
protocol: TCP
ingress:
enabled: true
className: ""
annotations:
appgw.ingress.kubernetes.io/use-private-ip: 'true'
kubernetes.io/ingress.class: azure/application-gateway
hosts:
- host: test.com
paths:
- path: /test
pathType: Prefix
port: 80
tls: []
serviceAccount:
# Specifies whether a service account should be created
create: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
podAnnotations: {}
podSecurityContext: {}
# fsGroup: 2000
我的 Pod 已准备就绪,看来服务已准备就绪。但是,test.com 域无法正常工作。我为我的域添加了 DNS 记录,并使用集群的 IP 来确保该域可用。但是,我在查看域时仍然遇到问题,错误消息如下:
Connection timed out && This site can’t be reached
有人知道更好的解决方法吗?
最佳答案
在 Kubernetes 中,您有 Ingress Controllers和 Ingress资源。您拥有的是 Ingress 的定义,而不是 Ingress Controller 。除非集群中安装了 Ingress Controller,否则 Ingress 将无法工作。
但是,在 AKS(Azure Kubernetes 服务)中,可以将 Ingress 资源绑定(bind)到 Azure Application Gateway ,这是集群外部的 Azure 资源。
要实现这一目标,您需要 AGIC (应用程序网关入口 Controller )它将负责将您的入口配置转发到应用程序网关。通过在您想要配置的 Ingress 资源上添加这些注释,您已经部分实现了这一点:
annotations:
appgw.ingress.kubernetes.io/use-private-ip: 'true'
kubernetes.io/ingress.class: azure/application-gateway
摘要:
您有两个选择:
- 安装入口 Controller ,例如 nginx或traefik并相应地调整 Ingress 资源上的注释。
- 确保您的订阅中部署了应用程序网关,集群中安装了 AGIC,以及允许 AGIC 修改应用程序网关所需的所有配置。
如果这是您第一次使用 Ingresses 和 Azure,我强烈建议您遵循第一个选项。
关于azure - 如何将域添加到 helm 中的 Ingress Controller 中以进行 kubernetes 部署?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73888219/