创建Deployment时extensions/v1beta1版本正则验证失败求助
Hey there, let's break down exactly what's causing that frustrating regex error and get your Deployment up and running.
1. Root Cause of the Error
That regex validation failure (quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$') is pointing to a simple but critical issue: your resource limit values aren't in a format Kubernetes understands.
Looking at your YAML, the resources.limits section uses placeholder variables like $SPARK_MASTER_MEMORY and $SPARK_MASTER_CPU—Kubernetes can't parse these as valid resource quantities. The mention of extensions/v1beta1 in the error is a red herring here; the real problem is unprocessed variables in your resource definitions.
2. Step-by-Step Fixes
Replace Placeholder Variables with Valid Resource Values
Kubernetes requires specific formats for CPU and memory quantities:
- Memory: Use units like
Mi(mebibytes),Gi(gibibytes),M(megabytes), orG(gigabytes). Example:1Gi,512Mi - CPU: Use whole numbers (for full cores) or
mfor millicores (1 core = 1000m). Example:1,750m
Update your resources block with concrete values:
resources: limits: memory: '1Gi' # Replace with your actual master memory requirement cpu: '500m' # Replace with your actual master CPU requirement
Optional (But Recommended): Update the API Version
Your Kubectl client is v1.6.4, while the server is v1.5.7. In Kubernetes 1.6+, Deployment resources moved from extensions/v1beta1 to apps/v1beta1. While extensions/v1beta1 still works on v1.5, switching to apps/v1beta1 will make your YAML more future-compatible:
kind: Deployment apiVersion: apps/v1beta1 # Updated from extensions/v1beta1 metadata: name: sf-spark-master # ... rest of your YAML remains the same
Validate Variable Substitution (If Using CI/CD)
If those $ variables are supposed to be replaced by a CI/CD pipeline (like Jenkins or GitLab CI), double-check that the pipeline is correctly substituting them before applying the YAML. You can test locally with a dry-run to catch issues early:
kubectl --kubeconfig=/var/go/.kube/mcc-pp-config --context=sam-mcc2-pp --namespace=sam-mcc2-pp apply -f k8s-config-sam-mcc2-pp/sf-spark-worker-deployment.yaml --record --dry-run
3. Final Verification
Once you've updated the resource values (and optionally the API version), run your original apply command again—it should succeed without the regex error.
内容的提问来源于stack exchange,提问作者Ritabrata

