StatefulSet: How to manage stateful applications?

It's just that the state information of some applications is not very important, and they can run normally even without restoring the state. This is what we often call "stateless applications". A typical example of a "stateless application" is a web server like Nginx, which only processes HTTP requests and does not generate data (except logs).

For some applications, the running status information is very important. It is absolutely unacceptable to lose the state due to restart. Such applications are "stateful applications".

Because only Deployment is used, multiple instances are irrelevant, the order of startup is not fixed, and the name, IP address, and domain name of the Pod are also completely random, which is the characteristic of "stateless application".

But for "stateful applications", there may be dependencies between multiple instances, such as master/slave, active/passive, which need to be started in order to ensure the normal operation of the application, and external clients may also use fixed network identifiers to access instance, and the information must be guaranteed to remain unchanged after the Pod is restarted.

On the basis of Deployment, Kubernetes defines a new API object with a well-understood name called StatefulSet, which is specially used to manage stateful applications.

Service itself will have a domain name in the format of "object name. namespace", and each Pod will also have a domain name in the format of "IP address. namespace". However, because the IP address is unstable, the Pod domain name is not practical. Generally, we will use a stable Service domain name.

Service finds that these Pods are not ordinary applications, but stateful applications that require a stable network identifier, so a new domain name will be created for the Pod in the format of "Pod name. Service name. Namespace.svc. cluster.local". Of course, this domain name can also be abbreviated as "Pod name. Service name".

In order to emphasize the one-to-one binding relationship between persistent storage and StatefulSet, Kubernetes specifically defines a field "volumeClaimTemplates" for StatefulSet, and directly embeds the PVC definition into the YAML file of StatefulSet. This ensures that when the StatefulSet is created, a PVC is automatically created for each Pod, making the StatefulSet more available.

This article is a study note for Day 20 in July. The content comes from Geek Time "Kubernetes Introductory Practical Course". This course is recommended.

Supongo que te gusta

Origin blog.csdn.net/key_3_feng/article/details/131833881
Recomendado
Clasificación