How to change a running pod name?

6/23/2018
  1. eg. I have 2 pods, they were called nginx-111-xxx, nginx-111-yyy, but there is something wrong in nginx-111-xxx, I need to create a new pod to replace it because the demands acquire you to delete nginx-111-xxx, then a NEW pods nginx-111-zzz, Can I rename nginx-111-zzz with nginx-111-xxx? I try to use kubectl edit command to achieve it,
  2. But Kubernetes said copy of your changes has been stored to "/tmp/kubectl-edit-oh43e.yaml" error: At least one of apiVersion, kind and name was changed, so If there is a way to change the name of the running pod ?enter image description here
-- Layne Liu
kubernetes

1 Answer

6/23/2018

It's not possible to change the name of a running pod, as the API will not except this.

The random pod names come in fact you are using kubernetes deployments, which are the default or most commonly used ways to run pods on kubernetes. But there are different ways to schedule pods, beside of that.

However, it looks like you need more predictable pod names for some reason. Here are some ways to go:

  1. use StatefulSets (https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/). The names of pods created by a StatefulSet will go like nginx-01, nginx-02 ..
  2. use pods directly. With that, you won't have those rolling update features from replicasets, DaemonSets etc, but absolute control about naming
-- David Steiman
Source: StackOverflow