Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cdk8s

Package Overview
Dependencies
Maintainers
1
Versions
1847
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cdk8s

This is the core library of Cloud Development Kit (CDK) for Kubernetes (cdk8s). cdk8s apps synthesize into standard Kubernetes manifests which can be applied to any Kubernetes cluster.

  • 2.69.33
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is cdk8s?

cdk8s (Cloud Development Kit for Kubernetes) is an open-source software development framework for defining Kubernetes applications and resources using familiar programming languages. It allows developers to use high-level constructs and abstractions to define Kubernetes manifests, making it easier to manage and deploy Kubernetes resources programmatically.

What are cdk8s's main functionalities?

Defining Kubernetes Manifests

This code sample demonstrates how to define a Kubernetes Deployment manifest using cdk8s. It creates a deployment with 3 replicas of an NGINX container.

const cdk8s = require('cdk8s');
const { App, Chart } = cdk8s;
const k8s = require('cdk8s-plus-17');

const app = new App();
const chart = new Chart(app, 'MyChart');

new k8s.Deployment(chart, 'MyDeployment', {
  spec: {
    replicas: 3,
    selector: {
      matchLabels: { app: 'my-app' }
    },
    template: {
      metadata: { labels: { app: 'my-app' } },
      spec: {
        containers: [{
          name: 'my-app',
          image: 'nginx'
        }]
      }
    }
  }
});

app.synth();

Using High-Level Constructs

This code sample shows how to use high-level constructs to define a Kubernetes Service manifest. It creates a LoadBalancer service that routes traffic to port 80 of the pods labeled with 'app: my-app'.

const cdk8s = require('cdk8s');
const { App, Chart } = cdk8s;
const k8s = require('cdk8s-plus-17');

const app = new App();
const chart = new Chart(app, 'MyChart');

new k8s.Service(chart, 'MyService', {
  spec: {
    type: 'LoadBalancer',
    ports: [{ port: 80, targetPort: 80 }],
    selector: { app: 'my-app' }
  }
});

app.synth();

Composing Charts

This code sample demonstrates how to compose multiple Kubernetes resources into a single chart. It defines both a Deployment and a Service within a custom chart class.

const cdk8s = require('cdk8s');
const { App, Chart } = cdk8s;
const k8s = require('cdk8s-plus-17');

class MyChart extends Chart {
  constructor(scope, id, props) {
    super(scope, id, props);

    new k8s.Deployment(this, 'MyDeployment', {
      spec: {
        replicas: 3,
        selector: {
          matchLabels: { app: 'my-app' }
        },
        template: {
          metadata: { labels: { app: 'my-app' } },
          spec: {
            containers: [{
              name: 'my-app',
              image: 'nginx'
            }]
          }
        }
      }
    });

    new k8s.Service(this, 'MyService', {
      spec: {
        type: 'LoadBalancer',
        ports: [{ port: 80, targetPort: 80 }],
        selector: { app: 'my-app' }
      }
    });
  }
}

const app = new App();
new MyChart(app, 'MyChart');
app.synth();

Other packages similar to cdk8s

Keywords

FAQs

Package last updated on 09 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc