Kubernetes stateless service and state service

Stateless Service

  1. Refers to an instance of the service does not run for the persistent local storage of data and results for multiple instances of the same request response is exactly the same.
  2. Multiple instances can share the same persistent data. For example: nginx instance, tomcat examples, etc.
  3. Related k8s resources: ReplicaSet, ReplicationController, Deployment and so on, because the service is stateless, so the pod controller creates these numbers are random values. And when the volume reduction of volume reduction does not clear one pod, but random, because the return value is the same for all instances get, so any volume reduction can be a pod.

Stateful service

  1. Pets and cattle analogy, cattle farmers can lose if the disease re-buy one, if pet owners pet is sick and died not find one exactly the same pet.
  2. Stateful service can be said to be in need of services data storage function, or to a multi-threaded type of service, queue and so on. (Mysql database, kafka, zookeeper, etc.) for each instance requires its own separate persistent storage, and k8s is stated to be defined by the template. Persistent volumes stated before creating a template to create a pod, bound to the pod, the template can define multiple.
 volumeClaimTemplates:
  - metadata:
      name: zookeeper
    spec:
      selector:
        matchLabels:
          app: zookeeper
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 3Gi

Description: stateful pod is used to running state of the application, so its very important data stored on the data volume, delete this statement when Statefulset volume reduction would be disastrous, especially for Statefulset, the volume reduction like reducing its value as simple replicas. For this reason, when you need to release a certain volume of durable, long-lasting volume you want to delete the corresponding statement manually.

K8s related resources: statefulSet, because it is stateful service, each pod has a specific name and network identification. For example pod name by name + statefulSet ordered numbers (0,1,2 ..)

Volume reduction during the operation, you can know exactly which one pod will shrink capacity, starting with the largest numbers. And Stat Pat fulset example in the presence of unhealthy situation is allowed to do volume reduction operation. StatefulSet volume reduction operation at any time only instance of a pod, so there will not be very fast shrinking capacity status of the application. For example, if a distributed storage applications while offline plurality of nodes, which may result in data loss. For example, the number of copies of a data item to data storage applications 2, if there are two nodes off the assembly line at the same time, a data record will be lost, if it happens to save on both nodes. If the volume reduction is linear, distributed storage applications have time to copy the missing copies to other nodes to ensure that data is not lost.

Published 352 original articles · won praise 390 · views 370 000 +

Guess you like

Origin blog.csdn.net/qq_19734597/article/details/104083559