“This is the 16th day of my participation in the First Challenge 2022. For details: First Challenge 2022”

【 K8S series 】 K8S learning 26, how to deploy stateful applications 1?

We can delete any POD we want, and the copy manager will immediately create a pod for us

So if our pod has persistent volume, then we can use the old method?

Stateful and stateless

A brief explanation of what a stateful service is and what a stateless service is:

Stateful service

  • The services themselves depend on the state in the environment and may require a database to persist the state data
  • At some point, a request can only be processed by one instance of the service
  • State data is stored, and the entire system may change if the instance needs to be extended

Stateless service

  • The service itself does not depend on its state
  • Any external request to any instance of the service will get the correct expected response
  • Can scale horizontally, can do load balancing, does not store its own state machine

Review the ReplicaSet

RS/RC is the controller that manages the pods, and the pods created are created from a preset template. There is no difference between these pods

We mentioned the data above. What if we added a declared persistent volume to RS?

Will all pods share a persistent volume declaration like this?

Or would you declare a separate persistent volume for each POD?

The answer, of course, is the former

We create an RS, which will create and delete multiple pods according to the number of pod copies. If we specify a persistent volume, then multiple PODS share the same volume

Since all our PODS are generated from the POD template, the POD template has already specified the specific persistent volume, no matter how many pods are generated, they all share a persistent volume

Unless we create multiple RS’s

What if we needed just one RS and each POD we created could enjoy a separate persistent volume declaration?

I’m sorry, K8S is not supported at the moment, maybe it can be supported in the future

Looking back, if we needed a POD for a persistent volume declaration, a persistent volume, then an RS would have to create a POD to do that

So how do we expand and shrink?

It is a nuisance, this action cannot be automatically dynamically expanding capacity, can we manually to delete the RS or modify the copy number of the RS, and to scale out, after our infinite change of RS, it really is too heavy, cloud native is never look like this, there must be a good way

Multiple PODS sharing a persistent volume, but using different directories?

That sounds good. Could we have multiple pods sharing a persistent volume, but using different directories, something like the following?

Well, based on the schematic, it seems to work

When we think about it, we know it’s not very good

Different pods need to dynamically specify different directories for persistent volumes. How do you do this? These pods are created from the same template. How do they change dynamically?

After all, you still need multiple RS’s, with different RS specifying the same persistent volume and different POD templates specifying the mount path they want to use

So is RS really unable to handle the above requirements? Create an RS so that multiple PODS have their own independent persistent volumes

Yes, we just can’t deal with it. Let’s see if K8S has any other ways to deal with this demand. Rest assured, we can definitely solve it

Today is here, learning, if there is a deviation, please correct

Welcome to like, follow and favorites

Friends, your support and encouragement, I insist on sharing, improve the quality of the power

All right, that’s it for this time

Technology is open, our mentality, should be more open. Embrace change, live in the sun, and strive to move forward.

I am Nezha, welcome to like, see you next time ~