StatefulSets are a type of workloads whose data or status is stored while they are running. For example, MySQL is a StatefulSet because it needs to store new data.
A container can be migrated between different hosts, but data is not stored on the hosts. To store StatefulSet data persistently, attach HA storage volumes provided by CCE to the container.
If a pod has multiple containers, ensure that the ports used by the containers do not conflict with each other. Otherwise, creating the StatefulSet will fail.
Settings in the YAML file are synchronized with those on the console. You can edit the YAML file on the console to create a workload. For example:
When you click Create YAML on the right of the console, do not create multiple YAML files in the YAML definition pane displayed. You need to create them one by one. Otherwise, an error will be reported during the creation.
Parameter |
Description |
---|---|
* Workload Name |
Name of a workload, which must be unique. Enter 4 to 52 characters starting with a lowercase letter and ending with a letter or digit. Only lowercase letters, digits, and hyphens (-) are allowed. |
* Cluster Name |
Cluster to which the workload belongs. |
* Namespace |
In a single cluster, data in different namespaces is isolated from each other. This enables applications to share the services of the same cluster without interfering each other. If no namespace is set, the default namespace is used. |
* Instances |
Number of pods in a workload. A workload can have one or more pods. The default value is 2. You can customize the value, for example, setting it to 1. Each workload pod consists of the same containers. You can configure multiple pods for a workload to ensure high reliability. For such a workload, if one pod is faulty, the workload can still run properly. If only one pod is used, a node or pod exception may cause service exceptions. |
Time Zone Synchronization |
If this parameter is enabled, the container and the node use the same time zone. NOTICE:
After time zone synchronization is enabled, disks of the hostPath type will be automatically added and listed in the Data Storage > Local Volume area. Do not modify or delete the disks. |
Description |
Description of the workload. |
Parameter |
Description |
---|---|
Image Name |
Name of the image. You can click Change Image to update it. |
*Image Version |
Select the image tag to be deployed. |
*Container Name |
Name of the container. You can modify it. |
Privileged Container |
Programs in a privileged container have certain privileges. If Privileged Container is On, the container is granted superuser permissions. For example, privileged containers can manipulate network devices on the host machine and modify kernel parameters. |
Container Resources |
CPU
Memory
For more information about Request and Limit, see Setting Container Specifications. GPU: configurable only when the cluster contains GPU nodes. It indicates the percentage of GPU resources reserved for a container. Select Use and set the percentage. For example, if this parameter is set to 10%, the container is allowed to use 10% of GPU resources. If you do not select Use or set this parameter to 0, no GPU resources can be used. GPU/Graphics Card: The workload's pods will be scheduled to the node with the specified GPU. If Any GPU type is selected, the container uses a random GPU in the node. If you select a specific GPU, the container uses this GPU accordingly. |
To edit an environment variable that has been set, click Edit. To delete an environment variable that has been set, click Delete.
You can add data storage volumes only when creating a StatefulSet.
Enter the user ID to set container permissions and prevent systems and other containers from being affected.
Parameter |
Description |
---|---|
Service Name |
Name of the Service corresponding to the workload for mutual access between pods. This Service is used for internal discovery of pods, and does not require an independent IP address or load balancing. |
Port Name |
Name of the container port. You are advised to enter a name that indicates the function of the port. |
Container Port |
Listening port inside the container. |
Click Add Service and set the workload access type.
If your workload will be reachable to other workloads or public networks, add a Service to define the workload access type.
The workload access type determines the network attributes of the workload. Workloads with different access types can provide different network capabilities. For details, see Overview.
During a rolling upgrade, old pods are gradually replaced with new ones, and service traffic is evenly distributed to both pods to ensure service continuity.
Ordered: The StatefulSet will deploy, delete, or scale pods in order and one by one (the StatefulSet waits until each pod is ready before continuing). This is the default policy.
Parallel: The StatefulSet will create pods in parallel to match the desired scale without waiting, and will delete all pods at once.
The following procedure uses an etcd workload as an example to describe how to create a workload using kubectl.
etcd-statefulset.yaml is an example file name, and you can change it as required.
vi etcd-statefulset.yaml
The following provides an example of the file contents. For more information on StatefulSet, see the Kubernetes documentation.
apiVersion: apps/v1 kind: StatefulSet metadata: name: etcd spec: replicas: 2 selector: matchLabels: app: etcd serviceName: etcd-svc template: metadata: labels: app: etcd spec: containers: - env: - name: PAAS_APP_NAME value: tesyhhj - name: PAAS_NAMESPACE value: default - name: PAAS_PROJECT_ID value: 9632fae707ce4416a0ab1e3e121fe555 image: etcd # If you use an image in My Images, obtain the image path from SWR. imagePullPolicy: IfNotPresent name: container-0 updateStrategy: type: RollingUpdate
vi etcd-headless.yaml
apiVersion: v1 kind: Service metadata: labels: app: etcd name: etcd-svc spec: clusterIP: None ports: - name: etcd-svc port: 3120 protocol: TCP targetPort: 3120 selector: app: etcd sessionAffinity: None type: ClusterIP
kubectl create -f etcd-statefulset.yaml
If the following information is displayed, the StatefulSet has been successfully created.
statefulset.apps/etcd created
kubectl create -f etcd-headless.yaml
If the following information is displayed, the headless service has been successfully created.
service/etcd-svc created