v2.0
v1.0
  1. Release Notes
    1. Release Notes - 2.0.2Latest
    1. Release Notes - 2.0.1
    1. Release Notes - 2.0.0
  1. Introduction
    1. Introduction
    1. Features
    1. Architecture
    1. Advantages
    1. Glossary
  1. Installation
    1. Intruction
      1. Intro
      2. Port Requirements
    1. Install on Linux
      1. All-in-One Installation
      2. Multi-Node Installation
      3. Installing HA Master and Etcd Cluster
      4. Storage Configuration Instruction
    1. Install on Kubernetes
      1. Prerequisites
      2. Online Installation
      3. Offline Installation
    1. Related Tools
      1. Integrating Harbor Registry
    1. Cluster Operation
      1. Adding New Nodes
      2. High Risk Operation
      3. Uninstalling KubeSphere
  1. Quick Start
    1. Getting Started with Multitenancy
    1. Exposing your APP using Ingress
    1. Deploying a MySQL Application
    1. Deploying a Wordpress Website
    1. Job to compute π to 2000 places
    1. Deploying Grafana using APP Template
    1. Creating Horizontal Pod Autoscaler
    1. S2i: Publish your app without Dockerfile
    1. Canary Release of Microservice APP
    1. CI/CD based on Spring Boot Project
    1. Building a Pipeline in a Graphical Panel
    1. CI/CD based on GitLab and Harbor
    1. Ingress-Nginx for Grayscale Release
  1. Cluster Admin Guide
    1. Multi-tenant Management
      1. Overview of Multi-tenant Management
      2. Overview of Role Management
    1. Platform Management
      1. Account Management
      2. Platform Roles Management
    1. Infrastructure
      1. Service Components
      2. Nodes
      3. Storage Classes
    1. Monitoring Center
      1. Physical Resources
      2. Application Resources
    1. Application Repository
    1. Jenkins System Settings
  1. User Guide
    1. Application Template
    1. Workloads
      1. Deployments
      2. StatefulSets
      3. DaemonSets
      4. Jobs
      5. CronJobs
    1. Storage
      1. Volumes
    1. Network & Services
      1. Services
      2. Routes
    1. Configuration Center
      1. Secret
      2. ConfigMap
      3. Image Registry
    1. Project Settings
      1. Basic Information
      2. Member Roles
      3. Project Members
      4. Internet Access
    1. DevOps Project
      1. DevOps Project Management
      2. DevOps Project Management
      3. DevOps Project Management
      4. DevOps Project Management
      5. DevOps Project Management
  1. Development Guide
    1. Preparing the Development Environment
    1. Development Workflow
  1. API Documentation
    1. API Guide
    1. How to invoke KubeSphere API
KubeSphere®️ 2020 All Rights Reserved.

StatefulSets

A StatefulSet operates under the same pattern as any other Controller. You define your desired state in a StatefulSet object. StatefulSets are valuable for applications that require one or more of the following.

  • Stable, unique network identifiers.
  • Stable, persistent storage.
  • Ordered, graceful deployment and scaling.
  • Ordered, automated rolling updates.

This document just describes the parameters or field meanings that may be used in creating a StatefulSet, for its management please refer to Workload Management. At the same time, Quick Start - Deploy a MySQL Application can also help you quickly understand StatefulSets.

Create a StatefulSet

Sign in with project-regular, enter into one project (e.g. demo-namespace), then select Workload → StatefulSets.

Create a StatefulSet

Step 1: Fill in the Basic Information

1.1. Click Create StatefulSet button, then fill in the basic information in the pop-up window. There are three ways to create a Statefulset, i.e. fill in the creation table, upload Yaml file and edit mode. The following mainly introduces each step within creation table. If you prefer edit mode, you can click on the edit mode button, it supports the yaml and json formats. Edit mode makes it easy for users who are used to command operations.

Edit mode

1.2. On the basic information page, enter the name of the StatefulSet, you can also fill in the description as required.

  • Name: A concise and clear name for this StatefulSet, which is convenient for users to browse and search.
  • Alias: Helps you better distinguish resources and supports Chinese.
  • Description: A brief introduction to StatefulSet.

Click Next when you're done.

Fill in the Basic Information

Step 2: Configure the Pod template

2.1. On the Pod Template page, user can set the number of replicas.

Click Add Container to add a container image as needed.

Add Container

2.2. The image defined in the template is pulled from the DockerHub by default. Enter the name of the container and the corresponding image name. The image name generally needs to be specified with its tag, such as mysql:5.6.

In order to realize the effective scheduling and allocation of resources in the cluster and improve resources utilization, the platform uses requests and limits to allocate resources. Request is usually the minimum resource requirement used by the container, and limit is usually the maximum value of the resource. Setting it to 0 means that there is no restriction on the resources used. Request can ensure that the pod has enough resources to run, and limit is to prevent a Pod from using resources unrestricted,causing other Pods to crash.

Table 1: CPU Quota Description

Parameter Description
Requests A request is the amount of that CPU resources that the system will guarantee for the container, and Kubernetes will use this value to decide on which node to place the pod.
Limits A limit is the maximum amount of CPU resources that Kubernetes will allow the container to use.

Table 2: Memory Quota Description

Parameter Description
Requests A request is the amount of that memory resources that the system will guarantee for the container, and Kubernetes will use this value to decide on which node to place the pod.
Limits A limit is the maximum amount of memory resources that Kubernetes will allow the container to use. If the memory usage exceeds this limit, the container may be killed.

Advanced Options

2.3. If the user has further requirements, click on Advanced Options.

  • Health Check: Kubernetes defines two types of health check probes for monitoring at the business level.    - Liveness Probe: Restarts the application when it detects that the container instance is unhealthy.    - Readiness Probe: To know when a Container is ready to start accepting traffic. A Pod is considered ready when all of its Containers are ready.
  • Command: In some cases, you need your command to run in a shell, see Kubernetes documentation.
  • Arguments: You can defined the arguments directly by providing strings, see Kubernetes documentation.
  • Ports: This is the container port that needs to be exposed. The port protocol can be TCP and UDP.
  • Environment Variables: you can define an argument for a Pod using any of the techniques available for defining environment variables, including ConfigMaps and Secrets, which has the same effect as the "ENV" in the Dockerfile, providing great flexibility for creating workloads.

    • Reference Configuration Center: Supports adding Secret and ConfigMap as environment variables to save configuration data in the form of key-value pairs. See ConfigMaps and Secrets.
  • Image Pull Policy: imagePullPolicy, the default image pull policy is IfNotPresent, the kubelet will no longer pull the image if the image already exists. If you need to pull the image frequently, set the pull policy to Always. If the container property imagePullPolicy is set to IfNotPresent or Never, the local image will be used first.

Click Save when setup is complete.

Pod template

Update Strategy

Update policies include RollingUpdate and OnDelete:

  • RollingUpdate: It is recommended to update the StatefulSets using Rolling-update. The StatefulSet controller will delete and recreate each Pod in the StatefulSet.

  • OnDelete: the StatefulSet controller will not automatically update the Pods in a StatefulSet. Users must manually delete Pods to cause the controller to create new Pods that reflect modifications made to a StatefulSet.

    • Partition: Default value is 0. If a partition is specified, all Pods with an ordinal that is greater than or equal to the partition will be updated when the StatefulSet’s template is updated. In most cases you will not need to use a partition, but they are useful if you want to stage an update, roll out a canary, or perform a phased roll out.

Update Strategy

After completing the above configuration information, click Next.

Step 3: Volume Template

3.1. Click Add Volume Template.

Add Volume Template

3.2. Fill in the name of the volume, select the storage type (e.g. local or csi-qingcloud), and the storage class needs to be created in advance, see Create Storage Class. Then specify the capacity and access mode of the volume to determine the mount path of the volume in the container, as described in Volumes.

Volume Template

Click on the Save button when you're done, then choose Next.

Step 4: Service Configuration

StatefulSets currently require a Headless Service to be responsible for the network identity of the Pods. THe service name could be customerized, The target port corresponds to the port exposed by the container.

Service Configuration

Click on the Next button when you're done.

Step 5: Label Settings

Labels are key/value pairs that are attached to objects, such as pods. Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users. Labels can be used to organize and to select subsets of objects, each object can have a set of key/value labels defined, such as app: mysql ; tier: frontend.

Label Settings

Click on the Next button when you're done.

Step 6: Node Selector

For the pod to be eligible to run on a node, the node must have each of the indicated key-value pairs as labels (it can have additional labels as well). The user can specify the node on which the Pod is expected to run by setting one or more sets of key-value pairs or select node directly. When not specified, the Pod will likely be scheduled to any node in the cluster that meets the resource scheduling criteria.

Node Selector

Click Create to complete the creation of the StatefulSet resource. The status display “Updating” is due to it's pulling the image. After the image pull succeeds, the status will display “Running”.