DEV Community

Maxime Guilbert
Maxime Guilbert

Posted on • Edited on

3 1

Kubernetes - Recreate element without error if already exists

One thing I never realized was the power of kubectl apply.


So if you want to quickly create an element in Kubernetes and avoid the error if the element already exists, you can use the following command (and adapt it to your needs)

kubectl create namespace my-namespace --dry-run=client -o yaml | kubectl apply -f -
Enter fullscreen mode Exit fullscreen mode

If you want more complex elements, you can use an existing file as input.

kubectl apply -f myYaml.yml
Enter fullscreen mode Exit fullscreen mode

And if you want more dynamism, you can use Helm or Kustomize!

Links


I hope it will help you! 😀

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay