It's not possible to change the name of a running pod, as the API will not accept 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:
I strongly recommend using statefulSet as advised. However, Keep in mind that editing specifications of a running pod should be approached with caution to avoid disruptions. The following fields can be edited for an existing pod:
- spec.containers[*].image
- spec.initContainers[*].image
- spec.activeDeadlineSeconds
- spec.tolerations
To make changes, you have two options:
Using kubectl edit:
Run kubectl edit pod <pod name>
to open the pod specification in the vi editor. Attempting to save changes directly will be denied, but a copy of the modified file is saved at a temporary location. Delete the existing pod with kubectl delete pod , then create a new pod with the changes using kubectl create -f /tmp/kubectl-edit-<random-string>.yaml.
in your case kubectl create -f /tmp/kubectl-edit-oh43e.yaml
Using exported YAML:
Extract the pod definition to a YAML file with kubectl get pod <pod name> -o yaml > my-new-pod.yaml
. Edit the exported file using an editor like vi (vi my-new-pod.yaml). Save the changes, delete the existing pod with kubectl delete pod , and create a new pod using kubectl create -f my-new-pod.yaml
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