Class Deployment

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

    @Generated(value="jsii-pacmak/1.55.1 (build 07d2d90)",
               date="2022-04-02T02:38:57.525Z")
    @Stability(Stable)
    public class Deployment
    extends Resource
    implements IPodTemplate
    A Deployment provides declarative updates for Pods and ReplicaSets.

    You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.

    Note: Do not manage ReplicaSets owned by a Deployment. Consider opening an issue in the main Kubernetes repository if your use case is not covered below.

    Use Case

    The following are typical use cases for Deployments:

    • Create a Deployment to rollout a ReplicaSet. The ReplicaSet creates Pods in the background. Check the status of the rollout to see if it succeeds or not.
    • Declare the new state of the Pods by updating the PodTemplateSpec of the Deployment. A new ReplicaSet is created and the Deployment manages moving the Pods from the old ReplicaSet to the new one at a controlled rate. Each new ReplicaSet updates the revision of the Deployment.
    • Rollback to an earlier Deployment revision if the current state of the Deployment is not stable. Each rollback updates the revision of the Deployment.
    • Scale up the Deployment to facilitate more load.
    • Pause the Deployment to apply multiple fixes to its PodTemplateSpec and then resume it to start a new rollout.
    • Use the status of the Deployment as an indicator that a rollout has stuck.
    • Clean up older ReplicaSets that you don't need anymore.
    • Constructor Detail

      • Deployment

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

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

        @Stability(Stable)
        public Deployment​(@NotNull
                          software.constructs.Construct scope,
                          @NotNull
                          String id,
                          @Nullable
                          DeploymentProps props)
        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        props -
      • Deployment

        @Stability(Stable)
        public Deployment​(@NotNull
                          software.constructs.Construct scope,
                          @NotNull
                          String id)
        Parameters:
        scope - This parameter is required.
        id - 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.
      • exposeViaIngress

        @Stability(Stable)
        @NotNull
        public IngressV1Beta1 exposeViaIngress​(@NotNull
                                               String path,
                                               @Nullable
                                               ExposeDeploymentViaIngressOptions options)
        Expose a deployment via an ingress.

        This will first expose the deployment with a service, and then expose the service via an ingress.

        Parameters:
        path - The ingress path to register under. This parameter is required.
        options - Additional options.
      • exposeViaIngress

        @Stability(Stable)
        @NotNull
        public IngressV1Beta1 exposeViaIngress​(@NotNull
                                               String path)
        Expose a deployment via an ingress.

        This will first expose the deployment with a service, and then expose the service via an ingress.

        Parameters:
        path - The ingress path to register under. This parameter is required.
      • exposeViaService

        @Stability(Stable)
        @NotNull
        public Service exposeViaService​(@Nullable
                                        ExposeDeploymentViaServiceOptions options)
        Expose a deployment via a service.

        This is equivalent to running kubectl expose deployment <deployment-name>.

        Parameters:
        options - Options to determine details of the service and port exposed.
      • exposeViaService

        @Stability(Stable)
        @NotNull
        public Service exposeViaService()
        Expose a deployment via a service.

        This is equivalent to running kubectl expose deployment <deployment-name>.

      • 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 deployment will match against in order to select pods.

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

      • 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