Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to ovewrite an existing pod in kubernetes cluster

yosser_mahfoudh April 28, 2022

I want to deploy a pod name core-x but that pod is already running in my cluster what I want is to overwrite the old one with the new one.

Knowing that my image version has the same tag?

I need your help please

2 answers

0 votes
yosser_mahfoudh April 28, 2022
pipeatlassian/kubectl-run:3.2.0
variables:
KUBE_CONFIG$KUBE_CONFIG
KUBECTL_COMMAND'delete -f masster/build/kubernetes/core-srv.yaml
 | apply'
RESOURCE_PATH'core-srv.yaml'
sleep: 10s 
@Yevhen  like this?
0 votes
Yevhen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 28, 2022

@yosser_mahfoudh you can't create a new pod with the same name and you can't change name of the existing pod too since name and namespace fields are immutable. Some of the fields can be changed though.

yosser_mahfoudh April 28, 2022

So if I create a new pod named core-Y. how the core-X stop runing in my kubernetes cluster?

Yevhen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 28, 2022

@yosser_mahfoudh you will have to explicitly delete it.

yosser_mahfoudh April 28, 2022

could you pleqse give me an example.

Yevhen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 28, 2022

That would be "kubectl delete pod $podName -n $namespace" if you're using kubectl.

yosser_mahfoudh April 28, 2022
This is what I have
step:
name: deploy
trigger: manual
script:
- echo VERSION_BACK=$(grep '<version>' pom.xml | head -1 | tail -1 | sed 's/[<>version/ \t]//g') > env.sh
- source env.sh
- cd /opt/atlassian/pipelines/agent/build/ && ls
- sed -i "s|{{image}}|imagename/core-srv:${VERSION_BACK}|g" core-srv.yaml
- pipe: atlassian/kubectl-run:3.2.0
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply'
RESOURCE_PATH: 'core-srv.yaml'
so should I replace apply by delete ?
Yevhen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 28, 2022

Yes. Perhaps, to delete the pod you don't need to run any sed against yaml. It'll be deleted as long as a pod with such a name exists in the namespace (its spec does not really matter)

yosser_mahfoudh April 28, 2022

But it will know which pod I want to delete ?

Yevhen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 28, 2022

It's will delete whatever is in metadata.name in your yaml.

yosser_mahfoudh April 28, 2022

I tried what you said but it deletes it and never restart creating the pod from the begin.

Yevhen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 28, 2022

@yosser_mahfoudh yes, this is what delete command is expected to do. In the next step you can apply again (I'd recommend adding a 10-15 second sleep to give apiserver time to delete the pod).

yosser_mahfoudh April 28, 2022

@Yevhen 

do you mean like this 

 pipeatlassian/kubectl-run:3.2.0
variables:
KUBE_CONFIG$KUBE_CONFIG
KUBECTL_COMMAND'delete -f masster/vuild/core-srv.yaml' | apply 
RESOURCE_PATH'core-srv.yaml'
Yevhen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 28, 2022

@yosser_mahfoudh I was more thinking about a new step. So your steps in the pipeline would differ by one command only.

Also, I'd recommend looking at an official K8s documentation and play with kubectl and your pod yaml in the command line to better understand kubectl and cluster behavior.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events