# KubernetesManifestProps

Properties for KubernetesManifest.

Extends: [KubernetesManifestOptions](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_eks.KubernetesManifestOptions.html)
Used as props by: [KubernetesManifest](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_eks.KubernetesManifest.html)

- Source: [`aws-eks/lib/k8s-manifest.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-eks/lib/k8s-manifest.ts#L82)

## Example

TypeScript:

```ts
declare const cluster: eks.Cluster;
const appLabel = { app: "hello-kubernetes" };

const deployment = {
  apiVersion: "apps/v1",
  kind: "Deployment",
  metadata: { name: "hello-kubernetes" },
  spec: {
    replicas: 3,
    selector: { matchLabels: appLabel },
    template: {
      metadata: { labels: appLabel },
      spec: {
        containers: [
          {
            name: "hello-kubernetes",
            image: "paulbouwer/hello-kubernetes:1.5",
            ports: [ { containerPort: 8080 } ],
          },
        ],
      },
    },
  },
};

const service = {
  apiVersion: "v1",
  kind: "Service",
  metadata: { name: "hello-kubernetes" },
  spec: {
    type: "LoadBalancer",
    ports: [ { port: 80, targetPort: 8080 } ],
    selector: appLabel,
  }
};

// option 1: use a construct
new eks.KubernetesManifest(this, 'hello-kub', {
  cluster,
  manifest: [ deployment, service ],
});

// or, option2: use `addManifest`
cluster.addManifest('hello-kub', service, deployment);
```

Python:

```python
# cluster: eks.Cluster

app_label = {"app": "hello-kubernetes"}

deployment = {
    "api_version": "apps/v1",
    "kind": "Deployment",
    "metadata": {"name": "hello-kubernetes"},
    "spec": {
        "replicas": 3,
        "selector": {"match_labels": app_label},
        "template": {
            "metadata": {"labels": app_label},
            "spec": {
                "containers": [{
                    "name": "hello-kubernetes",
                    "image": "paulbouwer/hello-kubernetes:1.5",
                    "ports": [{"container_port": 8080}]
                }
                ]
            }
        }
    }
}

service = {
    "api_version": "v1",
    "kind": "Service",
    "metadata": {"name": "hello-kubernetes"},
    "spec": {
        "type": "LoadBalancer",
        "ports": [{"port": 80, "target_port": 8080}],
        "selector": app_label
    }
}

# option 1: use a construct
eks.KubernetesManifest(self, "hello-kub",
    cluster=cluster,
    manifest=[deployment, service]
)

# or, option2: use `addManifest`
cluster.add_manifest("hello-kub", service, deployment)
```

Java:

```java
Cluster cluster;

Map<String, String> appLabel = Map.of("app", "hello-kubernetes");

Map<String, Object> deployment = Map.of(
        "apiVersion", "apps/v1",
        "kind", "Deployment",
        "metadata", Map.of("name", "hello-kubernetes"),
        "spec", Map.of(
                "replicas", 3,
                "selector", Map.of("matchLabels", appLabel),
                "template", Map.of(
                        "metadata", Map.of("labels", appLabel),
                        "spec", Map.of(
                                "containers", List.of(Map.of(
                                        "name", "hello-kubernetes",
                                        "image", "paulbouwer/hello-kubernetes:1.5",
                                        "ports", List.of(Map.of("containerPort", 8080))))))));

Map<String, Object> service = Map.of(
        "apiVersion", "v1",
        "kind", "Service",
        "metadata", Map.of("name", "hello-kubernetes"),
        "spec", Map.of(
                "type", "LoadBalancer",
                "ports", List.of(Map.of("port", 80, "targetPort", 8080)),
                "selector", appLabel));

// option 1: use a construct
// option 1: use a construct
KubernetesManifest.Builder.create(this, "hello-kub")
        .cluster(cluster)
        .manifest(List.of(deployment, service))
        .build();

// or, option2: use `addManifest`
cluster.addManifest("hello-kub", service, deployment);
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;

IDictionary<string, string> appLabel = new Dictionary<string, string> { { "app", "hello-kubernetes" } };

IDictionary<string, object> deployment = new Dictionary<string, object> {
    { "apiVersion", "apps/v1" },
    { "kind", "Deployment" },
    { "metadata", new Dictionary<string, string> { { "name", "hello-kubernetes" } } },
    { "spec", new Dictionary<string, object> {
        { "replicas", 3 },
        { "selector", new Dictionary<string, IDictionary<string, string>> { { "matchLabels", appLabel } } },
        { "template", new Dictionary<string, IDictionary<string, IDictionary<string, string>>> {
            { "metadata", new Dictionary<string, IDictionary<string, string>> { { "labels", appLabel } } },
            { "spec", new Dictionary<string, IDictionary<string, object>[]> {
                { "containers", new [] { new Dictionary<string, object> {
                    { "name", "hello-kubernetes" },
                    { "image", "paulbouwer/hello-kubernetes:1.5" },
                    { "ports", new [] { new Dictionary<string, int> { { "containerPort", 8080 } } } }
                } } }
            } }
        } }
    } }
};

IDictionary<string, object> service = new Dictionary<string, object> {
    { "apiVersion", "v1" },
    { "kind", "Service" },
    { "metadata", new Dictionary<string, string> { { "name", "hello-kubernetes" } } },
    { "spec", new Dictionary<string, object> {
        { "type", "LoadBalancer" },
        { "ports", new [] { new Dictionary<string, int> { { "port", 80 }, { "targetPort", 8080 } } } },
        { "selector", appLabel }
    } }
};

// option 1: use a construct
// option 1: use a construct
new KubernetesManifest(this, "hello-kub", new KubernetesManifestProps {
    Cluster = cluster,
    Manifest = new [] { deployment, service }
});

// or, option2: use `addManifest`
cluster.AddManifest("hello-kub", service, deployment);
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster

appLabel := map[string]*string{
	"app": jsii.String("hello-kubernetes"),
}

deployment := map[string]interface{}{
	"apiVersion": jsii.String("apps/v1"),
	"kind": jsii.String("Deployment"),
	"metadata": map[string]*string{
		"name": jsii.String("hello-kubernetes"),
	},
	"spec": map[string]interface{}{
		"replicas": jsii.Number(3),
		"selector": map[string]map[string]*string{
			"matchLabels": appLabel,
		},
		"template": map[string]map[string]map[string]*string{
			"metadata": map[string]map[string]*string{
				"labels": appLabel,
			},
			"spec": map[string][]map[string]interface{}{
				"containers": []map[string]interface{}{
					map[string]interface{}{
						"name": jsii.String("hello-kubernetes"),
						"image": jsii.String("paulbouwer/hello-kubernetes:1.5"),
						"ports": []map[string]*f64{
							map[string]*f64{
								"containerPort": jsii.Number(8080),
							},
						},
					},
				},
			},
		},
	},
}

service := map[string]interface{}{
	"apiVersion": jsii.String("v1"),
	"kind": jsii.String("Service"),
	"metadata": map[string]*string{
		"name": jsii.String("hello-kubernetes"),
	},
	"spec": map[string]interface{}{
		"type": jsii.String("LoadBalancer"),
		"ports": []map[string]*f64{
			map[string]*f64{
				"port": jsii.Number(80),
				"targetPort": jsii.Number(8080),
			},
		},
		"selector": appLabel,
	},
}

// option 1: use a construct
// option 1: use a construct
eks.NewKubernetesManifest(this, jsii.String("hello-kub"), &KubernetesManifestProps{
	Cluster: Cluster,
	Manifest: []map[string]interface{}{
		deployment,
		service,
	},
})

// or, option2: use `addManifest`
cluster.addManifest(jsii.String("hello-kub"), service, deployment)
```

## Properties

- `cluster`: [ICluster](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_eks.ICluster.html) (required) — The EKS cluster to apply this manifest to.

  [disable-awslint:ref-via-interface]

- `ingressAlb`: boolean = false — Automatically detect `Ingress` resources in the manifest and annotate them so they are picked up by an ALB Ingress Controller.

- `ingressAlbScheme`: [AlbScheme](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_eks.AlbScheme.html) = AlbScheme.INTERNAL — Specify the ALB scheme that should be applied to `Ingress` resources.

  Only applicable if `ingressAlb` is set to `true`.

- `manifest`: { [key: string]: any }[] (required) — The manifest to apply.

  Consists of any number of child resources.

  When the resources are created/updated, this manifest will be applied to the
  cluster through `kubectl apply` and when the resources or the stack is
  deleted, the resources in the manifest will be deleted through `kubectl delete`.

  ```ts
  [{
    apiVersion: 'v1',
    kind: 'Pod',
    metadata: { name: 'mypod' },
    spec: {
      containers: [ { name: 'hello', image: 'paulbouwer/hello-kubernetes:1.5', ports: [ { containerPort: 8080 } ] } ]
    }
  }]
  ```

- `overwrite`: boolean = false — Overwrite any existing resources.

  If this is set, we will use `kubectl apply` instead of `kubectl create`
  when the resource is created. Otherwise, if there is already a resource
  in the cluster with the same name, the operation will fail.

- `prune`: boolean — When a resource is removed from a Kubernetes manifest, it no longer appears in the manifest, and there is no way to know that this resource needs to be deleted.

  **Default:** based on the prune option of the cluster, which is `true` unless otherwise specified.

  To address this, `kubectl apply` has a `--prune` option which will
  query the cluster for all resources with a specific label and will remove
  all the labeld resources that are not part of the applied manifest. If this
  option is disabled and a resource is removed, it will become "orphaned" and
  will not be deleted from the cluster.

  When this option is enabled (default), the construct will inject a label to
  all Kubernetes resources included in this manifest which will be used to
  prune resources when the manifest changes via `kubectl apply --prune`.

  The label name will be `aws.cdk.eks/prune-<ADDR>` where `<ADDR>` is the
  42-char unique address of this construct in the construct tree. Value is
  empty.

- `removalPolicy`: [RemovalPolicy](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html) = RemovalPolicy.DESTROY — The removal policy applied to the custom resource that manages the Kubernetes manifest.

  The removal policy controls what happens to the resource if it stops being managed by CloudFormation.
  This can happen in one of three situations:

  - The resource is removed from the template, so CloudFormation stops managing it
  - A change to the resource is made that requires it to be replaced, so CloudFormation stops managing it
  - The stack is deleted, so CloudFormation stops managing all resources in it

- `skipValidation`: boolean = false — A flag to signify if the manifest validation should be skipped.
