KubernetesResource

class aws_cdk.aws_eks_legacy.KubernetesResource(scope, id, *, cluster, manifest)

Bases: Construct

(deprecated) Represents a resource within the Kubernetes system.

Alternatively, you can use cluster.addResource(resource[, resource, ...]) to define resources on this cluster.

Applies/deletes the resources using kubectl in sync with the resource.

Stability:

deprecated

ExampleMetadata:

infused

Example:

# 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.KubernetesResource(self, "hello-kub",
    cluster=cluster,
    manifest=[deployment, service]
)

# or, option2: use `addResource`
cluster.add_resource("hello-kub", service, deployment)
Parameters:
  • scope (Construct) –

  • id (str) –

  • cluster (Cluster) – (deprecated) The EKS cluster to apply this configuration to. [disable-awslint:ref-via-interface]

  • manifest (Sequence[Any]) – (deprecated) The resource manifest. Consists of any number of child resources. When the resource is created/updated, this manifest will be applied to the cluster through kubectl apply and when the resource or the stack is deleted, the manifest will be deleted through kubectl delete:: const manifest = { apiVersion: ‘v1’, kind: ‘Pod’, metadata: { name: ‘mypod’ }, spec: { containers: [ { name: ‘hello’, image: ‘paulbouwer/hello-kubernetes:1.5’, ports: [ { containerPort: 8080 } ] } ] } }

Stability:

deprecated

Methods

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

RESOURCE_TYPE = 'Custom::AWSCDK-EKS-KubernetesResource'
node

The construct tree node associated with this construct.

Static Methods

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters:

x (Any) –

Return type:

bool