Direct Kubernetes resource management including manifests, Helm charts, patches, and value queries for comprehensive workload deployment and configuration.
Apply and manage Kubernetes manifests using kubectl.
/**
* Apply/delete Kubernetes manifests using kubectl
*/
class KubernetesManifest extends Construct {
constructor(scope: Construct, id: string, props: KubernetesManifestProps);
/** CloudFormation resource type */
static readonly RESOURCE_TYPE = "Custom::AWSCDK-EKS-KubernetesResource";
}
/**
* Kubernetes manifest properties
*/
interface KubernetesManifestProps extends KubernetesManifestOptions {
/** EKS cluster */
readonly cluster: ICluster;
/** Kubernetes resource manifests */
readonly manifest: Record<string, any>[];
}
/**
* Kubernetes manifest options
*/
interface KubernetesManifestOptions {
/** Whether to prune old resources */
readonly prune?: boolean;
/** Skip validation */
readonly skipValidation?: boolean;
/** Ingress load balancer address */
readonly ingressAlb?: boolean;
/** Service load balancer address */
readonly ingressAlbScheme?: AlbScheme;
}Usage Examples:
import * as eks from "@aws-cdk/aws-eks";
// Deploy a simple pod
cluster.addManifest("HelloPod", {
apiVersion: "v1",
kind: "Pod",
metadata: {
name: "hello-pod",
namespace: "default",
labels: { app: "hello" },
},
spec: {
containers: [{
name: "hello",
image: "nginx:latest",
ports: [{ containerPort: 80 }],
}],
},
});
// Deploy multiple resources
const appManifest = cluster.addManifest("WebApp",
// Deployment
{
apiVersion: "apps/v1",
kind: "Deployment",
metadata: { name: "webapp", namespace: "default" },
spec: {
replicas: 3,
selector: { matchLabels: { app: "webapp" } },
template: {
metadata: { labels: { app: "webapp" } },
spec: {
containers: [{
name: "app",
image: "nginx:alpine",
ports: [{ containerPort: 80 }],
resources: {
requests: { memory: "64Mi", cpu: "50m" },
limits: { memory: "128Mi", cpu: "100m" },
},
}],
},
},
},
},
// Service
{
apiVersion: "v1",
kind: "Service",
metadata: { name: "webapp-service", namespace: "default" },
spec: {
selector: { app: "webapp" },
ports: [{ port: 80, targetPort: 80 }],
type: "ClusterIP",
},
}
);Install and manage Helm charts in the cluster.
/**
* Install and manage Helm charts in the cluster
*/
class HelmChart extends Construct {
constructor(scope: Construct, id: string, props: HelmChartProps);
/** CloudFormation resource type */
static readonly RESOURCE_TYPE = "Custom::AWSCDK-EKS-HelmChart";
}
/**
* Helm chart properties
*/
interface HelmChartProps extends HelmChartOptions {
/** EKS cluster */
readonly cluster: ICluster;
/** Chart name */
readonly chart: string;
}
/**
* Helm chart options
*/
interface HelmChartOptions {
/** Release name */
readonly release?: string;
/** Chart version */
readonly version?: string;
/** Helm repository URL */
readonly repository?: string;
/** Kubernetes namespace */
readonly namespace?: string;
/** Chart values */
readonly values?: { [key: string]: any };
/** Create namespace if it doesn't exist */
readonly createNamespace?: boolean;
/** Timeout for Helm operations */
readonly timeout?: Duration;
/** Wait for resources to be ready */
readonly wait?: boolean;
/** Chart values as YAML string */
readonly valuesYaml?: string;
}Usage Examples:
import * as eks from "@aws-cdk/aws-eks";
// Install NGINX Ingress Controller
cluster.addHelmChart("NginxIngress", {
chart: "ingress-nginx",
repository: "https://kubernetes.github.io/ingress-nginx",
namespace: "ingress-nginx",
createNamespace: true,
values: {
controller: {
service: {
type: "LoadBalancer",
annotations: {
"service.beta.kubernetes.io/aws-load-balancer-type": "nlb",
},
},
},
},
});
// Install Prometheus with custom values
cluster.addHelmChart("Prometheus", {
chart: "kube-prometheus-stack",
repository: "https://prometheus-community.github.io/helm-charts",
namespace: "monitoring",
createNamespace: true,
version: "45.7.1",
values: {
prometheus: {
prometheusSpec: {
retention: "30d",
storageSpec: {
volumeClaimTemplate: {
spec: {
storageClassName: "gp2",
accessModes: ["ReadWriteOnce"],
resources: { requests: { storage: "50Gi" } },
},
},
},
},
},
grafana: {
enabled: true,
adminPassword: "admin123", // Use AWS Secrets Manager in production
},
},
});Apply JSON patches to existing Kubernetes resources.
/**
* Apply JSON patches to Kubernetes resources
*/
class KubernetesPatch extends Construct {
constructor(scope: Construct, id: string, props: KubernetesPatchProps);
}
/**
* Kubernetes patch properties
*/
interface KubernetesPatchProps {
/** EKS cluster */
readonly cluster: ICluster;
/** Resource to patch */
readonly resourceName: string;
/** Resource namespace */
readonly resourceNamespace?: string;
/** API version */
readonly applyPatch: { [key: string]: any };
/** Restore patch */
readonly restorePatch: { [key: string]: any };
/** Patch type */
readonly patchType?: PatchType;
}
/**
* Patch types
*/
enum PatchType {
/** JSON patch */
JSON = "application/json-patch+json",
/** Strategic merge patch */
STRATEGIC = "application/strategic-merge-patch+json",
/** Merge patch */
MERGE = "application/merge-patch+json"
}Usage Examples:
// Patch CoreDNS for Fargate
new eks.KubernetesPatch(this, "CoreDnsPatch", {
cluster: cluster,
resourceName: "coredns",
resourceNamespace: "kube-system",
applyPatch: {
spec: {
template: {
metadata: {
annotations: {
"eks.amazonaws.com/compute-type": "fargate",
},
},
},
},
},
restorePatch: {
spec: {
template: {
metadata: {
annotations: {
"eks.amazonaws.com/compute-type": "ec2",
},
},
},
},
},
patchType: eks.PatchType.STRATEGIC,
});Fetch values from Kubernetes objects using kubectl get.
/**
* Fetch values from Kubernetes objects using kubectl get
*/
class KubernetesObjectValue extends Construct {
constructor(scope: Construct, id: string, props: KubernetesObjectValueProps);
/** CloudFormation resource type */
static readonly RESOURCE_TYPE = "Custom::AWSCDK-EKS-KubernetesObjectValue";
/** The fetched value as a string token */
readonly value: string;
}
/**
* Kubernetes object value properties
*/
interface KubernetesObjectValueProps {
/** EKS cluster */
readonly cluster: ICluster;
/** Object type */
readonly objectType: string;
/** Object name */
readonly objectName: string;
/** Object namespace */
readonly objectNamespace?: string;
/** JSONPath expression */
readonly jsonPath: string;
/** Timeout */
readonly timeout?: Duration;
}Usage Examples:
// Get load balancer hostname
const ingressHostname = new eks.KubernetesObjectValue(this, "IngressHostname", {
cluster: cluster,
objectType: "ingress",
objectName: "my-ingress",
objectNamespace: "default",
jsonPath: ".status.loadBalancer.ingress[0].hostname",
});
// Use the value in other resources
new cdk.CfnOutput(this, "IngressUrl", {
value: `http://${ingressHostname.value}`,
});
// Get service load balancer IP
const serviceIP = new eks.KubernetesObjectValue(this, "ServiceIP", {
cluster: cluster,
objectType: "service",
objectName: "nginx-service",
objectNamespace: "default",
jsonPath: ".status.loadBalancer.ingress[0].ip",
});/**
* Deploy CDK8s chart to the cluster
*/
addCdk8sChart(id: string, chart: Construct, options?: KubernetesManifestOptions): KubernetesManifest;CDK8s Usage Example:
import * as cdk8s from "cdk8s";
import * as kplus from "cdk8s-plus-21";
// Create CDK8s chart
const chart = new cdk8s.Chart(this, "MyChart");
const deployment = new kplus.Deployment(chart, "Deployment", {
replicas: 3,
containers: [{
image: "nginx:latest",
port: 80,
}],
});
// Deploy to EKS cluster
cluster.addCdk8sChart("MyCdk8sChart", chart);