In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to manage stateful applications in Kubernetes". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor learn "how to manage stateful applications in Kubernetes".
In Kubernetes, StatefulSet is used to manage API objects for stateful applications. StatefulSets is stable in Kubernetes version 1.9. StatefulSet manages Pod deployment and expansion and provides assurance of order and uniqueness for these Pod. Similar to Deployment, StatefulSet manages Pod; based on spec specifications. Unlike Deployment, StatefulSet needs to maintain a unique identity for each Pod. These Pod are created based on the same spec, but cannot be replaced with each other, and each Pod retains its own persistence identity.
1. Scenarios using StatefulSet
StatefulSets is valuable for the following application scenarios:
Stable and unique network identification
Stable and persistent storage
Orderly, elegant deployment and expansion
Delete and terminate gracefully in order
Automatically scrolling updates in order
The above stability is synonymous with persistence, and if the application does not require stable identification or sequential deployment, deletion, and expansion, a stateless replica set should be used. The controller of Deployment or ReplicaSet is more suitable for stateless business scenarios.
2. Restrictions on StatefulSet
Prior to Kubernetes 1.9, it was the beta version, and it was not available before Kubernetes 1.5.
Pod storage is provided by PersistentVolume (the storage class or pre-created by the administrator).
Deleting or downsizing StatefulSet will not delete the data volumes associated with StatefulSet, which ensures the security of the data.
The current StatefulSets requires a Headless service to provide network identity for the Pod, and this Headless service needs to be created manually.
3. Components
Here is an example of what StatefuleSet consists of:
A Headless service called nginx is used to control the network domain.
A statefulSet named web has three replica sets of the nginx container (launched in a unique Pod).
VolumeClaimTemplates that uses PersistenVolumes (provided by PersistentVolume Provisioner) to provide stable storage.
ApiVersion:v1kind:Servicemetadata: name:nginx labels: app:nginxspec: ports:-port:80 name:web clusterIP:None / / Headless Service selector: app:nginx---apiVersion:apps/v1kind:StatefulSetmetadata: name:webspec: selector: matchLabels: app:nginx# has to match .spec.template.metadata.labels serviceName: "nginx" replicas:3 # by default is 1 template: metadata: labels: app:nginx # has to match .spec.selector.matchLabels spec: terminationGracePeriodSeconds:10 containers:-name:nginx image:k8s.gcr.io/nginx-slim:0.8 ports:-containerPort:80 name:web volumeMounts: # Mount data volume-name:www mountPath:/usr/share/nginx/html # the mount path is the container / usr/share/nginx/html volumeClaimTemplates: # data volume life template-metadata: name:www spec: accessModes: ["ReadWriteOnce"] storageClassName:my-storage-class resources: requests: storage:1Gi4, Pod selector
The sepc.selector of StatefulSet must be set to match .spec.template.metadata.labels. Prior to Kubernetes 1.8, spec.selector was negligible and was set to a default value. In version 1.8 or later, if you do not set sepc.selector, it will cause the creation of StatefulSet to fail.
5. Pod identity
StatfuleSet Pod has a unique identity, which consists of sequential, stable network identification and stable storage. This identity always follows the Pod, but it is dispatched to that Node.
5.1 ordinal Index (Ordinal Index)
For StatefulSet with N replica sets, each Pod in StatefulSet is assigned an integer ordinal between 0 and N, which is unique in the entire set.
5.2 Network ID (Stable Network ID)
In StatefulSet, the host name of each Pod consists of the name and ordinal of the StatefulSet. The format of the host name for Pod: $(statefulset name)-$(ordinal). If you create three Pod, their host name is web-0,web-1,web-2. StatefulSet can use Headless services to control the domain of Pod. The format of the domain managed by Service is: $(service name). $(namespace) .svc.cluster.local, and cluster.local is a cluster domain. For each Pod created, it will get a DNS subdomain in the format: $(podname). $(governing service domain), where the management service is set in StatefulSet, via serviceName.
Here is the name of Pod in StatefulSet in DNS:
5.3 stable Stora
Kubernetes creates a corresponding PersistentVolume for each VolumeClaimTemplate. In the previous nginx instance, each Pod will my-storage-class the storage space of the PersistenVolume single instance and 1Gib of the storage type.
If no storage class is specified, the default storage is used. But a Pod is dispatched to the Node, and its volumeMounts will attach the PersistentVolumes and associate it with the PersistentVolumeClaims. It is important to note that even if Pod is deleted, the association between PersistentVolumes and PersistentVolumeClaims will not be deleted.
5.4 Pod named label
When the StatefulSet controller creates a Pod, it will add a tag to this collection of Pod names. This tag will be able to manage services to the specified Pod.
6. Deployment and expansion guarantee
For a StatefulSet with N replica sets, when Pod is deployed, they will be created in the order from 0 to NMel 1.
When a Pod is deleted, they will be terminated in reverse order from 1 to 0.
All dependent Pod should be running and ready before Pod expansion.
Before Pod can be terminated, all Pod that depend on it must be stopped completely.
In the nginx example created earlier, web-0,web-1 and web-2 are deployed sequentially. Web-1 can only be deployed after the web-0 is running and ready, and web-2 can only be deployed after the web-1 is running and ready. If web-0 fails, even if web-1 is running, web-2 will not start properly unless web-0 is restarted and running properly.
If you scale down the above example and set replicas=1, then web-2 is terminated first, followed by web-1. If the web-0 fails after the web-2 is terminated, but before the web-1 is terminated, the web-1 cannot be terminated unless the web-0 is running normally.
6.1 Pod Management Policy
After Kubernetes 1.7, the unique identity of StatefulSet can be guaranteed by the value of .spec.podManagementPolicy.
6.1.1 OrderedReady Pod Management
OrderedReady pod management is the default management mode for StatefulSets, which sequentially starts or terminates Pod.
6.1.2 parallel Pod management
Parallel Pod management tells the StatefulSet controller to start or terminate all Pod in parallel.
7. Update strategy
After Kubernetes 1.7, run to automatically update Pod containers, tags, resource requests / restrictions, and comments by configuring StatefulSet's .spec.updateStrategy.
7.1 On Delete Policy
The OnDelete update policy is the behavior of versions prior to 1.6. When the .spec.updatecontaingy.type of StatefulSet is set to OnDelete, the StatefulSet controller will not know to update the Pod.
7.2 Rolling Updates Policy
The RollingUpdate update policy implements automatic scrolling updates of Pod in StatefulSet, which is the default update mode for StatefulSet. If .spec.updatecontaingy.type is set to RollingUpdate, the StatefulSet controller will delete and rebuild each Pod in the StatefulSet. It will terminate the Pod from the highest to the lowest ordinal and rebuild the Pod in the order from smallest to largest.
7.3 Partitions
RollingUpdate update policies can be delimited by specifying .spec.updatedategy.rollingUpdate.partition. When delimiting is specified, all Pod with ordinal greater than or equal to delimited will be updated, and other Pod will not be updated. In most cases, separation is not used; separation is useful when you want a canary release, or a run-time release.
At this point, I believe you have a deeper understanding of "how to manage stateful applications in Kubernetes". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.