Context
A common speed trick: generate a pod with kubectl run ... --dry-run=client -o yaml, then rename the container with sed before applying.
Insight
kubectl writes each container’s fields in alphabetical order, so the list item starts with - image:, and name: sits on the next line without the dash:
containers: - image: nginx:1.27 name: webpodA pattern like s/- name: webpod/- name: webcont/ never matches. sed still exits 0, so you get no error, and the pod is created with the old container name. Later steps that use the new name then fail, such as kubectl set image pod/webpod webcont=....
Fix
Match the indented line instead, or edit in vim, and check the result:
kubectl run webpod --image=nginx:1.27 --dry-run=client -o yaml > pod.yamlsed -i 's/^ name: webpod$/ name: webcont/' pod.yaml # GNU sed; macOS: sed -i ''kubectl apply -f pod.yamlkubectl get pod webpod -o jsonpath='{.spec.containers[0].name}{"\n"}' # webcontmetadata.name stays webpod, because only the container’s indented line matches.