Kubernetes 1.25.11升级后CICD部署CronJob报错求助
Kubernetes 1.25升级后CronJob部署报错问题
我将Kubernetes版本升级至1.25.11,按废弃API迁移文档更新了API版本,升级过程顺利。但部署应用新功能时,CICD流水线报错:
Error: UPGRADE FAILED: [resource mapping not found for name: "abc-cron" namespace: "staging" from "": no matches for kind "CronJob" in version "batch/v1beta1"
我已将CronJob的API版本从batch/v1beta1修改为batch/v1,对应的YAML配置如下:
kind: CronJob apiVersion: batch/v1 metadata: name: abc-cron namespace: staging uid: ca924a0c-4696-401e-9224-9e92039aa089 resourceVersion: '79995787' generation: 2 creationTimestamp: '2023-01-12T13:54:31Z' labels: app.kubernetes.io/managed-by: Helm annotations: meta.helm.sh/release-name: app-staging meta.helm.sh/release-namespace: staging managedFields: - manager: helm operation: Update apiVersion: batch/v1 time: '2023-01-12T13:54:31Z' fieldsType: FieldsV1 fieldsV1: f:metadata: f:annotations: .: {} f:meta.helm.sh/release-name: {} f:meta.helm.sh/release-namespace: {} f:labels: .: {} f:app.kubernetes.io/managed-by: {} f:spec: f:concurrencyPolicy: {} f:failedJobsHistoryLimit: {} f:jobTemplate: f:spec: f:backoffLimit: {} f:template: f:spec: f:containers: k:{"name":"abc-cron"}: .: {} f:env: .: {} k:{"name":"ENVIRONMENT"}: .: {} f:name: {} f:value: {} f:image: {} f:imagePullPolicy: {} f:name: {} f:resources: {} f:terminationMessagePath: {} f:terminationMessagePolicy: {} f:dnsPolicy: {} f:imagePullSecrets: .: {} k:{"name":"docker-secret"}: {} f:restartPolicy: {} f:schedulerName: {} f:securityContext: {} f:terminationGracePeriodSeconds: {} f:schedule: {} f:successfulJobsHistoryLimit: {} - manager: Mozilla operation: Update apiVersion: batch/v1 time: '2023-01-12T13:57:21Z' fieldsType: FieldsV1 fieldsV1: f:spec: f:suspend: {} spec: schedule: 0 9 1,16 * * concurrencyPolicy: Replace suspend: true jobTemplate: metadata: creationTimestamp: null spec: backoffLimit: 4 template: metadata: creationTimestamp: null spec: containers: - name: abc-cron image: msapp.azurecr.io/abccron:ms-staging env: - name: ENVIRONMENT value: ms-staging resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File imagePullPolicy: Always restartPolicy: Never terminationGracePeriodSeconds: 30 dnsPolicy: ClusterFirst securityContext: {} imagePullSecrets: - name: docker-secret schedulerName: default-scheduler successfulJobsHistoryLimit: 3 failedJobsHistoryLimit: 1 status: {}
我是Kubernetes新手,无法解决该问题,恳请帮助。
问题分析与解决方法
清理Helm缓存:Helm可能缓存了旧版本的Chart模板,执行以下命令清理:
helm cache clean清理完成后重新运行部署命令。
检查所有Chart模板:确认CICD使用的Helm Chart中,所有
CronJob资源的apiVersion都已更新为batch/v1,没有遗漏任何一处旧版本引用。重新打包Chart:如果使用自定义Helm Chart,修改配置后重新打包:
helm package ./your-chart-directory确保CICD流水线使用的是最新打包的Chart包。
卸载并重新部署(谨慎操作):如果上述方法无效,可先卸载旧的Release(注意备份相关数据),再重新部署:
helm uninstall app-staging -n staging helm install app-staging ./your-chart -n staging检查CICD流水线配置:确认流水线中引用的是更新后的YAML/Chart文件,没有指向旧的配置路径。
内容的提问来源于stack exchange,提问作者SriLatha
相关产品推荐
相关产品推荐

