Google Kubernetes Engine与GitHub Actions部署报错:deployments.apps 'gke-deployment'未找到
解决GKE部署Action报错:deployments.apps "gke-deployment" not found
我在给GitHub仓库运行Google Kubernetes Engine部署Action时,工作流其余环节都正常,唯独部署步骤失败,报错信息:
Error from server (NotFound): deployments.apps "gke-deployment" not found
我推测问题出在YAML配置文件中,由于刚接触相关技术,配置是参考网络内容修改而来,对细节尚不熟悉。相关配置文件如下:
Kustomize.yaml
apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization metadata: name: arbitrary # Example configuration for the webserver # at https://github.com/monopole/hello commonLabels: app: videoo-render resources: - deployment.yaml - service.yaml
deployment.yaml(我认为问题出在此处)
apiVersion: apps/v1 kind: Deployment metadata: name: the-deployment spec: replicas: 3 selector: matchLabels: deployment: video-render template: metadata: labels: deployment: video-render spec: containers: - name: the-container image: monopole/hello:1 command: ["/video-render", "--port=8080", "--enableRiskyFeature=$(ENABLE_RISKY)"] ports: - containerPort: 8080 env: - name: ALT_GREETING valueFrom: configMapKeyRef: name: the-map key: altGreeting - name: ENABLE_RISKY valueFrom: configMapKeyRef: name: the-map key: enableRisky
service.yaml
kind: Service apiVersion: v1 metadata: name: the-service spec: selector: deployment: video-render type: LoadBalancer ports: - protocol: TCP port: 8666 targetPort: 8080
当前使用Ubuntu 20.04镜像,仓库代码为C++语言。
问题分析与解决步骤
报错提示找不到名为gke-deployment的Deployment,但你的配置里定义的Deployment名字是the-deployment,核心原因是部署脚本中指定操作的Deployment名称和实际配置的名称不匹配。
解决方法二选一:
- 修改GitHub Action的部署脚本,将操作的Deployment名称改为
the-deployment - 修改
deployment.yaml中metadata.name字段为gke-deployment,让配置和脚本的目标名称一致
额外注意事项
- 你的Deployment配置中引用了名为
the-map的ConfigMap,但当前配置里没有定义该资源,部署时会因找不到ConfigMap失败,需要补充configMap.yaml并将其添加到Kustomize的resources列表中 - 容器镜像使用的是
monopole/hello:1,这是示例镜像,需要替换成你自己构建的C++应用镜像,否则无法运行你的业务代码
内容的提问来源于stack exchange,提问作者Turgut
相关产品推荐
相关产品推荐

