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?
As others mentioned, kubernetes objects names are immutable, so technically rename is not possible.
Updating a Kubernetes Deployment You can edit a Deployment by changing the container image from one version to the other, decreasing or increasing the number of instances by changing the ReplicaSet value. etc. For example, the container image nginx we have been using in our exercises has many versions.
Edit PODs and DeploymentsRun the kubectl edit pod <pod name> command. This will open the pod specification in an editor (vi editor). Then edit the required properties.
I'm sorry, but object names in kubernetes cannot be changed. They're immutable. You'd have to delete and deploy the Deployment with a different name to get what you want.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With