Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

42 of kubernetes practice: StatefulSet

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

One: preface

1. Scenarios using StatefulSet

a. Stable and unique network identification

b. Stable and persistent storage

c. Orderly, elegant deployment and expansion

d. Delete and terminate gracefully in order

e. Automatically scrolling updates in order

Limitations of 2.StatefulSet

a. Prior to Kubernetes 1.9, it was the beta version, and it was not available before Kubernetes 1.5.

B.Pod storage is provided by PersistentVolume (the storage class or pre-created by the administrator).

c. Deleting or downsizing StatefulSet will not delete the data volumes associated with StatefulSet, which ensures the security of the data.

d. The current StatefulSets requires a Headless service to provide network identity for the Pod, and this Headless service needs to be created manually.

Second, storage and supply mode

1. Static resource provisioning mode, which is bound through PV and PVC.

two。 Dynamic resource supply mode, which completes resource dynamic binding through StorageClass and PVC

Third: StatefulSet Nginx application example

1. Create three pv (name is glusterfs-nginx-0,glusterfs-nginx-1,glusterfs-nginx-2)

Click (here) to collapse or open

ApiVersion: v1

Kind: PersistentVolume

Metadata:

Name: glusterfs-nginx-0

Namespace: default

Spec:

Capacity:

Storage: 1Gi

AccessModes:

-ReadWriteOnce

Glusterfs:

Endpoints: "glusterfs-cluster"

Path: "k8s-volume"

ReadOnly: false

two。 Create three pvc (name is glusterfs-nginx-0,glusterfs-nginx-1,glusterfs-nginx-2)

Click (here) to collapse or open

Kind: PersistentVolumeClaim

ApiVersion: v1

Metadata:

Name: glusterfs-nginx-0

Namespace: default

Spec:

AccessModes:

-ReadWriteOnce

Resources:

Requests:

Storage: 1Gi3. Create a Headless service

Click (here) to collapse or open

ApiVersion: v1

Kind: Service

Metadata:

Name: nginx

Labels:

Name: nginx

Spec:

Ports:

-port: 80

TargetPort: 80

ClusterIP: None

Selector:

Role: mongo4. Create StatefulSet

Click (here) to collapse or open

ApiVersion: apps/v1beta1

Kind: StatefulSet

Metadata:

Name: nginx

Spec:

ServiceName: "nginx"

Replicas: 3

Template:

Metadata:

Labels:

Role: nginx

Spec:

TerminationGracePeriodSeconds: 10

Containers:

-name: nginx

Image: nginx

Ports:

-containerPort: 80

VolumeMounts:

-name: glusterfs

MountPath: / usr/share/nginx/html

VolumeClaimTemplates:

-metadata:

Name: glusterfs

Spec:

AccessModes: ["ReadWriteOnce"]

Resources:

Requests:

Storage: 1Gi IV: remarks

1.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.

two。 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.

3. 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.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report