DEV Community

Cover image for How to resolve `kubectrl apply`deployment conflict error
Jeff
Jeff

Posted on

How to resolve `kubectrl apply`deployment conflict error

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

How do I manually diff?

You can export the current deployment yaml by:

kubectl get deploy/your-current-deploy -o yaml | pbcopy
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)