Class StatefulSet

  • All Implemented Interfaces:
    IPodSpec, IPodTemplate, IResource, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct

    @Generated(value="jsii-pacmak/1.52.1 (build 5ccc8f6)",
               date="2022-01-14T19:05:22.176Z")
    @Stability(Stable)
    public class StatefulSet
    extends Resource
    implements IPodTemplate
    StatefulSet is the workload API object used to manage stateful applications.

    Manages the deployment and scaling of a set of Pods, and provides guarantees about the ordering and uniqueness of these Pods.

    Like a Deployment, a StatefulSet manages Pods that are based on an identical container spec. Unlike a Deployment, a StatefulSet maintains a sticky identity for each of their Pods. These pods are created from the same spec, but are not interchangeable: each has a persistent identifier that it maintains across any rescheduling.

    If you want to use storage volumes to provide persistence for your workload, you can use a StatefulSet as part of the solution. Although individual Pods in a StatefulSet are susceptible to failure, the persistent Pod identifiers make it easier to match existing volumes to the new Pods that replace any that have failed.

    Using StatefulSets

    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.
    • Constructor Detail

      • StatefulSet

        protected StatefulSet​(software.amazon.jsii.JsiiObjectRef objRef)
      • StatefulSet

        protected StatefulSet​(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
      • StatefulSet

        @Stability(Stable)
        public StatefulSet​(@NotNull
                           software.constructs.Construct scope,
                           @NotNull
                           String id,
                           @NotNull
                           StatefulSetProps props)
        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        props - This parameter is required.
    • Method Detail

      • addContainer

        @Stability(Stable)
        @NotNull
        public Container addContainer​(@NotNull
                                      ContainerProps container)
        Add a container to the pod.

        Specified by:
        addContainer in interface IPodSpec
        Parameters:
        container - This parameter is required.
      • addVolume

        @Stability(Stable)
        public void addVolume​(@NotNull
                              Volume volume)
        Add a volume to the pod.

        Specified by:
        addVolume in interface IPodSpec
        Parameters:
        volume - This parameter is required.
      • selectByLabel

        @Stability(Stable)
        public void selectByLabel​(@NotNull
                                  String key,
                                  @NotNull
                                  String value)
        Configure a label selector to this deployment.

        Pods that have the label will be selected by deployments configured with this spec.

        Parameters:
        key - - The label key. This parameter is required.
        value - - The label value. This parameter is required.
      • getApiObject

        @Stability(Stable)
        @NotNull
        protected org.cdk8s.ApiObject getApiObject()
        The underlying cdk8s API object.

        Specified by:
        getApiObject in class Resource
        See Also:
        base.Resource.apiObject
      • getContainers

        @Stability(Stable)
        @NotNull
        public List<Container> getContainers()
        The containers belonging to the pod.

        Use addContainer to add containers.

        Specified by:
        getContainers in interface IPodSpec
      • getLabelSelector

        @Stability(Stable)
        @NotNull
        public Map<String,​String> getLabelSelector()
        The labels this statefulset will match against in order to select pods.

        Returns a a copy. Use selectByLabel() to add labels.

      • getPodManagementPolicy

        @Stability(Stable)
        @NotNull
        public PodManagementPolicy getPodManagementPolicy()
        Management policy to use for the set.
      • getPodMetadata

        @Stability(Stable)
        @NotNull
        public org.cdk8s.ApiObjectMetadataDefinition getPodMetadata()
        Provides read/write access to the underlying pod metadata of the resource.
        Specified by:
        getPodMetadata in interface IPodTemplate
      • getReplicas

        @Stability(Stable)
        @NotNull
        public Number getReplicas()
        Number of desired pods.
      • getVolumes

        @Stability(Stable)
        @NotNull
        public List<Volume> getVolumes()
        The volumes associated with this pod.

        Use addVolume to add volumes.

        Specified by:
        getVolumes in interface IPodSpec
      • getRestartPolicy

        @Stability(Stable)
        @Nullable
        public RestartPolicy getRestartPolicy()
        Restart policy for all containers within the pod.
        Specified by:
        getRestartPolicy in interface IPodSpec