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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,459,871
Community Members
 
Community Events
176
Community Groups

How to ovewrite an existing pod in kubernetes cluster

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

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 Apr 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.

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

Yevhen Atlassian Team Apr 28, 2022

@yosser_mahfoudh you will have to explicitly delete it.

could you pleqse give me an example.

Yevhen Atlassian Team Apr 28, 2022

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

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 Apr 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)

But it will know which pod I want to delete ?

Yevhen Atlassian Team Apr 28, 2022

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

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

Yevhen Atlassian Team Apr 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).

@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 Apr 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

Atlassian Community Events