Symton
When you try to apply a deployment yaml file to kubernetes cluster, you get the error:
kubectl apply -f tmp.yaml
The Deployment "xxx" is invalid:
* spec.template.spec.containers[0].env[53].valueFrom: Invalid value: "": may not be specified when `value` is not empty
Analysis
The kubernetes api met some issues when diff your tmp.yaml
with the current running deployment.
For example, your current running deployment file has a hardcoded environment, and your new tmp.yaml has an environment whose value is reading from other sources:
# current running deployment
- name: EXPRESS_LOG_LEVEL
value: debug
# You are trying to update to
- name: EXPRESS_LOG_LEVEL
valueFrom:
configMapKeyRef:
name: xxx-configmap
key: EXPRESS_LOG_LEVEL
How do I manually diff?
You can export the current deployment yaml by:
kubectl get deploy/your-current-deploy -o yaml | pbcopy
Then you can diff them via https://www.diffchecker.com/diff .
Solution
Delete the conflicted environments and then apply again:
KUBE_EDITOR="vim" kubectl edit deploy/your-current-deploy
kubectl apply -f tmp.yaml
# Now you get the success message!
deployment.apps/xxx-app configured
Top comments (0)