DEV Community

Maxime Guilbert
Maxime Guilbert

Posted on • Updated on

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!


I hope it will help you! 😀

Top comments (0)