A StatefulSet is an application that needs to retain data or state while running. StatefulSets are ideal for stateful applications, such as databases, cache services, and message queues. Unlike Deployments, StatefulSets have the following features:
Parameter | Description |
|---|---|
Workload Type | Select StatefulSet. For details about different workload types, see Workload Overview. |
Workload Name | Enter a name for the workload. Enter 1 to 63 characters starting with a lowercase letter and ending with a lowercase letter or digit. Only lowercase letters, digits, and hyphens (-) are allowed. |
Namespace | Select a namespace for the workload. The default value is default. You can also click Create Namespace to create one. For details, see Creating a Namespace. |
Pods | Enter the number of workload pods. |
Container Runtime | A CCE standard cluster uses a common runtime by default, whereas a CCE Turbo cluster supports both common and secure runtimes. For details about their differences, see Secure Runtime and Common Runtime. |
Time Zone Synchronization | Configure whether to enable time zone synchronization. After this function is enabled, the container and node will share the same time zone. Time zone synchronization relies on the local disk mounted to the container. Do not modify or delete the local disk. For details, see Configuring Time Zone Synchronization. |
If you configured multiple containers for a pod, ensure that the ports used by each container do not conflict with each other, or the workload cannot be deployed.
Parameter | Description |
|---|---|
Container Name | Enter a name for the container. |
Pull Policy | Image update or pull policy. If you select Always, the image is pulled from the image repository each time. If you do not select Always, the existing image of the node is preferentially used. If the image does not exist, the image is pulled from the image repository. |
Image Name | Click Select Image and select the image used by the container. To use a third-party image, directly enter image path. Ensure that the image access credential can be used to access the image repository. For details, see Using Third-Party Images. |
Image Tag | Select the image tag to be deployed. |
CPU Quota |
If Request and Limit are not specified, the quota is not limited. For more information and suggestions about Request and Limit, see Configuring Container Specifications. |
Memory Quota |
If Request and Limit are not specified, the quota is not limited. For more information and suggestions about Request and Limit, see Configuring Container Specifications. |
(Optional) GPU Quota | Configurable only when the cluster contains GPU nodes and the CCE AI Suite (NVIDIA GPU) add-on has been installed.
For details about how to use GPUs in a cluster, see Default GPU Scheduling in Kubernetes. |
(Optional) Privileged Container | Programs in a privileged container have certain privileges. If this option is enabled, the container will be assigned privileges. For example, privileged containers can manipulate network devices on the host machine, modify kernel parameters, access all devices on the node. For more information, see Pod Security Standards. |
(Optional) Init Container | Whether to use the container as an init container. An init container does not support health check. An init container is a special container that runs before other app containers in a pod are started. Each pod can contain multiple containers. In addition, a pod can contain one or more init containers. Application containers in a pod are started and run only after the running of all init containers completes. For details, see Init Containers. |
(Optional) Run Option | Add run options for the container. For details, see Pod. CCE supports the following run options:
|
Dynamic mounting is achieved by using the volumeClaimTemplates field and depends on the dynamic creation capability of StorageClass. A StatefulSet associates each pod with a PVC using the volumeClaimTemplates field, and the PVC is bound to the corresponding PV. Therefore, after the pod is rescheduled, the original data can still be mounted based on the PVC name.
To disable the collection of the standard output logs of the current workload, add the annotation kubernetes.AOM.log.stdout: [] in Labels and Annotations in the Advanced Settings area. For details about how to use this annotation, see Table 1.
A headless Service provides a fixed access domain name for every pod within a StatefulSet for mutual pod access. For details, see Headless Service.
A Service provides external access for pods. With a static IP address, a Service forwards access traffic to pods and automatically balances load for these pods.
You can also create a Service after creating a workload. For details about Services of different types, see Service Overview.
Parameter | Description |
|---|---|
Upgrade | Specify the upgrade mode and parameters of the workload. Rolling upgrade and Replace upgrade are available. For details, see Upgrading and Rolling Back a Workload. |
Pod Management Policies | For some distributed systems, the StatefulSet ordering guarantees are unnecessary and/or undesirable. These systems require only uniqueness and identifiers.
|
Scheduling | Configure affinity and anti-affinity policies for flexible workload scheduling. Load affinity and node affinity are provided.
|
Toleration | Using both taints and tolerations allows (not forcibly) the pod to be scheduled to a node with the matching taints, and controls the pod eviction policies after the node where the pod is located is tainted. For details, see Configuring Tolerance Policies. |
Labels and Annotations | Add labels or annotations for pods using key-value pairs. After the setting, click Confirm. For details about labels and annotations, see Configuring Labels and Annotations. |
DNS | Configure a separate DNS policy for the workload. For details, see DNS Configuration. |
Network Configuration |
|
In this example, a Nginx workload is used and the EVS volume is dynamically mounted to it using the volumeClaimTemplates field.
nginx-statefulset.yaml is an example file name, and you can change it as required.
vi nginx-statefulset.yaml
The below content shows only an example. For details about StatefulSets, see the Kubernetes official documentation.
apiVersion: apps/v1kind: StatefulSetmetadata:name: nginxspec:selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: container-1image: nginx:latestimagePullPolicy: IfNotPresentresources:requests:cpu: 250mmemory: 512Milimits:cpu: 250mmemory: 512MivolumeMounts:- name: testreadOnly: falsemountPath: /usr/share/nginx/htmlsubPath: ''imagePullSecrets:- name: default-secretdnsPolicy: ClusterFirstvolumes: []serviceName: nginx-svcreplicas: 2volumeClaimTemplates: # Dynamically mounts the EVS volume to the workload.- apiVersion: v1kind: PersistentVolumeClaimmetadata:name: testnamespace: defaultannotations:everest.io/disk-volume-type: SAS # SAS EVS volume type.labels:failure-domain.beta.kubernetes.io/region: ru-moscow-1 # region where the EVS volume is created.failure-domain.beta.kubernetes.io/zone: # AZ where the EVS volume is created. It must be the same as the AZ of the node.spec:accessModes:- ReadWriteOnce # The value must be ReadWriteOnce for the EVS volume.resources:requests:storage: 10GistorageClassName: csi-disk # StorageClass name. The value is csi-disk for the EVS volume.updateStrategy:type: RollingUpdate
Create the nginx-headless.yaml file.
vi nginx-headless.yaml
File content:
apiVersion: v1kind: Servicemetadata:name: nginx-svcnamespace: defaultlabels:app: nginxspec:selector:app: nginxversion: v1clusterIP: Noneports:- name: nginxtargetPort: 80nodePort: 0port: 80protocol: TCPtype: ClusterIP
kubectl create -f nginx-statefulset.yaml
If information similar to the following is displayed, the StatefulSet has been created:
statefulset.apps/nginx created
Create a headless Service.
kubectl create -f nginx-headless.yaml
If the following information is displayed, the headless service has been successfully created.
service/nginx-svc created