cdk8s-image is a library that provides a CDK8s construct for building Docker images from a local Dockerfile and pushing them to a specified container registry, all within the context of a CDK8s application. This allows developers to define container images as part of their Kubernetes application infrastructure using familiar programming languages. The current stable version is `0.2.746`, with releases occurring frequently, often multiple times a month, indicating active development. Its key differentiator is the seamless integration of Docker image lifecycle management directly into the CDK8s synthesis process, eliminating the need for separate CI/CD steps for image building when defining Kubernetes resources.
npm install cdk8s-imageVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to build and push a local Docker image using the `Image` construct and then reference it in a Kubernetes `Deployment`.
Always pin to exact versions or thoroughly test when upgrading `cdk8s-image` within the same minor version. Refer to the GitHub changelog for specific changes.
Ensure Docker is running and properly configured (e.g., login to private registries) in the environment where `cdk8s synth` is executed. Verify network connectivity to your target container registry.
For production, use a fully qualified domain name (FQDN) for the registry that is accessible from your Kubernetes cluster and CI/CD environment. Ensure authentication is handled for private registries.
Double-check the `dir` path to ensure it correctly points to the directory containing your `Dockerfile`. Ensure the user executing `cdk8s synth` has read access to this directory.
Ensure your Docker daemon is running (`systemctl start docker` or `open --background /Applications/Docker.app`). Check the specified `dir` for a valid `Dockerfile` and review Docker build logs for specific errors.
Start your local Docker registry (`docker run -d -p 5000:5000 --restart always --name registry registry:2`) or ensure the specified registry is correct and accessible.
Install the package: `npm install cdk8s-image` or `yarn add cdk8s-image`. Ensure your `tsconfig.json` paths are correctly configured if using aliases.