You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Kubernetes Engine:上传health-check.yaml时健康检查验证报错

Fixing Kubernetes Deployment Validation Errors in health-check.yaml

Hey there! Let's get those validation errors sorted out—they're pointing to a couple of structural issues with your Deployment YAML, and we can fix them easily without skipping validation (which you definitely shouldn't do, since that hides real problems).

What's Causing the Errors?

Let's break down the two error messages:

  • unknown field "containers" in io.k8s.api.extensions.v1beta1.DeploymentSpec: The containers field doesn't belong directly under Deployment.spec in the extensions/v1beta1 API version. Containers are part of the Pod template, so they need to be nested inside spec.template.spec.
  • missing required field "template" in io.k8s.api.extensions.v1beta1.DeploymentSpec: Every Deployment requires a template section—this defines the blueprint for the Pods that the Deployment will manage. It's a mandatory field, so omitting it triggers this error.

Bonus Note: Deprecated API Version

Quick heads up: extensions/v1beta1 for Deployments is deprecated (it was removed in Kubernetes 1.22). For stability, you should switch to the apps/v1 API version instead—it's the current stable version for Deployments.

Corrected YAML Structure

Here's how to fix your health-check.yaml (I'll use the recommended apps/v1 version, but I'll note the differences if you need to stick with extensions/v1beta1 temporarily):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: health-check-deployment  # Replace with your deployment name
spec:
  replicas: 1  # Adjust replica count as needed
  selector:  # Required for apps/v1: matches labels in the Pod template
    matchLabels:
      app: health-check
  template:
    metadata:
      labels:
        app: health-check  # Matches the selector above
    spec:
      containers:  # Now correctly nested under template.spec
      - name: health-check-container
        image: your-image:tag  # Replace with your container image
        # Add your container config here (ports, probes, env vars, etc.)
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 10

If You Must Use extensions/v1beta1:

The structure is similar, but you don't need the selector field (though it's still good practice to include it):

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: health-check-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: health-check
    spec:
      containers:
      - name: health-check-container
        image: your-image:tag
        # Your container config

Why Skipping Validation Is a Bad Idea

Using --validate=false might let you apply the YAML, but it won't fix the underlying issue. The Deployment will fail to create Pods because the structure is invalid—you'll end up with more headaches later. Always fix the validation errors instead of bypassing them.

内容的提问来源于stack exchange,提问作者Nick Parsons

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:04:16