If I do kubectl get deployments
, I get:
$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
analytics-rethinkdb 1 1 1 1 18h
frontend 1 1 1 1 6h
queue 1 1 1 1 6h
Is it possible to rename the deployment to rethinkdb
? I have tried googling kubectl edit analytics-rethinkdb
and changing the name in the yaml, but that results in an error:
$ kubectl edit deployments/analytics-rethinkdb
error: metadata.name should not be changed
I realize I can just kubectl delete deployments/analytics-rethinkdb
and then do kubectl run analytics --image=rethinkdb --command -- rethinkdb etc etc
but I feel like it should be possible to simply rename it, no?
Object names are immutable in Kubernetes. If you want to change a name, you can export/edit/recreate with a different name
As others mentioned, kubernetes objects names are immutable, so technically rename is not possible.
A hacking approach to emulate some similar behavior would be to delete an object and create it with a different name. That is a bit dangerous as some conflicts can happen depending on your object. A command line approach could look like this:
kubectl get deployment analytics-rethinkdb -o json \
| jq '.metadata.name = "rethinkdb"' \
| kubectl apply -f - && \
kubectl delete deployment analytics-rethinkdb