Home > other >  How to save changes on pod in Kubernetes after pod deployed
How to save changes on pod in Kubernetes after pod deployed

Time:08-08

I have Jenkins deployment with one pod I want to make changes to the pod, for example, I wanna install and set up maven. I mounted volume to do pod. But when I restart the pod, changes made with kubectl exec are gone. But when I make changes in Jenkins GUI, changes are persistent. What is the reason behind it, and is there a way to save changes after pod deployed?

CodePudding user response:

The kubernetes pod (the docker container in general) is by default stateless, to make it stateful, you need to store the state somewhere (a database, cloud storage, or a persistent disk, ...).

In your case you use mount a volume to the pod, and the state is restored when you use Jenkins, so here is a few things to check:

  • is the volume mount after every deployment/restart?
  • do you execute the same command manually and in Jenkins GUI?
  • do you use the correct mount path when you execute the command manually?

CodePudding user response:

...I mounted volume to do pod...when I make changes in Jenkins GUI, changes are persistent.

By default changes made with Jenkins GUI is saved to the Jenkins home; presumably the location that you have mounted with a persistent volume.

What is the reason behind it,

When your pod goes away, the persistent volume remains in the system. You get back your changes when your pod come back online and mounted with the same volume. This means any changes that did not persist in the mounted volume will not be retain. This also means if your new pod cannot mount back the same persistent volume for any reason; you loose all the previous changes as well.

...and is there a way to save changes after pod deployed?

GUI or kubectl exec; any change that you want to persist thru Pod lifecycle; you ensure such change is always saves to the mounted volume; and the same volume is always available for new pod to mount.

  • Related