环境
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.15", GitCommit:"1d79bc3bcccfba7466c44cc2055d6e7442e140ea", GitTreeState:"clean", BuildDate:"2022-09-21T12:18:10Z", GoVersion:"go1.16.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"24+", GitVersion:"v1.24.8-eks-ffeb93d", GitCommit:"abb98ec0631dfe573ec5eae40dc48fd8f2017424", GitTreeState:"clean", BuildDate:"2022-11-29T18:45:03Z", GoVersion:"go1.18.8", Compiler:"gc", Platform:"linux/amd64"}
WARNING: version difference between client (1.22) and server (1.24) exceeds the supported minor version skew of +/-1
apiVersion: networking.k8s.io/v1
kind: Ingress
说明
修改apiVersion后报错
current release manifest contains removed kubernetes api(s) for this kubernetes version and it is therefore unable to build the kubernetes objects for performing the diff. error from kubernetes: unable to recognize "": no matches for kind "Ingress" in version "extensions/v1"
有两个问题让我很困惑
下面是我的模板文件
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Release.Namespace }}-ingress
namespace: {{ .Release.Namespace }}
annotations:
meta.helm.sh/release-name: ingress
meta.helm.sh/release-namespace: {{ .Release.Namespace }}
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/listen-ports: {{ .Values.listenPorts | toJson | quote }}
alb.ingress.kubernetes.io/certificate-arn: {{ .Values.certificateArn }}
alb.ingress.kubernetes.io/healthcheck-path: /health-check
alb.ingress.kubernetes.io/healthcheck-interval-seconds: "30"
alb.ingress.kubernetes.io/healthcheck-timeout-seconds: "5"
alb.ingress.kubernetes.io/ssl-policy: "ELBSecurityPolicy-TLS-1-2-Ext-2018-06"
alb.ingress.kubernetes.io/load-balancer-attributes: deletion_protection.enabled={{ .Values.deleteProtection }},access_logs.s3.enabled={{ .Values.enabledAccessLog }},access_logs.s3.bucket=alb-access-log-s3-{{ .Release.Namespace }}
# maintenance mode - api-playback #
alb.ingress.kubernetes.io/conditions.api-playback-maintenance-rule-1 : {{ .Values.maintenanceIpAddress1 | toJson | quote }}
alb.ingress.kubernetes.io/conditions.api-playback-maintenance-rule-2 : {{ .Values.maintenanceIpAddress2 | toJson | quote }}
alb.ingress.kubernetes.io/conditions.api-playback-maintenance-rule-3 : {{ .Values.maintenanceIpAddress3 | toJson | quote }}
alb.ingress.kubernetes.io/actions.api-playback-maintenance-rule-1 : {{ .Values.playbackMaintenanceAnnotationCode | toJson | quote }}
alb.ingress.kubernetes.io/actions.api-playback-maintenance-rule-2 : {{ .Values.playbackMaintenanceAnnotationCode | toJson | quote }}
alb.ingress.kubernetes.io/actions.api-playback-maintenance-rule-3 : {{ .Values.playbackMaintenanceAnnotationCode | toJson | quote }}
# maintenance mode - api-cms #
alb.ingress.kubernetes.io/conditions.api-cms-maintenance-rule-1 : {{ .Values.maintenanceIpAddress1 | toJson | quote }}
alb.ingress.kubernetes.io/conditions.api-cms-maintenance-rule-2 : {{ .Values.maintenanceIpAddress2 | toJson | quote }}
alb.ingress.kubernetes.io/conditions.api-cms-maintenance-rule-3 : {{ .Values.maintenanceIpAddress3 | toJson | quote }}
alb.ingress.kubernetes.io/actions.api-cms-maintenance-rule-1 : {{ .Values.cmsMaintenanceAnnotationCode | toJson | quote }}
alb.ingress.kubernetes.io/actions.api-cms-maintenance-rule-2 : {{ .Values.cmsMaintenanceAnnotationCode | toJson | quote }}
alb.ingress.kubernetes.io/actions.api-cms-maintenance-rule-3 : {{ .Values.cmsMaintenanceAnnotationCode | toJson | quote }}
# maintenance mode - api-client #
alb.ingress.kubernetes.io/conditions.api-client-maintenance-rule-1 : {{ .Values.maintenanceIpAddress1 | toJson | quote }}
alb.ingress.kubernetes.io/conditions.api-client-maintenance-rule-2 : {{ .Values.maintenanceIpAddress2 | toJson | quote }}
alb.ingress.kubernetes.io/conditions.api-client-maintenance-rule-3 : {{ .Values.maintenanceIpAddress3 | toJson | quote }}
alb.ingress.kubernetes.io/actions.api-client-maintenance-rule-1 : {{ .Values.clientMaintenanceAnnotationCode | toJson | quote }}
alb.ingress.kubernetes.io/actions.api-client-maintenance-rule-2 : {{ .Values.clientMaintenanceAnnotationCode | toJson | quote }}
alb.ingress.kubernetes.io/actions.api-client-maintenance-rule-3 : {{ .Values.clientMaintenanceAnnotationCode | toJson | quote }}
alb.ingress.kubernetes.io/actions.maintenance-503: >
{"type":"fixed-response","fixedResponseConfig":{"contentType":"text/plain","statusCode":"503","messageBody":"maintenance mode"}}
labels:
app.kubernetes.io/name: {{ .Release.Namespace }}-ingress
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
rules:
# maintenance rules
{{- $inMaintenanceMode := .Values.inMaintenanceMode -}}
{{- if $inMaintenanceMode }}
{{- $dn := .Values.dn -}}
{{- $hasDN := .Values.hasDN -}}
{{- range .Values.maintenanceRules }}
{{- if $hasDN }}
- host: {{ .hostPrefix }}.{{ $dn }}
http:
{{- else }}
- http:
{{- end }}
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: Prefix
backend:
service:
name: {{ .serviceName }}
port:
name: use-annotation
{{- end }}
{{- end }}
# if not inMaintenanceMode
{{- else }}
# default rules
{{- $dn := .Values.dn -}}
{{- $hasDN := .Values.hasDN -}}
{{- range .Values.rules }}
{{- if $hasDN }}
- host: {{ .hostPrefix }}.{{ $dn }}
http:
{{- else }}
- http:
{{- end }}
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: Prefix
backend:
service:
name: {{ .serviceName }}
port:
number: {{ .servicePort }}
{{- end }}
{{- end }}
{{- end }}
部署无误
这是由于 API 版本不匹配,如果 2-3 分钟的停机时间适合您,快速方法是卸载和重新安装Dev环境的helm chart。
您可以使用这个helm插件来了解弃用的API:https://github.com/helm/helm-mapkubeapis
选项 2:
您可以使用建议的选项首先编辑基于支持的 configmap/secret
kubectl get secret -l owner=helm,status=deployed,name=<release_name> --namespace <release_namespace> | awk '{print $1}' | grep -v NAME
kubectl get secret <release_secret_name> -n <release_namespace> -o yaml > release.yaml
cp release.yaml release.bak
cat release.yaml | grep -oP '(?<=release: ).*' | base64 -d | base64 -d | gzip -d > release.data.decoded
cat release.data.decoded | gzip | base64 | base64
kubectl apply -f release.yaml -n <release_namespace>
参考文档:https://helm.sh/docs/topics/kubernetes_apis/#updating-api-versions-of-a-release-manifest