| Interface | Description |
|---|---|
| AddDirectoryOptions |
(experimental) Options for `configmap.addDirectory()`.
|
| CommandProbeOptions |
(experimental) Options for `Probe.fromCommand()`.
|
| ConfigMapProps |
(experimental) Properties for initialization of `ConfigMap`.
|
| ConfigMapVolumeOptions |
(experimental) Options for the ConfigMap-based volume.
|
| ContainerProps |
(experimental) Properties for creating a container.
|
| DeploymentProps |
(experimental) Properties for initialization of `Deployment`.
|
| EmptyDirVolumeOptions |
(experimental) Options for volumes populated with an empty directory.
|
| EnvValueFromConfigMapOptions |
(experimental) Options to specify an envionment variable value from a ConfigMap key.
|
| EnvValueFromProcessOptions |
(experimental) Options to specify an environment variable value from the process environment.
|
| EnvValueFromSecretOptions |
(experimental) Options to specify an environment variable value from a Secret.
|
| ExposeOptions |
(experimental) Options for exposing a deployment via a service.
|
| HttpGetProbeOptions |
(experimental) Options for `Probe.fromHttpGet()`.
|
| IConfigMap |
(experimental) Represents a config map.
|
| IngressProps |
(experimental) Properties for `Ingress`.
|
| IngressRule |
(experimental) Represents the rules mapping the paths under a specified host to the related backend services.
|
| IPodSpec |
(experimental) Represents a resource that can be configured with a kuberenets pod spec.
|
| IPodTemplate |
(experimental) Represents a resource that can be configured with a kuberenets pod template.
|
| IResource |
(experimental) Represents a resource.
|
| ISecret | |
| IServiceAccount | |
| JobProps |
(experimental) Properties for initialization of `Job`.
|
| MountOptions |
(experimental) Options for mounts.
|
| PathMapping |
(experimental) Maps a string key to a path within a volume.
|
| PodProps |
(experimental) Properties for initialization of `Pod`.
|
| PodSpecProps |
(experimental) Properties of a `PodSpec`.
|
| PodTemplateProps |
(experimental) Properties of a `PodTemplate`.
|
| ProbeOptions |
(experimental) Probe options.
|
| ResourceProps |
(experimental) Initialization properties for resources.
|
| SecretProps | |
| SecretValue |
(experimental) Represents a specific value in JSON secret.
|
| ServiceAccountProps |
(experimental) Properties for initialization of `ServiceAccount`.
|
| ServiceIngressBackendOptions |
(experimental) Options for setting up backends for ingress rules.
|
| ServicePort |
(experimental) Definition of a service port.
|
| ServicePortOptions | |
| ServiceProps |
(experimental) Properties for initialization of `Service`.
|
| SizeConversionOptions |
(experimental) Options for how to convert time to a different unit.
|
| TimeConversionOptions |
(experimental) Options for how to convert time to a different unit.
|
| VolumeMount |
(experimental) Mount a volume from the pod to the container.
|
| Class | Description |
|---|---|
| AddDirectoryOptions.Builder |
A builder for
AddDirectoryOptions |
| AddDirectoryOptions.Jsii$Proxy |
An implementation for
AddDirectoryOptions |
| CommandProbeOptions.Builder |
A builder for
CommandProbeOptions |
| CommandProbeOptions.Jsii$Proxy |
An implementation for
CommandProbeOptions |
| ConfigMap |
(experimental) ConfigMap holds configuration data for pods to consume.
|
| ConfigMap.Builder |
(experimental) A fluent builder for
ConfigMap. |
| ConfigMapProps.Builder |
A builder for
ConfigMapProps |
| ConfigMapProps.Jsii$Proxy |
An implementation for
ConfigMapProps |
| ConfigMapVolumeOptions.Builder |
A builder for
ConfigMapVolumeOptions |
| ConfigMapVolumeOptions.Jsii$Proxy |
An implementation for
ConfigMapVolumeOptions |
| Container |
(experimental) A single application container that you want to run within a pod.
|
| Container.Builder |
(experimental) A fluent builder for
Container. |
| ContainerProps.Builder |
A builder for
ContainerProps |
| ContainerProps.Jsii$Proxy |
An implementation for
ContainerProps |
| Deployment |
(experimental) A Deployment provides declarative updates for Pods and ReplicaSets.
|
| Deployment.Builder |
(experimental) A fluent builder for
Deployment. |
| DeploymentProps.Builder |
A builder for
DeploymentProps |
| DeploymentProps.Jsii$Proxy |
An implementation for
DeploymentProps |
| Duration |
(experimental) Represents a length of time.
|
| EmptyDirVolumeOptions.Builder |
A builder for
EmptyDirVolumeOptions |
| EmptyDirVolumeOptions.Jsii$Proxy |
An implementation for
EmptyDirVolumeOptions |
| EnvValue |
(experimental) Utility class for creating reading env values from various sources.
|
| EnvValueFromConfigMapOptions.Builder |
A builder for
EnvValueFromConfigMapOptions |
| EnvValueFromConfigMapOptions.Jsii$Proxy |
An implementation for
EnvValueFromConfigMapOptions |
| EnvValueFromProcessOptions.Builder |
A builder for
EnvValueFromProcessOptions |
| EnvValueFromProcessOptions.Jsii$Proxy |
An implementation for
EnvValueFromProcessOptions |
| EnvValueFromSecretOptions.Builder |
A builder for
EnvValueFromSecretOptions |
| EnvValueFromSecretOptions.Jsii$Proxy |
An implementation for
EnvValueFromSecretOptions |
| ExposeOptions.Builder |
A builder for
ExposeOptions |
| ExposeOptions.Jsii$Proxy |
An implementation for
ExposeOptions |
| HttpGetProbeOptions.Builder |
A builder for
HttpGetProbeOptions |
| HttpGetProbeOptions.Jsii$Proxy |
An implementation for
HttpGetProbeOptions |
| IConfigMap.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| Ingress |
(experimental) Ingress is a collection of rules that allow inbound connections to reach the endpoints defined by a backend.
|
| Ingress.Builder |
(experimental) A fluent builder for
Ingress. |
| IngressBackend |
(experimental) The backend for an ingress path.
|
| IngressProps.Builder |
A builder for
IngressProps |
| IngressProps.Jsii$Proxy |
An implementation for
IngressProps |
| IngressRule.Builder |
A builder for
IngressRule |
| IngressRule.Jsii$Proxy |
An implementation for
IngressRule |
| IPodSpec.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IPodTemplate.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IResource.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| ISecret.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IServiceAccount.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| Job |
(experimental) A Job creates one or more Pods and ensures that a specified number of them successfully terminate.
|
| Job.Builder |
(experimental) A fluent builder for
Job. |
| JobProps.Builder |
A builder for
JobProps |
| JobProps.Jsii$Proxy |
An implementation for
JobProps |
| MountOptions.Builder |
A builder for
MountOptions |
| MountOptions.Jsii$Proxy |
An implementation for
MountOptions |
| PathMapping.Builder |
A builder for
PathMapping |
| PathMapping.Jsii$Proxy |
An implementation for
PathMapping |
| Pod |
(experimental) Pod is a collection of containers that can run on a host.
|
| Pod.Builder |
(experimental) A fluent builder for
Pod. |
| PodProps.Builder |
A builder for
PodProps |
| PodProps.Jsii$Proxy |
An implementation for
PodProps |
| PodSpec |
(experimental) Provides read/write capabilities ontop of a `PodSpecProps`.
|
| PodSpec.Builder |
(experimental) A fluent builder for
PodSpec. |
| PodSpecProps.Builder |
A builder for
PodSpecProps |
| PodSpecProps.Jsii$Proxy |
An implementation for
PodSpecProps |
| PodTemplate |
(experimental) Provides read/write capabilities ontop of a `PodTemplateProps`.
|
| PodTemplate.Builder |
(experimental) A fluent builder for
PodTemplate. |
| PodTemplateProps.Builder |
A builder for
PodTemplateProps |
| PodTemplateProps.Jsii$Proxy |
An implementation for
PodTemplateProps |
| Probe |
(experimental) Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.
|
| ProbeOptions.Builder |
A builder for
ProbeOptions |
| ProbeOptions.Jsii$Proxy |
An implementation for
ProbeOptions |
| Resource |
(experimental) Base class for all Kubernetes objects in stdk8s.
|
| ResourceProps.Builder |
A builder for
ResourceProps |
| ResourceProps.Jsii$Proxy |
An implementation for
ResourceProps |
| Secret |
(experimental) Kubernetes Secrets let you store and manage sensitive information, such as passwords, OAuth tokens, and ssh keys.
|
| Secret.Builder |
(experimental) A fluent builder for
Secret. |
| SecretProps.Builder |
A builder for
SecretProps |
| SecretProps.Jsii$Proxy |
An implementation for
SecretProps |
| SecretValue.Builder |
A builder for
SecretValue |
| SecretValue.Jsii$Proxy |
An implementation for
SecretValue |
| Service |
(experimental) An abstract way to expose an application running on a set of Pods as a network service.
|
| Service.Builder |
(experimental) A fluent builder for
Service. |
| ServiceAccount |
(experimental) A service account provides an identity for processes that run in a Pod.
|
| ServiceAccount.Builder |
(experimental) A fluent builder for
ServiceAccount. |
| ServiceAccountProps.Builder |
A builder for
ServiceAccountProps |
| ServiceAccountProps.Jsii$Proxy |
An implementation for
ServiceAccountProps |
| ServiceIngressBackendOptions.Builder |
A builder for
ServiceIngressBackendOptions |
| ServiceIngressBackendOptions.Jsii$Proxy |
An implementation for
ServiceIngressBackendOptions |
| ServicePort.Builder |
A builder for
ServicePort |
| ServicePort.Jsii$Proxy |
An implementation for
ServicePort |
| ServicePortOptions.Builder |
A builder for
ServicePortOptions |
| ServicePortOptions.Jsii$Proxy |
An implementation for
ServicePortOptions |
| ServiceProps.Builder |
A builder for
ServiceProps |
| ServiceProps.Jsii$Proxy |
An implementation for
ServiceProps |
| Size |
(experimental) Represents the amount of digital storage.
|
| SizeConversionOptions.Builder |
A builder for
SizeConversionOptions |
| SizeConversionOptions.Jsii$Proxy |
An implementation for
SizeConversionOptions |
| TimeConversionOptions.Builder |
A builder for
TimeConversionOptions |
| TimeConversionOptions.Jsii$Proxy |
An implementation for
TimeConversionOptions |
| Volume |
(experimental) Volume represents a named volume in a pod that may be accessed by any container in the pod.
|
| VolumeMount.Builder |
A builder for
VolumeMount |
| VolumeMount.Jsii$Proxy |
An implementation for
VolumeMount |
| Enum | Description |
|---|---|
| EmptyDirMedium |
(experimental) The medium on which to store the volume.
|
| ImagePullPolicy | |
| MountPropagation | |
| Protocol | |
| RestartPolicy |
(experimental) Restart policy for all containers within the pod.
|
| ServiceType |
(experimental) 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.
|
| SizeRoundingBehavior |
(experimental) Rounding behaviour when converting between units of `Size`.
|
This library is in very early stages of development, as such, and in correspondence with a0.xsemantic major version line, itsAPIis likely to rapidly change in breaking ways. It is therefore not recommended to use library for production workloads.
cdk8s+ is a software development framework that provides high level abstractions for authoring Kubernetes applications. Built on top of the auto generated building blocks provided by cdk8s, this library includes a hand crafted construct for each native kubernetes object, exposing richer API's with reduced complexity.
cdk8s+ is currently built on top of version 1.17.0 of the kubernetes API specifications.
If you are deploying manifests produced by cdk8s+ onto clusters of a lower version, you might encounter some unsupported spec properties or invalid manifests.
See Supporting various k8s API specs for more details and progress on this issue.
We strive to develop this library with full transparency and as much community feedback and contributions as possible. To that end, we publish this development version. The lack of features/capabilities is intentional, we look forward to build and expand this framework with the help of the community.
If you are interested in contributing, see Contribution Guide.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
import org.cdk8s.*;
import path.*;
// our cdk app
App app = new App();
// our kuberentes chart
Chart chart = new Chart(app, "Chart");
// lets create a volume that contains our app.
// we use a trick with a config map!
ConfigMap appData = new ConfigMap(chart, "AppData");
appData.addDirectory(path.join(__dirname, "app"));
Volume appVolume = kplus.Volume.fromConfigMap(appData);
// now we create a container that runs our app
String appPath = "/var/lib/app";
int port = 80;
Container container = new Container(new ContainerProps()
.image("node:14.4.0-alpine3.12")
.command(asList("node", "index.js", port))
.port(port)
.workingDir(appPath));
// make the app accessible to the container
container.mount(appPath, appVolume);
// now lets create a deployment to run a few instances of this container
Deployment deployment = new Deployment(chart, "Deployment", new DeploymentProps()
.replicas(3)
.containers(asList(container)));
// finally, we expose the deployment as a load balancer service and make it run
deployment.expose(8080, new ExposeOptions().serviceType(kplus.ServiceType.getLOAD_BALANCER()));
// we are done, synth
app.synth();
apiVersion: v1
data:
index.js: |-
var http = require('http');
var port = process.argv[2];
//create a server object:
http.createServer(function (req, res) {
res.write('Hello World!'); //write a response to the client
res.end(); //end the response
}).listen(port); //the server object listens on port 80
kind: ConfigMap
metadata:
annotations: {}
labels: {}
name: chart-appdata-configmap-da4c63ab
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels: {}
name: chart-deployment-pod-d4285cc9
spec:
replicas: 3
selector:
matchLabels:
cdk8s.deployment: ChartDeploymentCFC2E30C
template:
metadata:
annotations: {}
labels:
cdk8s.deployment: ChartDeploymentCFC2E30C
spec:
containers:
- command:
- node
- index.js
- "80"
env: []
image: node:14.4.0-alpine3.12
name: main
ports:
- containerPort: 80
volumeMounts:
- mountPath: /var/lib/app
name: configmap-chart-appdata-configmap-da4c63ab
workingDir: /var/lib/app
volumes:
- configMap:
name: chart-appdata-configmap-da4c63ab
name: configmap-chart-appdata-configmap-da4c63ab
---
apiVersion: v1
kind: Service
metadata:
annotations: {}
labels: {}
name: chart-deployment-service-pod-42f50c26
spec:
externalIPs: []
ports:
- port: 8080
targetPort: 80
selector:
cdk8s.deployment: ChartDeploymentCFC2E30C
type: LoadBalancer
We currently support both Python and TypeScript/JavaScript. More languages are coming soon.
We would love to hear which languages you want to see next: Languages Support
❯ npm install cdk8s-plus cdk8s
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
import org.cdk8s.*;
App app = new App();
Chart chart = new Chart(app, "Chart");
new Deployment(chart, "Deployment", new DeploymentProps()
.replicas(3)
.containers(asList(new Container(new ContainerProps()
.image("ubuntu")))));
❯ pip install cdk8s-plus cdk8s
import cdk8s_plus as kplus import cdk8s app = cdk8s.App() chart = cdk8s.Chart(app, 'Chart') kplus.Deployment(chart, 'Deployment', replicas=1, containers=[kplus.Container(image='ubuntu')] )
Following are excerpts for the usage of every construct provided by this library. It details the commonly used patterns and configuration properties. In general, every such construct can be configured using two mechanisms:
The documentation presented here focuses on post instantiation mutations, however, every such mutation can also be pre-configured using constructor properties for the corresponding spec. A complete API reference can be found in here.
Container
Define containers that run in a pod using the Container class.
API Reference: Container
Environment variables can be added to containers using various sources, via semantically explicit API's:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
Container container = new Container(new ContainerProps()
.image("my-app"));
// explicitly use a value.
container.addEnv("endpoint", kplus.EnvValue.fromValue("value"));
// use a specific key from a config map.
IConfigMap backendsConfig = kplus.ConfigMap.fromConfigMapName("backends");
container.addEnv("endpoint", kplus.EnvValue.fromConfigMap(backendsConfig, "endpoint"));
// use a specific key from a secret.
ISecret credentials = kplus.Secret.fromSecretName("credentials");
container.addEnv("password", kplus.EnvValue.fromSecret(credentials, "password"));
A very common capability is to mount a volume with some data onto a container. Using pure kubernetes API, this would require writing something like:
kind: Pod
apiVersion: v1
spec:
containers:
- name: main
volumeMounts:
- mountPath: /path/to/mount
name: 'config-volume'
volumes:
- name: 'config-volume'
configMap:
name: 'config'
Notice the apparent redundancy of having to specify the volume name twice. Also, if you happen to need the same mount in other pods, you would need to duplicate this configuration. This can get complex and cluttered very fast.
In contrast, here is how to do this with cdk8s+:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
IConfigMap config = kplus.ConfigMap.fromConfigMapName("config");
Volume volume = kplus.Volume.fromConfigMap(config);
Container container = new Container(new ContainerProps()
.image("my-app"));
// Cool alert: every pod that will later be configured with this container,
// will automatically have access to this volume, so you don't need to explicitly add it to the pod spec!.
container.mount("/path/to/mount", volume);
A Probe is a diagnostic performed periodically by the kubelet on a Container. To perform a diagnostic, the kubelet calls a Handler implemented by the container.
A Probe instance can be created through one of the fromXxx static methods:
Probe.fromHttpGet()Probe.fromCommand()
Readiness probes can be configured at the container-level through the readiness option:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Container.Builder.create()
// ...
.readiness(kplus.Probe.fromHttpGet("/ping"))
.build();
See the API reference for details.
VolumeVolume represents a named volume in a pod that may be accessed by any container in the pod.
API Reference: Volume
A very useful operation is to create a volume from a ConfigMap. Kubernetes will translate every key in the config map to a file,
who's content is the value of the key.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
IConfigMap configMap = kplus.ConfigMap.fromConfigMapName("redis-config");
Volume configVolume = kplus.Volume.fromConfigMap(configMap);
The easiest way to allocate some persistent storage to your container is to create a volume from an empty directory. This volume, as the name suggests, is initially empty, and can be written to by containers who mount it. The data in the volume is preserved throughout the lifecycle of the pod, but is deleted forever as soon as the pod itself is removed.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
Volume data = kplus.Volume.fromEmptyDir(configMap);
Container redis = new Container(new ContainerProps()
.image("redis"));
// mount to the redis container.
redis.mount("/var/lib/redis", data);
JobJobs are a very useful concept in kubernetes deployments. They can be used for add-hoc provisioning tasks, as well as long running processing jobs.
API Reference: Job
In configuration, they don't differ much from regular pods, but offer some additional properties.
You can configure a TTL for the job after it finished its execution successfully.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.*;
import org.cdk8s.plus.*;
App app = new App();
Chart chart = new Chart(app, "Chart");
// let's define a job spec, and set a 1 second TTL.
Job load = new Job(chart, "LoadData", new JobProps()
.ttlAfterFinished(kplus.Duration.seconds(1)));
// now add a container to all the pods created by this job
job.addContainer(new Container(new ContainerProps()
.image("loader")));
ServiceUse services when you want to expose a set of pods using a stable network identity. They can also be used for externalizing endpoints to clients outside of the kubernetes cluster.
API Reference: Service
Services must be configured with selectors that tell it which pods should it serve. The most common selector method is using labels.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.*;
import org.cdk8s.plus.*;
App app = new App();
Chart chart = new Chart(app, "Chart");
Service frontends = new Service(chart, "FrontEnds");
// this will cause the service to select all pods with the 'run: frontend' label.
frontends.selectByLabel("run", "frontend");
Ports that the service will listen and redirect to can be configured like so:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.*;
import org.cdk8s.plus.*;
App app = new App();
Chart chart = new Chart(app, "Chart");
Service frontends = new Service(chart, "FrontEnds");
// make the service bind to port 9000 and redirect to port 80 on the associated containers.
frontends.serve(Map.of("port", 9000, "targetPort", 80));
DeploymentCreate a deployment to govern the lifecycle and orchestration of a set of identical pods.
API Reference: Deployment
When you specify pods in a deployment, you normally have to configure the appropriate labels and selectors to make the deployment control the relevant pods. This construct does this automatically.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.*;
import org.cdk8s.plus.*;
App app = new App();
Chart chart = new Chart(app, "Chart");
new Deployment(chart, "FrontEnds", new DeploymentProps()
.containers(asList(new Container(new ContainerProps().image("node")))));
Note the resulting manifest contains a special cdk8s.deployment label that is applied to the pods, and is used as
the selector for the deployment.
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels: {}
name: chart-frontends-pod-a48e7f2e
spec:
replicas: 1
selector:
matchLabels:
cdk8s.deployment: ChartFrontEndsDD8A97CE
template:
metadata:
annotations: {}
labels:
cdk8s.deployment: ChartFrontEndsDD8A97CE
Following up on pod selection, you can also easily create a service that will select the pods relevant to the deployment.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826 // store the deployment to created in a constant var frontends = new Deployment(chart, "FrontEnds"); // create a ClusterIP service that listens on port 9000 and redirects to port 9000 on the containers. frontends.expose(9000);
Notice the resulting manifest, will have the same cdk8s.deployment magic label as the selector.
This will cause the service to attach to the pods that were configured as part of the said deployment.
apiVersion: v1
kind: Service
metadata:
annotations: {}
labels: {}
name: chart-frontends-service-pod-1f70150b
spec:
externalIPs: []
ports:
- port: 9000
selector:
cdk8s.deployment: ChartFrontEndsDD8A97CE
type: ClusterIP
ConfigMapConfigMap are used to store configuration data. They provide a dictionary based data structure that can be consumed in various shapes and forms.
API Reference: ConfigMap
ConfigMap
You can reference to an existing ConfigMap like so. Note that this does not create a new object,
and will therefore not be included in the resulting manifest.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
IConfigMap config = kplus.ConfigMap.fromConfigMapName("config");
// the 'config' constant can later be used by API's that require an IConfigMap.
// for example when creating a volume.
Volume volume = kplus.Volume.fromConfigMap(config);
You can create config maps and add some data to them like so:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
import org.cdk8s.*;
App app = new App();
Chart chart = new Chart(app, "Chart");
var config = new new ConfigMap(chart, "Config")();
config.addData("url", "https://my-endpoint:8080");
Here is a nifty little trick you can use to create a volume that contains a directory on the client machine (machine that runs cdk8s synth):
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
import org.cdk8s.*;
import path.*;
App app = new App();
Chart chart = new Chart(app, "Chart");
var appMap = new new ConfigMap(chart, "Config")();
// add the files in the directory to the config map.
// this will create a key for each file.
// note that only top level files will be included, sub-directories are not yet supported.
appMap.addDirectory(path.join(__dirname, "app"));
Volume appVolume = kplus.Volume.fromConfigMap(appMap);
// for here, just mount the volume to a container, and run your app!
String mountPath = "/var/app";
Container container = new Container(new ContainerProps()
.image("node")
.command(asList("node", "app.js"))
.workingDir(mountPath));
container.mount(mountPath, appVolume);
PodA pod is essentially a collection of containers. It is the most fundamental computation unit that can be provisioned.
API Reference: Pod
Containers and volumes can be added to pod definition like so:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
Container container = new Container(new ContainerProps()
.image("node"));
Volume storage = kplus.Volume.fromEmptyDir("storage");
container.mount("/data", storage);
var app = new App();
var chart = new Chart(app, "Chart");
var pod = new new Pod(chart, "Pod")();
// this will automatically add the volume as well.
pod.addContainer(container);
// but if you want to explicitly add it, simply use:
pod.addVolume(storage);
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
var app = new App();
var chart = new Chart(app, "Chart");
var pod = new new Pod(chart, "Pod", new PodProps()
.restartPolicy(NEVER))();
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
var app = new App();
var chart = new Chart(app, "Chart");
var pod = new new Pod(chart, "Pod", new PodProps()
.serviceAccount(fromServiceAccountName("aws")))();
SecretSecrets are used to store confidential information. Never store such information on the definition of the pod itself.
API Reference: Secret
SecretTo reference a secret created outside of your deployment definition, use the following. Note that this does not create a new object, and will therefore not be included in the resulting manifest.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
ISecret secret = kplus.Secret.fromSecretName("aws-creds");
To create a new secret with some data, use:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
import org.cdk8s.*;
App app = new App();
Chart chart = new Chart(app, "Chart");
Secret secret = new Secret(chart, "Secret");
secret.addStringData("password", "some-encrypted-data");
ServiceAccountUse service accounts to provide an identity for pods.
API Reference: ServiceAccount
ServiceAccountTo reference a service account created outside of your deployment definition, use the following. Note that this does not create a new object, and will therefore not be included in the resulting manifest.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
IServiceAccount serviceAccount = kplus.ServiceAccount.fromServiceAccountName("aws-service");
To create a new service account, and give it access to some secrets, use the following:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import org.cdk8s.plus.*;
import org.cdk8s.*;
App app = new App();
Chart chart = new Chart(app, "Chart");
ISecret awsCreds = kplus.Secret.fromSecretName("aws-creds");
ServiceAccount awsService = new ServiceAccount(chart, "AWS");
// give access to the aws creds secret.
awsService.addSecret(awsCreds);
IngressIngress manages external access to services in a cluster, typically through HTTP. Ingress may provide load balancing, SSL termination and name-based virtual hosting.
You must have an Ingress controller to satisfy an Ingress. Only creating an Ingress resource has no effect.
API Reference: Ingress
The following example will route HTTP requests sent to the /hello url prefix
to a service associated with a deployment of the
hashicorp/http-echo image.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
var helloDeployment = Deployment.Builder.create(this, text)
.containers(asList(
Container.Builder.create()
.image("hashicorp/http-echo")
.args(asList("-text", "hello ingress"))
.build()))
.build();
var helloService = helloDeployment.expose(5678);
var ingress = new Ingress(this, "ingress");
ingress.addRule("/hello", kplus.IngressBackend.fromService(helloService));
You can use addHostRule(host, path, backend) to define a route that will only
apply to requests with this Host header. This can be used to implement virtual
hosts.
The addDefaultBackend(backend) and addHostDefaultBackend(host, backend)
methods can be used to define backends that will accept all requests that do not
match any other rules.
The TCP port used to route requests to services will be determined based on
which ports are exposed by the service (e.g. through serve()). If the service
exposes multiple ports, then a port must be specified via
IngressBackend.fromService(service, { port }.
Copyright © 2020. All rights reserved.