Skip to content

cdk8s-plus-17

Classes

Name Description
ConfigMap ConfigMap holds configuration data for pods to consume.
Container A single application container that you want to run within a pod.
Deployment A Deployment provides declarative updates for Pods and ReplicaSets.
EnvValue Utility class for creating reading env values from various sources.
IngressV1Beta1 Ingress is a collection of rules that allow inbound connections to reach the endpoints defined by a backend.
IngressV1Beta1Backend The backend for an ingress path.
Job A Job creates one or more Pods and ensures that a specified number of them successfully terminate.
Pod Pod is a collection of containers that can run on a host.
PodSpec Provides read/write capabilities ontop of a PodSpecProps.
PodTemplate Provides read/write capabilities ontop of a PodTemplateProps.
Probe Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.
Resource Base class for all Kubernetes objects in stdk8s.
Secret Kubernetes Secrets let you store and manage sensitive information, such as passwords, OAuth tokens, and ssh keys.
Service An abstract way to expose an application running on a set of Pods as a network service.
ServiceAccount A service account provides an identity for processes that run in a Pod.
Volume Volume represents a named volume in a pod that may be accessed by any container in the pod.

Structs

Name Description
AddDirectoryOptions Options for configmap.addDirectory().
CommandProbeOptions Options for Probe.fromCommand().
ConfigMapProps Properties for initialization of ConfigMap.
ConfigMapVolumeOptions Options for the ConfigMap-based volume.
ContainerProps Properties for creating a container.
DeploymentProps Properties for initialization of Deployment.
EmptyDirVolumeOptions Options for volumes populated with an empty directory.
EnvValueFromConfigMapOptions Options to specify an envionment variable value from a ConfigMap key.
EnvValueFromProcessOptions Options to specify an environment variable value from the process environment.
EnvValueFromSecretOptions Options to specify an environment variable value from a Secret.
ExposeOptions Options for exposing a deployment via a service.
HttpGetProbeOptions Options for Probe.fromHttpGet().
IngressV1Beta1Props Properties for Ingress.
IngressV1Beta1Rule Represents the rules mapping the paths under a specified host to the related backend services.
JobProps Properties for initialization of Job.
MountOptions Options for mounts.
PathMapping Maps a string key to a path within a volume.
PodProps Properties for initialization of Pod.
PodSpecProps Properties of a PodSpec.
PodTemplateProps Properties of a PodTemplate.
ProbeOptions Probe options.
ResourceProps Initialization properties for resources.
SecretProps No description
SecretValue Represents a specific value in JSON secret.
ServiceAccountProps Properties for initialization of ServiceAccount.
ServiceIngressV1BetaBackendOptions Options for setting up backends for ingress rules.
ServicePort Definition of a service port.
ServicePortOptions No description
ServiceProps Properties for initialization of Service.
VolumeMount Mount a volume from the pod to the container.

Interfaces

Name Description
IConfigMap Represents a config map.
IPodSpec Represents a resource that can be configured with a kuberenets pod spec. (e.g Deployment, Job, Pod, …).
IPodTemplate Represents a resource that can be configured with a kuberenets pod template. (e.g Deployment, Job, …).
IResource Represents a resource.
ISecret No description
IServiceAccount No description

Enums

Name Description
EmptyDirMedium The medium on which to store the volume.
ImagePullPolicy No description
MountPropagation No description
Protocol No description
RestartPolicy Restart policy for all containers within the pod.
ServiceType For some parts of your application (for example, frontends) you may want to expose a Service onto an external IP address, that’s outside of your cluster.

class ConfigMap ๐Ÿ”น

ConfigMap holds configuration data for pods to consume.

Implements: IConstruct, IResource, IConfigMap, IResource Extends: Resource

Initializer

new ConfigMap(scope: Construct, id: string, props?: ConfigMapProps)
  • scope (Construct) No description
  • id (string) No description
  • props (ConfigMapProps) No description
  • metadata (ApiObjectMetadata) Metadata that all persisted resources must have, which includes all objects users must create. Optional
  • binaryData (Map) BinaryData contains the binary data. Optional
  • data (Map) Data contains the configuration data. Optional

Properties

Name Type Description
apiObject๐Ÿ”น ApiObject The underlying cdk8s API object.
binaryData๐Ÿ”น Map The binary data associated with this config map.
data๐Ÿ”น Map The data associated with this config map.

Methods

addBinaryData(key, value)๐Ÿ”น

Adds a binary data entry to the config map.

BinaryData can contain byte sequences that are not in the UTF-8 range.

addBinaryData(key: string, value: string): void
  • key (string) The key.
  • value (string) The value.

addData(key, value)๐Ÿ”น

Adds a data entry to the config map.

addData(key: string, value: string): void
  • key (string) The key.
  • value (string) The value.

addDirectory(localDir, options?)๐Ÿ”น

Adds a directory to the ConfigMap.

addDirectory(localDir: string, options?: AddDirectoryOptions): void
  • localDir (string) A path to a local directory.
  • options (AddDirectoryOptions) Options.
  • exclude (Array) Glob patterns to exclude when adding files. Default: include all files
  • keyPrefix (string) A prefix to add to all keys in the config map. Default: “”

addFile(localFile, key?)๐Ÿ”น

Adds a file to the ConfigMap.

addFile(localFile: string, key?: string): void
  • localFile (string) The path to the local file.
  • key (string) The ConfigMap key (default to the file name).

static fromConfigMapName(name)๐Ÿ”น

Represents a ConfigMap created elsewhere.

static fromConfigMapName(name: string): IConfigMap
  • name (string) The name of the config map to import.

Returns: * IConfigMap

class Container ๐Ÿ”น

A single application container that you want to run within a pod.

Initializer

new Container(props: ContainerProps)
  • props (ContainerProps) No description
  • image (string) Docker image name.
  • args (Array) Arguments to the entrypoint. The docker image’s CMD is used if command is not provided. Default: []
  • command (Array) Entrypoint array. Default: The docker image’s ENTRYPOINT.
  • env (MapEnvValue>) List of environment variables to set in the container. Default: No environment variables.
  • imagePullPolicy (ImagePullPolicy) Image pull policy for this container. Default: ImagePullPolicy.ALWAYS
  • liveness (Probe) Periodic probe of container liveness. Default: no liveness probe is defined
  • name (string) Name of the container specified as a DNS_LABEL. Default: ‘main’
  • port (number) Number of port to expose on the pod’s IP address. Default: No port is exposed.
  • readiness (Probe) Determines when the container is ready to serve traffic. Default: no readiness probe is defined
  • startup (Probe) StartupProbe indicates that the Pod has successfully initialized. Default: no startup probe is defined.
  • volumeMounts (Array<VolumeMount>) Pod volumes to mount into the container’s filesystem. Optional
  • workingDir (string) Container’s working directory. Default: The container runtime’s default.

Properties

Name Type Description
env๐Ÿ”น MapEnvValue> The environment variables for this container.
image๐Ÿ”น string The container image.
imagePullPolicy๐Ÿ”น ImagePullPolicy Image pull policy for this container.
mounts๐Ÿ”น Array<VolumeMount> Volume mounts configured for this container.
name๐Ÿ”น string The name of the container.
args?๐Ÿ”น Array Arguments to the entrypoint.
Optional
command?๐Ÿ”น Array Entrypoint array (the command to execute when the container starts).
Optional
port?๐Ÿ”น number The port this container exposes.
Optional
workingDir?๐Ÿ”น string The working directory inside the container.
Optional

Methods

addEnv(name, value)๐Ÿ”น

Add an environment value to the container.

The variable value can come from various dynamic sources such a secrets of config maps.

addEnv(name: string, value: EnvValue): void
  • name (string) - The variable name.
  • value (EnvValue) - The variable value.

mount(path, volume, options?)๐Ÿ”น

Mount a volume to a specific path so that it is accessible by the container.

Every pod that is configured to use this container will autmoatically have access to the volume.

mount(path: string, volume: Volume, options?: MountOptions): void
  • path (string) - The desired path in the container.
  • volume (Volume) - The volume to mount.
  • options (MountOptions) No description
  • propagation (MountPropagation) Determines how mounts are propagated from the host to container and the other way around. Default: MountPropagation.NONE
  • readOnly (boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Default: false
  • subPath (string) Path within the volume from which the container’s volume should be mounted.). Default: “” the volume’s root
  • subPathExpr (string) Expanded path within the volume from which the container’s volume should be mounted. Default: “” volume’s root.

class Deployment ๐Ÿ”น

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.

Implements: IConstruct, IResource, IPodTemplate, IPodSpec Extends: Resource

Initializer

new Deployment(scope: Construct, id: string, props?: DeploymentProps)
  • scope (Construct) No description
  • id (string) No description
  • props (DeploymentProps) No description
  • metadata (ApiObjectMetadata) Metadata that all persisted resources must have, which includes all objects users must create. Optional
  • containers (Array<ContainerProps>) List of containers belonging to the pod. Default: No containers. Note that a pod spec must include at least one container.
  • restartPolicy (RestartPolicy) Restart policy for all containers within the pod. Default: RestartPolicy.ALWAYS
  • serviceAccount (IServiceAccount) A service account provides an identity for processes that run in a Pod. Default: No service account.
  • volumes (Array<Volume>) List of volumes that can be mounted by containers belonging to the pod. Default: No volumes.
  • podMetadata (ApiObjectMetadata) The pod metadata. Optional
  • defaultSelector (boolean) Automatically allocates a pod selector for this deployment. Default: true
  • replicas (number) Number of desired pods. Default: 1

Properties

Name Type Description
apiObject๐Ÿ”น ApiObject The underlying cdk8s API object.
containers๐Ÿ”น Array<Container> The containers belonging to the pod.
labelSelector๐Ÿ”น Map The labels this deployment will match against in order to select pods.
podMetadata๐Ÿ”น ApiObjectMetadataDefinition Provides read/write access to the underlying pod metadata of the resource.
replicas๐Ÿ”น number Number of desired pods.
volumes๐Ÿ”น Array<Volume> The volumes associated with this pod.
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Optional
serviceAccount?๐Ÿ”น IServiceAccount The service account used to run this pod.
Optional

Methods

addContainer(container)๐Ÿ”น

Add a container to the pod.

addContainer(container: ContainerProps): Container
  • container (ContainerProps) No description
  • image (string) Docker image name.
  • args (Array) Arguments to the entrypoint. The docker image’s CMD is used if command is not provided. Default: []
  • command (Array) Entrypoint array. Default: The docker image’s ENTRYPOINT.
  • env (MapEnvValue>) List of environment variables to set in the container. Default: No environment variables.
  • imagePullPolicy (ImagePullPolicy) Image pull policy for this container. Default: ImagePullPolicy.ALWAYS
  • liveness (Probe) Periodic probe of container liveness. Default: no liveness probe is defined
  • name (string) Name of the container specified as a DNS_LABEL. Default: ‘main’
  • port (number) Number of port to expose on the pod’s IP address. Default: No port is exposed.
  • readiness (Probe) Determines when the container is ready to serve traffic. Default: no readiness probe is defined
  • startup (Probe) StartupProbe indicates that the Pod has successfully initialized. Default: no startup probe is defined.
  • volumeMounts (Array<VolumeMount>) Pod volumes to mount into the container’s filesystem. Optional
  • workingDir (string) Container’s working directory. Default: The container runtime’s default.

Returns: * Container

addVolume(volume)๐Ÿ”น

Add a volume to the pod.

addVolume(volume: Volume): void
  • volume (Volume) No description

expose(port, options?)๐Ÿ”น

Expose a deployment via a service.

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

expose(port: number, options?: ExposeOptions): Service
  • port (number) The port number the service will bind to.
  • options (ExposeOptions) Options to determine details of the service and port exposed.
  • name (string) The name of the service to expose. Default: undefined Uses the system generated name.
  • protocol (Protocol) The IP protocol for this port. Default: Protocol.TCP
  • serviceType (ServiceType) The type of the exposed service. Default: ClusterIP.
  • targetPort (number) The port number the service will redirect to. Default: The port of the first container in the deployment (ie. containers[0].port)

Returns: * Service

selectByLabel(key, value)๐Ÿ”น

Configure a label selector to this deployment.

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

selectByLabel(key: string, value: string): void
  • key (string) - The label key.
  • value (string) - The label value.

class EnvValue ๐Ÿ”น

Utility class for creating reading env values from various sources.

Properties

Name Type Description
value?๐Ÿ”น any Optional
valueFrom?๐Ÿ”น any Optional

Methods

static fromConfigMap(configMap, key, options?)๐Ÿ”น

Create a value by reading a specific key inside a config map.

static fromConfigMap(configMap: IConfigMap, key: string, options?: EnvValueFromConfigMapOptions): EnvValue
  • configMap (IConfigMap) - The config map.
  • key (string) - The key to extract the value from.
  • options (EnvValueFromConfigMapOptions) - Additional options.
  • optional (boolean) Specify whether the ConfigMap or its key must be defined. Default: false

Returns: * EnvValue

static fromProcess(key, options?)๐Ÿ”น

Create a value from a key in the current process environment.

static fromProcess(key: string, options?: EnvValueFromProcessOptions): EnvValue
  • key (string) - The key to read.
  • options (EnvValueFromProcessOptions) - Additional options.
  • required (boolean) Specify whether the key must exist in the environment. Default: false

Returns: * EnvValue

static fromSecretValue(secretValue, options?)๐Ÿ”น

Defines an environment value from a secret JSON value.

static fromSecretValue(secretValue: SecretValue, options?: EnvValueFromSecretOptions): EnvValue
  • secretValue (SecretValue) The secret value (secrent + key).
  • options (EnvValueFromSecretOptions) Additional options.
  • optional (boolean) Specify whether the Secret or its key must be defined. Default: false

Returns: * EnvValue

static fromValue(value)๐Ÿ”น

Create a value from the given argument.

static fromValue(value: string): EnvValue
  • value (string) - The value.

Returns: * EnvValue

class IngressV1Beta1 ๐Ÿ”น

Ingress is a collection of rules that allow inbound connections to reach the endpoints defined by a backend.

An Ingress can be configured to give services externally-reachable urls, load balance traffic, terminate SSL, offer name based virtual hosting etc.

Implements: IConstruct, IResource Extends: Resource

Initializer

new IngressV1Beta1(scope: Construct, id: string, props?: IngressV1Beta1Props)
  • scope (Construct) No description
  • id (string) No description
  • props (IngressV1Beta1Props) No description
  • metadata (ApiObjectMetadata) Metadata that all persisted resources must have, which includes all objects users must create. Optional
  • defaultBackend (IngressV1Beta1Backend) The default backend services requests that do not match any rule. Optional
  • rules (Array<IngressV1Beta1Rule>) Routing rules for this ingress. Optional

Properties

Name Type Description
apiObject๐Ÿ”น ApiObject The underlying cdk8s API object.

Methods

addDefaultBackend(backend)๐Ÿ”น

Defines the default backend for this ingress.

A default backend capable of servicing requests that don’t match any rule.

addDefaultBackend(backend: IngressV1Beta1Backend): void

addHostDefaultBackend(host, backend)๐Ÿ”น

Specify a default backend for a specific host name.

This backend will be used as a catch-all for requests targeted to this host name (the Host header matches this value).

addHostDefaultBackend(host: string, backend: IngressV1Beta1Backend): void

addHostRule(host, path, backend)๐Ÿ”น

Adds an ingress rule applied to requests to a specific host and a specific HTTP path (the Host header matches this value).

addHostRule(host: string, path: string, backend: IngressV1Beta1Backend): void
  • host (string) The host name.
  • path (string) The HTTP path.
  • backend (IngressV1Beta1Backend) The backend to route requests to.

addRule(path, backend)๐Ÿ”น

Adds an ingress rule applied to requests sent to a specific HTTP path.

addRule(path: string, backend: IngressV1Beta1Backend): void

addRules(…rules)๐Ÿ”น

Adds rules to this ingress.

addRules(...rules: IngressV1Beta1Rule[]): void
  • rules (IngressV1Beta1Rule) The rules to add.
  • backend (IngressV1Beta1Backend) Backend defines the referenced service endpoint to which the traffic will be forwarded to.
  • host (string) Host is the fully qualified domain name of a network host, as defined by RFC 3986. Default: If the host is unspecified, the Ingress routes all traffic based on the specified IngressRuleValue.
  • path (string) Path is an extended POSIX regex as defined by IEEE Std 1003.1, (i.e this follows the egrep/unix syntax, not the perl syntax) matched against the path of an incoming request. Currently it can contain characters disallowed from the conventional “path” part of a URL as defined by RFC 3986. Paths must begin with a ‘/’. Default: If unspecified, the path defaults to a catch all sending traffic to the backend.

protected onValidate()๐Ÿ”น

(deprecated) Validate the current construct.

This method can be implemented by derived constructs in order to perform validation logic. It is called on all constructs before synthesis.

protected onValidate(): Array<string>

Returns: * Array

class IngressV1Beta1Backend ๐Ÿ”น

The backend for an ingress path.

Methods

static fromService(service, options?)๐Ÿ”น

A Kubernetes Service to use as the backend for this path.

static fromService(service: Service, options?: ServiceIngressV1BetaBackendOptions): IngressV1Beta1Backend
  • service (Service) The service object.
  • options (ServiceIngressV1BetaBackendOptions) No description
  • port (number) The port to use to access the service. Default: if the service exposes a single port, this port will be used.

Returns: * IngressV1Beta1Backend

class Job ๐Ÿ”น

A Job creates one or more Pods and ensures that a specified number of them successfully terminate.

As pods successfully complete, the Job tracks the successful completions. When a specified number of successful completions is reached, the task (ie, Job) is complete. Deleting a Job will clean up the Pods it created. A simple case is to create one Job object in order to reliably run one Pod to completion. The Job object will start a new Pod if the first Pod fails or is deleted (for example due to a node hardware failure or a node reboot). You can also use a Job to run multiple Pods in parallel.

Implements: IConstruct, IResource, IPodTemplate, IPodSpec Extends: Resource

Initializer

new Job(scope: Construct, id: string, props?: JobProps)
  • scope (Construct) No description
  • id (string) No description
  • props (JobProps) No description
  • metadata (ApiObjectMetadata) Metadata that all persisted resources must have, which includes all objects users must create. Optional
  • containers (Array<ContainerProps>) List of containers belonging to the pod. Default: No containers. Note that a pod spec must include at least one container.
  • restartPolicy (RestartPolicy) Restart policy for all containers within the pod. Default: RestartPolicy.ALWAYS
  • serviceAccount (IServiceAccount) A service account provides an identity for processes that run in a Pod. Default: No service account.
  • volumes (Array<Volume>) List of volumes that can be mounted by containers belonging to the pod. Default: No volumes.
  • podMetadata (ApiObjectMetadata) The pod metadata. Optional
  • activeDeadline (Duration) Specifies the duration the job may be active before the system tries to terminate it. Default: If unset, then there is no deadline.
  • backoffLimit (number) Specifies the number of retries before marking this job failed. Default: If not set, system defaults to 6.
  • ttlAfterFinished (Duration) Limits the lifetime of a Job that has finished execution (either Complete or Failed). Default: If this field is unset, the Job won’t be automatically deleted.

Properties

Name Type Description
apiObject๐Ÿ”น ApiObject The underlying cdk8s API object.
containers๐Ÿ”น Array<Container> The containers belonging to the pod.
podMetadata๐Ÿ”น ApiObjectMetadataDefinition Provides read/write access to the underlying pod metadata of the resource.
volumes๐Ÿ”น Array<Volume> The volumes associated with this pod.
activeDeadline?๐Ÿ”น Duration Duration before job is terminated.
Optional
backoffLimit?๐Ÿ”น number Number of retries before marking failed.
Optional
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Optional
serviceAccount?๐Ÿ”น IServiceAccount The service account used to run this pod.
Optional
ttlAfterFinished?๐Ÿ”น Duration TTL before the job is deleted after it is finished.
Optional

Methods

addContainer(container)๐Ÿ”น

Add a container to the pod.

addContainer(container: ContainerProps): Container
  • container (ContainerProps) No description
  • image (string) Docker image name.
  • args (Array) Arguments to the entrypoint. The docker image’s CMD is used if command is not provided. Default: []
  • command (Array) Entrypoint array. Default: The docker image’s ENTRYPOINT.
  • env (MapEnvValue>) List of environment variables to set in the container. Default: No environment variables.
  • imagePullPolicy (ImagePullPolicy) Image pull policy for this container. Default: ImagePullPolicy.ALWAYS
  • liveness (Probe) Periodic probe of container liveness. Default: no liveness probe is defined
  • name (string) Name of the container specified as a DNS_LABEL. Default: ‘main’
  • port (number) Number of port to expose on the pod’s IP address. Default: No port is exposed.
  • readiness (Probe) Determines when the container is ready to serve traffic. Default: no readiness probe is defined
  • startup (Probe) StartupProbe indicates that the Pod has successfully initialized. Default: no startup probe is defined.
  • volumeMounts (Array<VolumeMount>) Pod volumes to mount into the container’s filesystem. Optional
  • workingDir (string) Container’s working directory. Default: The container runtime’s default.

Returns: * Container

addVolume(volume)๐Ÿ”น

Add a volume to the pod.

addVolume(volume: Volume): void
  • volume (Volume) No description

class Pod ๐Ÿ”น

Pod is a collection of containers that can run on a host.

This resource is created by clients and scheduled onto hosts.

Implements: IConstruct, IResource, IPodSpec Extends: Resource

Initializer

new Pod(scope: Construct, id: string, props?: PodProps)
  • scope (Construct) No description
  • id (string) No description
  • props (PodProps) No description
  • metadata (ApiObjectMetadata) Metadata that all persisted resources must have, which includes all objects users must create. Optional
  • containers (Array<ContainerProps>) List of containers belonging to the pod. Default: No containers. Note that a pod spec must include at least one container.
  • restartPolicy (RestartPolicy) Restart policy for all containers within the pod. Default: RestartPolicy.ALWAYS
  • serviceAccount (IServiceAccount) A service account provides an identity for processes that run in a Pod. Default: No service account.
  • volumes (Array<Volume>) List of volumes that can be mounted by containers belonging to the pod. Default: No volumes.

Properties

Name Type Description
apiObject๐Ÿ”น ApiObject The underlying cdk8s API object.
containers๐Ÿ”น Array<Container> The containers belonging to the pod.
volumes๐Ÿ”น Array<Volume> The volumes associated with this pod.
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Optional
serviceAccount?๐Ÿ”น IServiceAccount The service account used to run this pod.
Optional

Methods

addContainer(container)๐Ÿ”น

Add a container to the pod.

addContainer(container: ContainerProps): Container
  • container (ContainerProps) No description
  • image (string) Docker image name.
  • args (Array) Arguments to the entrypoint. The docker image’s CMD is used if command is not provided. Default: []
  • command (Array) Entrypoint array. Default: The docker image’s ENTRYPOINT.
  • env (MapEnvValue>) List of environment variables to set in the container. Default: No environment variables.
  • imagePullPolicy (ImagePullPolicy) Image pull policy for this container. Default: ImagePullPolicy.ALWAYS
  • liveness (Probe) Periodic probe of container liveness. Default: no liveness probe is defined
  • name (string) Name of the container specified as a DNS_LABEL. Default: ‘main’
  • port (number) Number of port to expose on the pod’s IP address. Default: No port is exposed.
  • readiness (Probe) Determines when the container is ready to serve traffic. Default: no readiness probe is defined
  • startup (Probe) StartupProbe indicates that the Pod has successfully initialized. Default: no startup probe is defined.
  • volumeMounts (Array<VolumeMount>) Pod volumes to mount into the container’s filesystem. Optional
  • workingDir (string) Container’s working directory. Default: The container runtime’s default.

Returns: * Container

addVolume(volume)๐Ÿ”น

Add a volume to the pod.

addVolume(volume: Volume): void
  • volume (Volume) No description

class PodSpec ๐Ÿ”น

Provides read/write capabilities ontop of a PodSpecProps.

Implements: IPodSpec

Initializer

new PodSpec(props?: PodSpecProps)
  • props (PodSpecProps) No description
  • containers (Array<ContainerProps>) List of containers belonging to the pod. Default: No containers. Note that a pod spec must include at least one container.
  • restartPolicy (RestartPolicy) Restart policy for all containers within the pod. Default: RestartPolicy.ALWAYS
  • serviceAccount (IServiceAccount) A service account provides an identity for processes that run in a Pod. Default: No service account.
  • volumes (Array<Volume>) List of volumes that can be mounted by containers belonging to the pod. Default: No volumes.

Properties

Name Type Description
containers๐Ÿ”น Array<Container> The containers belonging to the pod.
volumes๐Ÿ”น Array<Volume> The volumes associated with this pod.
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Optional
serviceAccount?๐Ÿ”น IServiceAccount The service account used to run this pod.
Optional

Methods

addContainer(container)๐Ÿ”น

Add a container to the pod.

addContainer(container: ContainerProps): Container
  • container (ContainerProps) No description
  • image (string) Docker image name.
  • args (Array) Arguments to the entrypoint. The docker image’s CMD is used if command is not provided. Default: []
  • command (Array) Entrypoint array. Default: The docker image’s ENTRYPOINT.
  • env (MapEnvValue>) List of environment variables to set in the container. Default: No environment variables.
  • imagePullPolicy (ImagePullPolicy) Image pull policy for this container. Default: ImagePullPolicy.ALWAYS
  • liveness (Probe) Periodic probe of container liveness. Default: no liveness probe is defined
  • name (string) Name of the container specified as a DNS_LABEL. Default: ‘main’
  • port (number) Number of port to expose on the pod’s IP address. Default: No port is exposed.
  • readiness (Probe) Determines when the container is ready to serve traffic. Default: no readiness probe is defined
  • startup (Probe) StartupProbe indicates that the Pod has successfully initialized. Default: no startup probe is defined.
  • volumeMounts (Array<VolumeMount>) Pod volumes to mount into the container’s filesystem. Optional
  • workingDir (string) Container’s working directory. Default: The container runtime’s default.

Returns: * Container

addVolume(volume)๐Ÿ”น

Add a volume to the pod.

addVolume(volume: Volume): void
  • volume (Volume) No description

class PodTemplate ๐Ÿ”น

Provides read/write capabilities ontop of a PodTemplateProps.

Implements: IPodSpec, IPodTemplate, IPodSpec Extends: PodSpec

Initializer

new PodTemplate(props?: PodTemplateProps)
  • props (PodTemplateProps) No description
  • containers (Array<ContainerProps>) List of containers belonging to the pod. Default: No containers. Note that a pod spec must include at least one container.
  • restartPolicy (RestartPolicy) Restart policy for all containers within the pod. Default: RestartPolicy.ALWAYS
  • serviceAccount (IServiceAccount) A service account provides an identity for processes that run in a Pod. Default: No service account.
  • volumes (Array<Volume>) List of volumes that can be mounted by containers belonging to the pod. Default: No volumes.
  • podMetadata (ApiObjectMetadata) The pod metadata. Optional

Properties

Name Type Description
podMetadata๐Ÿ”น ApiObjectMetadataDefinition Provides read/write access to the underlying pod metadata of the resource.

class Probe ๐Ÿ”น

Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.

Initializer

new Probe()

Methods

static fromCommand(command, options?)๐Ÿ”น

Defines a probe based on a command which is executed within the container.

static fromCommand(command: Array<string>, options?: CommandProbeOptions): Probe
  • command (Array) The command to execute.
  • options (CommandProbeOptions) Options.
  • failureThreshold (number) Minimum consecutive failures for the probe to be considered failed after having succeeded. Default: 3
  • initialDelaySeconds (Duration) Number of seconds after the container has started before liveness probes are initiated. Default: immediate
  • periodSeconds (Duration) How often (in seconds) to perform the probe. Default: Duration.seconds(10) Minimum value is 1.
  • successThreshold (number) Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Default: 1 Must be 1 for liveness and startup. Minimum value is 1.
  • timeoutSeconds (Duration) Number of seconds after which the probe times out. Default: Duration.seconds(1)

Returns: * Probe

static fromHttpGet(path, options?)๐Ÿ”น

Defines a probe based on an HTTP GET request to the IP address of the container.

static fromHttpGet(path: string, options?: HttpGetProbeOptions): Probe
  • path (string) The URL path to hit.
  • options (HttpGetProbeOptions) Options.
  • failureThreshold (number) Minimum consecutive failures for the probe to be considered failed after having succeeded. Default: 3
  • initialDelaySeconds (Duration) Number of seconds after the container has started before liveness probes are initiated. Default: immediate
  • periodSeconds (Duration) How often (in seconds) to perform the probe. Default: Duration.seconds(10) Minimum value is 1.
  • successThreshold (number) Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Default: 1 Must be 1 for liveness and startup. Minimum value is 1.
  • timeoutSeconds (Duration) Number of seconds after which the probe times out. Default: Duration.seconds(1)
  • port (number) The TCP port to use when sending the GET request. Default: defaults to container.port.

Returns: * Probe

class Resource ๐Ÿ”น

Base class for all Kubernetes objects in stdk8s.

Represents a single resource.

Implements: IConstruct, IResource Extends: Construct Implemented by: ConfigMap, Deployment, IngressV1Beta1, Job, Pod, Secret, Service, ServiceAccount

Initializer

new Resource(scope: Construct, id: string, _: ResourceProps)
  • scope (Construct) No description
  • id (string) No description
  • _ (ResourceProps) No description
  • metadata (ApiObjectMetadata) Metadata that all persisted resources must have, which includes all objects users must create. Optional

Properties

Name Type Description
apiObject๐Ÿ”น ApiObject The underlying cdk8s API object.
metadata๐Ÿ”น ApiObjectMetadataDefinition
name๐Ÿ”น string The name of this API object.

class Secret ๐Ÿ”น

Kubernetes Secrets let you store and manage sensitive information, such as passwords, OAuth tokens, and ssh keys.

Storing confidential information in a Secret is safer and more flexible than putting it verbatim in a Pod definition or in a container image.

Implements: IConstruct, IResource, ISecret, IResource Extends: Resource

Initializer

new Secret(scope: Construct, id: string, props?: SecretProps)
  • scope (Construct) No description
  • id (string) No description
  • props (SecretProps) No description
  • metadata (ApiObjectMetadata) Metadata that all persisted resources must have, which includes all objects users must create. Optional
  • stringData (Map) stringData allows specifying non-binary secret data in string form. Optional

Properties

Name Type Description
apiObject๐Ÿ”น ApiObject The underlying cdk8s API object.

Methods

addStringData(key, value)๐Ÿ”น

Adds a string data field to the secert.

addStringData(key: string, value: string): void
  • key (string) Key.
  • value (string) Value.

getStringData(key)๐Ÿ”น

Gets a string data by key or undefined.

getStringData(key: string): string
  • key (string) Key.

Returns: * string

static fromSecretName(name)๐Ÿ”น

Imports a secret from the cluster as a reference.

static fromSecretName(name: string): ISecret
  • name (string) The name of the secret to reference.

Returns: * ISecret

class Service ๐Ÿ”น

An abstract way to expose an application running on a set of Pods as a network service.

With Kubernetes you don’t need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.

For example, consider a stateless image-processing backend which is running with 3 replicas. Those replicas are fungibleโ€”frontends do not care which backend they use. While the actual Pods that compose the backend set may change, the frontend clients should not need to be aware of that, nor should they need to keep track of the set of backends themselves. The Service abstraction enables this decoupling.

If you’re able to use Kubernetes APIs for service discovery in your application, you can query the API server for Endpoints, that get updated whenever the set of Pods in a Service changes. For non-native applications, Kubernetes offers ways to place a network port or load balancer in between your application and the backend Pods.

Implements: IConstruct, IResource Extends: Resource

Initializer

new Service(scope: Construct, id: string, props?: ServiceProps)
  • scope (Construct) No description
  • id (string) No description
  • props (ServiceProps) No description
  • metadata (ApiObjectMetadata) Metadata that all persisted resources must have, which includes all objects users must create. Optional
  • clusterIP (string) The IP address of the service and is usually assigned randomly by the master. Default: Automatically assigned.
  • externalIPs (Array) A list of IP addresses for which nodes in the cluster will also accept traffic for this service. Default: No external IPs.
  • ports (Array<ServicePort>) The port exposed by this service. Optional
  • type (ServiceType) Determines how the Service is exposed. Default: ServiceType.ClusterIP

Properties

Name Type Description
apiObject๐Ÿ”น ApiObject The underlying cdk8s API object.
ports๐Ÿ”น Array<ServicePort> Ports for this service.
selector๐Ÿ”น Map Returns the labels which are used to select pods for this service.
type๐Ÿ”น ServiceType Determines how the Service is exposed.
clusterIP?๐Ÿ”น string The IP address of the service and is usually assigned randomly by the master.
Optional

Methods

addDeployment(deployment, port, options?)๐Ÿ”น

Associate a deployment to this service.

If not targetPort is specific in the portOptions, then requests will be routed to the port exposed by the first container in the deployment’s pods. The deployment’s labelSelector will be used to select pods.

addDeployment(deployment: Deployment, port: number, options?: ServicePortOptions): void
  • deployment (Deployment) The deployment to expose.
  • port (number) The external port.
  • options (ServicePortOptions) Optional settings for the port.
  • name (string) The name of this port within the service. Optional
  • nodePort (number) The port on each node on which this service is exposed when type=NodePort or LoadBalancer. Default: to auto-allocate a port if the ServiceType of this Service requires one.
  • protocol (Protocol) The IP protocol for this port. Default: Protocol.TCP
  • targetPort (number) The port number the service will redirect to. Default: The value of port will be used.

addSelector(label, value)๐Ÿ”น

Services defined using this spec will select pods according the provided label.

addSelector(label: string, value: string): void
  • label (string) The label key.
  • value (string) The label value.

serve(port, options?)๐Ÿ”น

Configure a port the service will bind to.

This method can be called multiple times.

serve(port: number, options?: ServicePortOptions): void
  • port (number) The port definition.
  • options (ServicePortOptions) No description
  • name (string) The name of this port within the service. Optional
  • nodePort (number) The port on each node on which this service is exposed when type=NodePort or LoadBalancer. Default: to auto-allocate a port if the ServiceType of this Service requires one.
  • protocol (Protocol) The IP protocol for this port. Default: Protocol.TCP
  • targetPort (number) The port number the service will redirect to. Default: The value of port will be used.

class ServiceAccount ๐Ÿ”น

A service account provides an identity for processes that run in a Pod.

When you (a human) access the cluster (for example, using kubectl), you are authenticated by the apiserver as a particular User Account (currently this is usually admin, unless your cluster administrator has customized your cluster). Processes in containers inside pods can also contact the apiserver. When they do, they are authenticated as a particular Service Account (for example, default).

Implements: IConstruct, IResource, IServiceAccount, IResource Extends: Resource

Initializer

new ServiceAccount(scope: Construct, id: string, props?: ServiceAccountProps)
  • scope (Construct) No description
  • id (string) No description
  • props (ServiceAccountProps) No description
  • metadata (ApiObjectMetadata) Metadata that all persisted resources must have, which includes all objects users must create. Optional
  • secrets (Array<ISecret>) List of secrets allowed to be used by pods running using this ServiceAccount. Optional

Properties

Name Type Description
apiObject๐Ÿ”น ApiObject The underlying cdk8s API object.
secrets๐Ÿ”น Array<ISecret> List of secrets allowed to be used by pods running using this service account.

Methods

addSecret(secret)๐Ÿ”น

Allow a secret to be accessed by pods using this service account.

addSecret(secret: ISecret): void

static fromServiceAccountName(name)๐Ÿ”น

Imports a service account from the cluster as a reference.

static fromServiceAccountName(name: string): IServiceAccount
  • name (string) The name of the service account resource.

Returns: * IServiceAccount

class Volume ๐Ÿ”น

Volume represents a named volume in a pod that may be accessed by any container in the pod.

Docker also has a concept of volumes, though it is somewhat looser and less managed. In Docker, a volume is simply a directory on disk or in another Container. Lifetimes are not managed and until very recently there were only local-disk-backed volumes. Docker now provides volume drivers, but the functionality is very limited for now (e.g. as of Docker 1.7 only one volume driver is allowed per Container and there is no way to pass parameters to volumes).

A Kubernetes volume, on the other hand, has an explicit lifetime - the same as the Pod that encloses it. Consequently, a volume outlives any Containers that run within the Pod, and data is preserved across Container restarts. Of course, when a Pod ceases to exist, the volume will cease to exist, too. Perhaps more importantly than this, Kubernetes supports many types of volumes, and a Pod can use any number of them simultaneously.

At its core, a volume is just a directory, possibly with some data in it, which is accessible to the Containers in a Pod. How that directory comes to be, the medium that backs it, and the contents of it are determined by the particular volume type used.

To use a volume, a Pod specifies what volumes to provide for the Pod (the .spec.volumes field) and where to mount those into Containers (the .spec.containers[*].volumeMounts field).

A process in a container sees a filesystem view composed from their Docker image and volumes. The Docker image is at the root of the filesystem hierarchy, and any volumes are mounted at the specified paths within the image. Volumes can not mount onto other volumes

Initializer

new Volume(name: string, config: any)
  • name (string) No description
  • config (any) No description

Properties

Name Type Description
name๐Ÿ”น string

Methods

static fromConfigMap(configMap, options?)๐Ÿ”น

Populate the volume from a ConfigMap.

The configMap resource provides a way to inject configuration data into Pods. The data stored in a ConfigMap object can be referenced in a volume of type configMap and then consumed by containerized applications running in a Pod.

When referencing a configMap object, you can simply provide its name in the volume to reference it. You can also customize the path to use for a specific entry in the ConfigMap.

static fromConfigMap(configMap: IConfigMap, options?: ConfigMapVolumeOptions): Volume
  • configMap (IConfigMap) The config map to use to populate the volume.
  • options (ConfigMapVolumeOptions) Options.
  • defaultMode (number) Mode bits to use on created files by default. Default: 0644. Directories within the path are not affected by this setting. This might be in conflict with other options that affect the file mode, like fsGroup, and the result can be other mode bits set.
  • items (MapPathMapping>) If unspecified, each key-value pair in the Data field of the referenced ConfigMap will be projected into the volume as a file whose name is the key and content is the value. Default: no mapping
  • name (string) The volume name. Default: auto-generated
  • optional (boolean) Specify whether the ConfigMap or its keys must be defined. Default: undocumented

Returns: * Volume

static fromEmptyDir(name, options?)๐Ÿ”น

An emptyDir volume is first created when a Pod is assigned to a Node, and exists as long as that Pod is running on that node.

As the name says, it is initially empty. Containers in the Pod can all read and write the same files in the emptyDir volume, though that volume can be mounted at the same or different paths in each Container. When a Pod is removed from a node for any reason, the data in the emptyDir is deleted forever.

static fromEmptyDir(name: string, options?: EmptyDirVolumeOptions): Volume
  • name (string) No description
  • options (EmptyDirVolumeOptions) - Additional options.
  • medium (EmptyDirMedium) By default, emptyDir volumes are stored on whatever medium is backing the node - that might be disk or SSD or network storage, depending on your environment. Default: EmptyDirMedium.DEFAULT
  • sizeLimit (Size) Total amount of local storage required for this EmptyDir volume. Default: limit is undefined

Returns: * Volume

struct AddDirectoryOptions ๐Ÿ”น

Options for configmap.addDirectory().

Name Type Description
exclude?๐Ÿ”น Array Glob patterns to exclude when adding files.
Default: include all files
keyPrefix?๐Ÿ”น string A prefix to add to all keys in the config map.
Default: “”

struct CommandProbeOptions ๐Ÿ”น

Options for Probe.fromCommand().

Name Type Description
failureThreshold?๐Ÿ”น number Minimum consecutive failures for the probe to be considered failed after having succeeded.
Default: 3
initialDelaySeconds?๐Ÿ”น Duration Number of seconds after the container has started before liveness probes are initiated.
Default: immediate
periodSeconds?๐Ÿ”น Duration How often (in seconds) to perform the probe.
Default: Duration.seconds(10) Minimum value is 1.
successThreshold?๐Ÿ”น number Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1.
Default: 1 Must be 1 for liveness and startup. Minimum value is 1.
timeoutSeconds?๐Ÿ”น Duration Number of seconds after which the probe times out.
Default: Duration.seconds(1)

struct ConfigMapProps ๐Ÿ”น

Properties for initialization of ConfigMap.

Name Type Description
binaryData?๐Ÿ”น Map BinaryData contains the binary data.
Optional
data?๐Ÿ”น Map Data contains the configuration data.
Optional
metadata?๐Ÿ”น ApiObjectMetadata Metadata that all persisted resources must have, which includes all objects users must create.
Optional

struct ConfigMapVolumeOptions ๐Ÿ”น

Options for the ConfigMap-based volume.

Name Type Description
defaultMode?๐Ÿ”น number Mode bits to use on created files by default.
Default: 0644. Directories within the path are not affected by this setting. This might be in conflict with other options that affect the file mode, like fsGroup, and the result can be other mode bits set.
items?๐Ÿ”น MapPathMapping> If unspecified, each key-value pair in the Data field of the referenced ConfigMap will be projected into the volume as a file whose name is the key and content is the value.
Default: no mapping
name?๐Ÿ”น string The volume name.
Default: auto-generated
optional?๐Ÿ”น boolean Specify whether the ConfigMap or its keys must be defined.
Default: undocumented

struct ContainerProps ๐Ÿ”น

Properties for creating a container.

Name Type Description
image๐Ÿ”น string Docker image name.
args?๐Ÿ”น Array Arguments to the entrypoint. The docker image’s CMD is used if command is not provided.
Default: []
command?๐Ÿ”น Array Entrypoint array.
Default: The docker image’s ENTRYPOINT.
env?๐Ÿ”น MapEnvValue> List of environment variables to set in the container.
Default: No environment variables.
imagePullPolicy?๐Ÿ”น ImagePullPolicy Image pull policy for this container.
Default: ImagePullPolicy.ALWAYS
liveness?๐Ÿ”น Probe Periodic probe of container liveness.
Default: no liveness probe is defined
name?๐Ÿ”น string Name of the container specified as a DNS_LABEL.
Default: ‘main’
port?๐Ÿ”น number Number of port to expose on the pod’s IP address.
Default: No port is exposed.
readiness?๐Ÿ”น Probe Determines when the container is ready to serve traffic.
Default: no readiness probe is defined
startup?๐Ÿ”น Probe StartupProbe indicates that the Pod has successfully initialized.
Default: no startup probe is defined.
volumeMounts?๐Ÿ”น Array<VolumeMount> Pod volumes to mount into the container’s filesystem.
Optional
workingDir?๐Ÿ”น string Container’s working directory.
Default: The container runtime’s default.

struct DeploymentProps ๐Ÿ”น

Properties for initialization of Deployment.

Name Type Description
containers?๐Ÿ”น Array<ContainerProps> List of containers belonging to the pod.
Default: No containers. Note that a pod spec must include at least one container.
defaultSelector?๐Ÿ”น boolean Automatically allocates a pod selector for this deployment.
Default: true
metadata?๐Ÿ”น ApiObjectMetadata Metadata that all persisted resources must have, which includes all objects users must create.
Optional
podMetadata?๐Ÿ”น ApiObjectMetadata The pod metadata.
Optional
replicas?๐Ÿ”น number Number of desired pods.
Default: 1
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Default: RestartPolicy.ALWAYS
serviceAccount?๐Ÿ”น IServiceAccount A service account provides an identity for processes that run in a Pod.
Default: No service account.
volumes?๐Ÿ”น Array<Volume> List of volumes that can be mounted by containers belonging to the pod.
Default: No volumes.

struct EmptyDirVolumeOptions ๐Ÿ”น

Options for volumes populated with an empty directory.

Name Type Description
medium?๐Ÿ”น EmptyDirMedium By default, emptyDir volumes are stored on whatever medium is backing the node - that might be disk or SSD or network storage, depending on your environment.
Default: EmptyDirMedium.DEFAULT
sizeLimit?๐Ÿ”น Size Total amount of local storage required for this EmptyDir volume.
Default: limit is undefined

struct EnvValueFromConfigMapOptions ๐Ÿ”น

Options to specify an envionment variable value from a ConfigMap key.

Name Type Description
optional?๐Ÿ”น boolean Specify whether the ConfigMap or its key must be defined.
Default: false

struct EnvValueFromProcessOptions ๐Ÿ”น

Options to specify an environment variable value from the process environment.

Name Type Description
required?๐Ÿ”น boolean Specify whether the key must exist in the environment.
Default: false

struct EnvValueFromSecretOptions ๐Ÿ”น

Options to specify an environment variable value from a Secret.

Name Type Description
optional?๐Ÿ”น boolean Specify whether the Secret or its key must be defined.
Default: false

struct ExposeOptions ๐Ÿ”น

Options for exposing a deployment via a service.

Name Type Description
name?๐Ÿ”น string The name of the service to expose.
Default: undefined Uses the system generated name.
protocol?๐Ÿ”น Protocol The IP protocol for this port.
Default: Protocol.TCP
serviceType?๐Ÿ”น ServiceType The type of the exposed service.
Default: ClusterIP.
targetPort?๐Ÿ”น number The port number the service will redirect to.
Default: The port of the first container in the deployment (ie. containers[0].port)

struct HttpGetProbeOptions ๐Ÿ”น

Options for Probe.fromHttpGet().

Name Type Description
failureThreshold?๐Ÿ”น number Minimum consecutive failures for the probe to be considered failed after having succeeded.
Default: 3
initialDelaySeconds?๐Ÿ”น Duration Number of seconds after the container has started before liveness probes are initiated.
Default: immediate
periodSeconds?๐Ÿ”น Duration How often (in seconds) to perform the probe.
Default: Duration.seconds(10) Minimum value is 1.
port?๐Ÿ”น number The TCP port to use when sending the GET request.
Default: defaults to container.port.
successThreshold?๐Ÿ”น number Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1.
Default: 1 Must be 1 for liveness and startup. Minimum value is 1.
timeoutSeconds?๐Ÿ”น Duration Number of seconds after which the probe times out.
Default: Duration.seconds(1)

interface IConfigMap ๐Ÿ”น

Implemented by: ConfigMap Obtainable from: ConfigMap.fromConfigMapName()

Represents a config map.

Properties

Name Type Description
name๐Ÿ”น string The Kubernetes name of this resource.

interface IPodSpec ๐Ÿ”น

Implemented by: Deployment, Job, Pod, PodSpec, PodTemplate

Represents a resource that can be configured with a kuberenets pod spec. (e.g Deployment, Job, Pod, …).

Use the PodSpec class as an implementation helper.

Properties

Name Type Description
containers๐Ÿ”น Array<Container> The containers belonging to the pod.
volumes๐Ÿ”น Array<Volume> The volumes associated with this pod.
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Optional
serviceAccount?๐Ÿ”น IServiceAccount The service account used to run this pod.
Optional

Methods

addContainer(container)๐Ÿ”น

Add a container to the pod.

addContainer(container: ContainerProps): Container
  • container (ContainerProps) The container.
  • image (string) Docker image name.
  • args (Array) Arguments to the entrypoint. The docker image’s CMD is used if command is not provided. Default: []
  • command (Array) Entrypoint array. Default: The docker image’s ENTRYPOINT.
  • env (MapEnvValue>) List of environment variables to set in the container. Default: No environment variables.
  • imagePullPolicy (ImagePullPolicy) Image pull policy for this container. Default: ImagePullPolicy.ALWAYS
  • liveness (Probe) Periodic probe of container liveness. Default: no liveness probe is defined
  • name (string) Name of the container specified as a DNS_LABEL. Default: ‘main’
  • port (number) Number of port to expose on the pod’s IP address. Default: No port is exposed.
  • readiness (Probe) Determines when the container is ready to serve traffic. Default: no readiness probe is defined
  • startup (Probe) StartupProbe indicates that the Pod has successfully initialized. Default: no startup probe is defined.
  • volumeMounts (Array<VolumeMount>) Pod volumes to mount into the container’s filesystem. Optional
  • workingDir (string) Container’s working directory. Default: The container runtime’s default.

Returns: * Container

addVolume(volume)๐Ÿ”น

Add a volume to the pod.

addVolume(volume: Volume): void

interface IPodTemplate ๐Ÿ”น

Implemented by: Deployment, Job, PodTemplate

Represents a resource that can be configured with a kuberenets pod template. (e.g Deployment, Job, …).

Use the PodTemplate class as an implementation helper.

Properties

Name Type Description
containers๐Ÿ”น Array<Container> The containers belonging to the pod.
podMetadata๐Ÿ”น ApiObjectMetadataDefinition Provides read/write access to the underlying pod metadata of the resource.
volumes๐Ÿ”น Array<Volume> The volumes associated with this pod.
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Optional
serviceAccount?๐Ÿ”น IServiceAccount The service account used to run this pod.
Optional

Methods

addContainer(container)๐Ÿ”น

Add a container to the pod.

addContainer(container: ContainerProps): Container
  • container (ContainerProps) The container.
  • image (string) Docker image name.
  • args (Array) Arguments to the entrypoint. The docker image’s CMD is used if command is not provided. Default: []
  • command (Array) Entrypoint array. Default: The docker image’s ENTRYPOINT.
  • env (MapEnvValue>) List of environment variables to set in the container. Default: No environment variables.
  • imagePullPolicy (ImagePullPolicy) Image pull policy for this container. Default: ImagePullPolicy.ALWAYS
  • liveness (Probe) Periodic probe of container liveness. Default: no liveness probe is defined
  • name (string) Name of the container specified as a DNS_LABEL. Default: ‘main’
  • port (number) Number of port to expose on the pod’s IP address. Default: No port is exposed.
  • readiness (Probe) Determines when the container is ready to serve traffic. Default: no readiness probe is defined
  • startup (Probe) StartupProbe indicates that the Pod has successfully initialized. Default: no startup probe is defined.
  • volumeMounts (Array<VolumeMount>) Pod volumes to mount into the container’s filesystem. Optional
  • workingDir (string) Container’s working directory. Default: The container runtime’s default.

Returns: * Container

addVolume(volume)๐Ÿ”น

Add a volume to the pod.

addVolume(volume: Volume): void

interface IResource ๐Ÿ”น

Implemented by: ConfigMap, Deployment, IngressV1Beta1, Job, Pod, Secret, Service, ServiceAccount

Represents a resource.

Properties

Name Type Description
name๐Ÿ”น string The Kubernetes name of this resource.

interface ISecret ๐Ÿ”น

Implemented by: Secret Obtainable from: Secret.fromSecretName()

Properties

Name Type Description
name๐Ÿ”น string The Kubernetes name of this resource.

interface IServiceAccount ๐Ÿ”น

Implemented by: ServiceAccount Obtainable from: ServiceAccount.fromServiceAccountName()

Properties

Name Type Description
name๐Ÿ”น string The Kubernetes name of this resource.

struct IngressV1Beta1Props ๐Ÿ”น

Properties for Ingress.

Name Type Description
defaultBackend?๐Ÿ”น IngressV1Beta1Backend The default backend services requests that do not match any rule.
Optional
metadata?๐Ÿ”น ApiObjectMetadata Metadata that all persisted resources must have, which includes all objects users must create.
Optional
rules?๐Ÿ”น Array<IngressV1Beta1Rule> Routing rules for this ingress.
Optional

struct IngressV1Beta1Rule ๐Ÿ”น

Represents the rules mapping the paths under a specified host to the related backend services.

Incoming requests are first evaluated for a host match, then routed to the backend associated with the matching path.

Name Type Description
backend๐Ÿ”น IngressV1Beta1Backend Backend defines the referenced service endpoint to which the traffic will be forwarded to.
host?๐Ÿ”น string Host is the fully qualified domain name of a network host, as defined by RFC 3986.
Default: If the host is unspecified, the Ingress routes all traffic based on the specified IngressRuleValue.
path?๐Ÿ”น string Path is an extended POSIX regex as defined by IEEE Std 1003.1, (i.e this follows the egrep/unix syntax, not the perl syntax) matched against the path of an incoming request. Currently it can contain characters disallowed from the conventional “path” part of a URL as defined by RFC 3986. Paths must begin with a ‘/’.
Default: If unspecified, the path defaults to a catch all sending traffic to the backend.

struct JobProps ๐Ÿ”น

Properties for initialization of Job.

Name Type Description
activeDeadline?๐Ÿ”น Duration Specifies the duration in seconds the job may be active before the system tries to terminate it.
Default: If unset, then there is no deadline.
backoffLimit?๐Ÿ”น number Specifies the number of retries before marking this job failed.
Default: If not set, system defaults to 6.
containers?๐Ÿ”น Array<ContainerProps> List of containers belonging to the pod.
Default: No containers. Note that a pod spec must include at least one container.
metadata?๐Ÿ”น ApiObjectMetadata Metadata that all persisted resources must have, which includes all objects users must create.
Optional
podMetadata?๐Ÿ”น ApiObjectMetadata The pod metadata.
Optional
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Default: RestartPolicy.ALWAYS
serviceAccount?๐Ÿ”น IServiceAccount A service account provides an identity for processes that run in a Pod.
Default: No service account.
ttlAfterFinished?๐Ÿ”น Duration Limits the lifetime of a Job that has finished execution (either Complete or Failed).
Default: If this field is unset, the Job won’t be automatically deleted.
volumes?๐Ÿ”น Array<Volume> List of volumes that can be mounted by containers belonging to the pod.
Default: No volumes.

struct MountOptions ๐Ÿ”น

Options for mounts.

Name Type Description
propagation?๐Ÿ”น MountPropagation Determines how mounts are propagated from the host to container and the other way around.
Default: MountPropagation.NONE
readOnly?๐Ÿ”น boolean Mounted read-only if true, read-write otherwise (false or unspecified).
Default: false
subPath?๐Ÿ”น string Path within the volume from which the container’s volume should be mounted.).
Default: “” the volume’s root
subPathExpr?๐Ÿ”น string Expanded path within the volume from which the container’s volume should be mounted.
Default: “” volume’s root.

struct PathMapping ๐Ÿ”น

Maps a string key to a path within a volume.

Name Type Description
path๐Ÿ”น string The relative path of the file to map the key to.
mode?๐Ÿ”น number Optional: mode bits to use on this file, must be a value between 0 and 0777.
Optional

struct PodProps ๐Ÿ”น

Properties for initialization of Pod.

Name Type Description
containers?๐Ÿ”น Array<ContainerProps> List of containers belonging to the pod.
Default: No containers. Note that a pod spec must include at least one container.
metadata?๐Ÿ”น ApiObjectMetadata Metadata that all persisted resources must have, which includes all objects users must create.
Optional
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Default: RestartPolicy.ALWAYS
serviceAccount?๐Ÿ”น IServiceAccount A service account provides an identity for processes that run in a Pod.
Default: No service account.
volumes?๐Ÿ”น Array<Volume> List of volumes that can be mounted by containers belonging to the pod.
Default: No volumes.

struct PodSpecProps ๐Ÿ”น

Properties of a PodSpec.

Name Type Description
containers?๐Ÿ”น Array<ContainerProps> List of containers belonging to the pod.
Default: No containers. Note that a pod spec must include at least one container.
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Default: RestartPolicy.ALWAYS
serviceAccount?๐Ÿ”น IServiceAccount A service account provides an identity for processes that run in a Pod.
Default: No service account.
volumes?๐Ÿ”น Array<Volume> List of volumes that can be mounted by containers belonging to the pod.
Default: No volumes.

struct PodTemplateProps ๐Ÿ”น

Properties of a PodTemplate.

Adds metadata information on top of the spec.

Name Type Description
containers?๐Ÿ”น Array<ContainerProps> List of containers belonging to the pod.
Default: No containers. Note that a pod spec must include at least one container.
podMetadata?๐Ÿ”น ApiObjectMetadata The pod metadata.
Optional
restartPolicy?๐Ÿ”น RestartPolicy Restart policy for all containers within the pod.
Default: RestartPolicy.ALWAYS
serviceAccount?๐Ÿ”น IServiceAccount A service account provides an identity for processes that run in a Pod.
Default: No service account.
volumes?๐Ÿ”น Array<Volume> List of volumes that can be mounted by containers belonging to the pod.
Default: No volumes.

struct ProbeOptions ๐Ÿ”น

Probe options.

Name Type Description
failureThreshold?๐Ÿ”น number Minimum consecutive failures for the probe to be considered failed after having succeeded.
Default: 3
initialDelaySeconds?๐Ÿ”น Duration Number of seconds after the container has started before liveness probes are initiated.
Default: immediate
periodSeconds?๐Ÿ”น Duration How often (in seconds) to perform the probe.
Default: Duration.seconds(10) Minimum value is 1.
successThreshold?๐Ÿ”น number Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1.
Default: 1 Must be 1 for liveness and startup. Minimum value is 1.
timeoutSeconds?๐Ÿ”น Duration Number of seconds after which the probe times out.
Default: Duration.seconds(1)

struct ResourceProps ๐Ÿ”น

Initialization properties for resources.

Name Type Description
metadata?๐Ÿ”น ApiObjectMetadata Metadata that all persisted resources must have, which includes all objects users must create.
Optional

struct SecretProps ๐Ÿ”น

Name Type Description
metadata?๐Ÿ”น ApiObjectMetadata Metadata that all persisted resources must have, which includes all objects users must create.
Optional
stringData?๐Ÿ”น Map stringData allows specifying non-binary secret data in string form.
Optional

struct SecretValue ๐Ÿ”น

Represents a specific value in JSON secret.

Name Type Description
key๐Ÿ”น string The JSON key.
secret๐Ÿ”น ISecret The secret.

struct ServiceAccountProps ๐Ÿ”น

Properties for initialization of ServiceAccount.

Properties for initialization of ServiceAccount.

Name Type Description
metadata?๐Ÿ”น ApiObjectMetadata Metadata that all persisted resources must have, which includes all objects users must create.
Optional
secrets?๐Ÿ”น Array<ISecret> List of secrets allowed to be used by pods running using this ServiceAccount.
Optional

struct ServiceIngressV1BetaBackendOptions ๐Ÿ”น

Options for setting up backends for ingress rules.

Name Type Description
port?๐Ÿ”น number The port to use to access the service.
Default: if the service exposes a single port, this port will be used.

struct ServicePort ๐Ÿ”น

Definition of a service port.

Name Type Description
port๐Ÿ”น number The port number the service will bind to.
name?๐Ÿ”น string The name of this port within the service.
Optional
nodePort?๐Ÿ”น number The port on each node on which this service is exposed when type=NodePort or LoadBalancer.
Default: to auto-allocate a port if the ServiceType of this Service requires one.
protocol?๐Ÿ”น Protocol The IP protocol for this port.
Default: Protocol.TCP
targetPort?๐Ÿ”น number The port number the service will redirect to.
Default: The value of port will be used.

struct ServicePortOptions ๐Ÿ”น

Name Type Description
name?๐Ÿ”น string The name of this port within the service.
Optional
nodePort?๐Ÿ”น number The port on each node on which this service is exposed when type=NodePort or LoadBalancer.
Default: to auto-allocate a port if the ServiceType of this Service requires one.
protocol?๐Ÿ”น Protocol The IP protocol for this port.
Default: Protocol.TCP
targetPort?๐Ÿ”น number The port number the service will redirect to.
Default: The value of port will be used.

struct ServiceProps ๐Ÿ”น

Properties for initialization of Service.

Name Type Description
clusterIP?๐Ÿ”น string The IP address of the service and is usually assigned randomly by the master.
Default: Automatically assigned.
externalIPs?๐Ÿ”น Array A list of IP addresses for which nodes in the cluster will also accept traffic for this service.
Default: No external IPs.
metadata?๐Ÿ”น ApiObjectMetadata Metadata that all persisted resources must have, which includes all objects users must create.
Optional
ports?๐Ÿ”น Array<ServicePort> The port exposed by this service.
Optional
type?๐Ÿ”น ServiceType Determines how the Service is exposed.
Default: ServiceType.ClusterIP

struct VolumeMount ๐Ÿ”น

Mount a volume from the pod to the container.

Name Type Description
path๐Ÿ”น string Path within the container at which the volume should be mounted.
volume๐Ÿ”น Volume The volume to mount.
propagation?๐Ÿ”น MountPropagation Determines how mounts are propagated from the host to container and the other way around.
Default: MountPropagation.NONE
readOnly?๐Ÿ”น boolean Mounted read-only if true, read-write otherwise (false or unspecified).
Default: false
subPath?๐Ÿ”น string Path within the volume from which the container’s volume should be mounted.).
Default: “” the volume’s root
subPathExpr?๐Ÿ”น string Expanded path within the volume from which the container’s volume should be mounted.
Default: “” volume’s root.

enum EmptyDirMedium ๐Ÿ”น

The medium on which to store the volume.

Name Description
DEFAULT ๐Ÿ”น The default volume of the backing node.
MEMORY ๐Ÿ”น Mount a tmpfs (RAM-backed filesystem) for you instead.

enum ImagePullPolicy ๐Ÿ”น

Name Description
ALWAYS ๐Ÿ”น Every time the kubelet launches a container, the kubelet queries the container image registry to resolve the name to an image digest.
IF_NOT_PRESENT ๐Ÿ”น The image is pulled only if it is not already present locally.
NEVER ๐Ÿ”น The image is assumed to exist locally.

enum MountPropagation ๐Ÿ”น

Name Description
NONE ๐Ÿ”น This volume mount will not receive any subsequent mounts that are mounted to this volume or any of its subdirectories by the host.
HOST_TO_CONTAINER ๐Ÿ”น This volume mount will receive all subsequent mounts that are mounted to this volume or any of its subdirectories.
BIDIRECTIONAL ๐Ÿ”น This volume mount behaves the same the HostToContainer mount.

enum Protocol ๐Ÿ”น

Name Description
TCP ๐Ÿ”น
UDP ๐Ÿ”น
SCTP ๐Ÿ”น

enum RestartPolicy ๐Ÿ”น

Restart policy for all containers within the pod.

Name Description
ALWAYS ๐Ÿ”น Always restart the pod after it exits.
ON_FAILURE ๐Ÿ”น Only restart if the pod exits with a non-zero exit code.
NEVER ๐Ÿ”น Never restart the pod.

enum ServiceType ๐Ÿ”น

For some parts of your application (for example, frontends) you may want to expose a Service onto an external IP address, that’s outside of your cluster.

Kubernetes ServiceTypes allow you to specify what kind of Service you want. The default is ClusterIP.

Name Description
CLUSTER_IP ๐Ÿ”น Exposes the Service on a cluster-internal IP.
NODE_PORT ๐Ÿ”น Exposes the Service on each Node’s IP at a static port (the NodePort).
LOAD_BALANCER ๐Ÿ”น Exposes the Service externally using a cloud provider’s load balancer.
EXTERNAL_NAME ๐Ÿ”น Maps the Service to the contents of the externalName field (e.g. foo.bar.example.com), by returning a CNAME record with its value. No proxying of any kind is set up.