0.0.316 • Published 19 hours ago

cdk8s-aws-cdk v0.0.316

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
19 hours ago

cdk8s-aws-cdk

AWS CDK Adapter for cdk8s allows you to define AWS CDK constructs within a cdk8s application. The AWS resources will be provisioned using the AWS Controllers for Kubernetes.

DO NOT USE THIS IN PRODUCTION

This project is in very early alpha stages of development and is subject to frequent breaking changes.

Pre-requisites

In you Kubernetes cluster, install the appropriate ACK controllers, depending on which resources you want to provision.

Getting Started

Install the adapter and the AWS CDK in your cdk8s project.

npm install cdk8s-aws-cdk aws-cdk-lib

The adapter provides a special Chart, that allows defining AWS CDK resources. You must extend this chart, in place of the normal cdk8s.Chart object.

import * as awscdkadapter from 'cdk8s-aws-cdk'
import * as k from 'cdk8s';
import * as kplus from 'cdk8s-plus-24';
import { aws_s3 as s3 } from 'aws-cdk-lib';

export class MyChart extends awscdkadapter.Chart {

  constructor(scope: Construct, id: string, props: k.ChartProps = {}) {
    super(scope, id, props);

    // define an s3 bucket with aws-cdk
    new s3.Bucket(this, 'Bucket');

    // define a kubernetes deployment with cdk8s+
    new kplus.Deployment(this, 'Deployment', {
      containers: [{ image: 'image' }],
    });

  }

}

Synthesizing this chart will produce:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: s3sample-deployment-c828e7a5
spec:
  minReadySeconds: 0
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      cdk8s.io/metadata.addr: S3Sample-Deployment-c8c2c08d
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        cdk8s.io/metadata.addr: S3Sample-Deployment-c8c2c08d
    spec:
      automountServiceAccountToken: true
      containers:
        - image: image
          imagePullPolicy: Always
          name: main
          securityContext:
            privileged: false
            readOnlyRootFilesystem: false
            runAsNonRoot: false
      dnsPolicy: ClusterFirst
      securityContext:
        fsGroupChangePolicy: Always
        runAsNonRoot: false
      setHostnameAsFQDN: false
---
apiVersion: s3.services.k8s.aws/v1alpha1
kind: Bucket
metadata:
  name: s3sample-bucket83908e77-c80d1127
spec:
  name: s3sample-bucket83908e77-c80d1127

You can then apply this manifest to the cluster by any means.

Limitations

The are quite a few limitations at the moment.

Resource Coverage

There are two layers of resource coverage that are involved in the process:

ACK Resources

The adapter maps every AWS CDK resource to its corresponding ACK resource. This means resources that aren't currently supported by ACK cannot be defined.

Adapter Mappers

For resources that are supported by ACK, this adapter contains mappers that can do the translation. Not all supported resources have been mapped yet, the built-in mapped resources are:

  • EC2 Security Group
  • IAM Policy
  • IAM Role
  • Lambda Function
  • RDS DB Instance
  • RDS Subnet Group
  • S3 Bucket

If your application contains additional resources, that are supported by ACK but haven't been mapped by the adapter, you can register customer mappers:

First you implement a custom mapper:

import * as awscdkadapter from 'cdk8s-aws-cdk'

export class KmsKeyMapper extends awscdkadapter.CloudFormationResourceMapper {

  /**
   * @see CloudFormationResourceMapper.type
   */
  public readonly type: string = 'AWS::KMS::Key';

  // implement the additional required methods and properties
  ...
}

Then you register it:

import * as awscdkadapter from 'cdk8s-aws-cdk'
import * as k from 'cdk8s';
import { aws_kms as kms } from 'aws-cdk-lib';

export class MyChart extends awscdkadapter.Chart {

  constructor(scope: Construct, id: string, props: k.ChartProps = {}) {
    super(scope, id, props);

    this.registerMapper(new KmsKeyMapper(this))

    // now you can define a kms key
    new kms.Key(this, 'Key');

  }

}

Attributes

CDK Tokens that represent CloudFormation attributes (i.e Fn::GetAttr) can be used as Kubernetes environment variables when defining containers, but they cannot be used for anything else.

For example, you can pass an attribute to a container like so:

const dbInstance = new rds.DatabaseInstance(...);
const container = deployment.addContainer(...);

container.env.addVariable('DB_ADDRESS', kplus.EnvValue.fromValue(dbInstance.dbInstanceEndpointAddress))

But you cannot pass the same attribute to, for example, lambda function environment variables:

const dbInstance = new rds.DatabaseInstance(...);
const func = new lambda.Function(...);

func.addEnvironment('DB_ADDRESS', dbInstance.dbInstanceEndpointAddress);

This is because attribute mapping is implemented by exporting them using ACK Field Exports. These field exports can only be imported in a select number of resources, and currently the adapter only supports kubernetes environment variables.

Assets

AWS CDK assets are currently not supported.

Examples

0.0.316

19 hours ago

0.0.315

2 days ago

0.0.314

3 days ago

0.0.313

4 days ago

0.0.312

10 days ago

0.0.311

11 days ago

0.0.310

17 days ago

0.0.309

1 month ago

0.0.308

1 month ago

0.0.307

1 month ago

0.0.303

2 months ago

0.0.302

2 months ago

0.0.301

2 months ago

0.0.300

2 months ago

0.0.299

2 months ago

0.0.298

2 months ago

0.0.296

3 months ago

0.0.297

3 months ago

0.0.295

3 months ago

0.0.294

3 months ago

0.0.293

3 months ago

0.0.292

3 months ago

0.0.291

3 months ago

0.0.290

3 months ago

0.0.289

3 months ago

0.0.288

3 months ago

0.0.287

3 months ago

0.0.286

3 months ago

0.0.285

3 months ago

0.0.284

3 months ago

0.0.283

3 months ago

0.0.282

3 months ago

0.0.281

3 months ago

0.0.279

3 months ago

0.0.280

3 months ago

0.0.278

3 months ago

0.0.277

3 months ago

0.0.276

3 months ago

0.0.275

3 months ago

0.0.274

4 months ago

0.0.273

4 months ago

0.0.272

4 months ago

0.0.271

4 months ago

0.0.270

4 months ago

0.0.269

4 months ago

0.0.268

4 months ago

0.0.267

4 months ago

0.0.266

4 months ago

0.0.265

4 months ago

0.0.264

4 months ago

0.0.263

4 months ago

0.0.262

4 months ago

0.0.261

5 months ago

0.0.260

5 months ago

0.0.259

5 months ago

0.0.205

9 months ago

0.0.204

9 months ago

0.0.203

9 months ago

0.0.202

9 months ago

0.0.209

8 months ago

0.0.208

8 months ago

0.0.207

8 months ago

0.0.206

8 months ago

0.0.201

9 months ago

0.0.200

9 months ago

0.0.216

8 months ago

0.0.215

8 months ago

0.0.214

8 months ago

0.0.213

8 months ago

0.0.219

8 months ago

0.0.218

8 months ago

0.0.217

8 months ago

0.0.212

8 months ago

0.0.211

8 months ago

0.0.210

8 months ago

0.0.227

7 months ago

0.0.226

7 months ago

0.0.225

7 months ago

0.0.224

7 months ago

0.0.229

7 months ago

0.0.228

7 months ago

0.0.223

7 months ago

0.0.222

7 months ago

0.0.221

8 months ago

0.0.220

8 months ago

0.0.197

9 months ago

0.0.196

9 months ago

0.0.195

9 months ago

0.0.194

9 months ago

0.0.199

9 months ago

0.0.198

9 months ago

0.0.193

9 months ago

0.0.192

9 months ago

0.0.191

9 months ago

0.0.190

9 months ago

0.0.159

10 months ago

0.0.158

10 months ago

0.0.153

10 months ago

0.0.152

10 months ago

0.0.151

10 months ago

0.0.150

10 months ago

0.0.157

10 months ago

0.0.156

10 months ago

0.0.155

10 months ago

0.0.154

10 months ago

0.0.169

10 months ago

0.0.164

10 months ago

0.0.163

10 months ago

0.0.162

10 months ago

0.0.161

10 months ago

0.0.168

10 months ago

0.0.167

10 months ago

0.0.166

10 months ago

0.0.165

10 months ago

0.0.160

10 months ago

0.0.175

9 months ago

0.0.174

9 months ago

0.0.173

9 months ago

0.0.172

9 months ago

0.0.179

9 months ago

0.0.178

9 months ago

0.0.177

9 months ago

0.0.176

9 months ago

0.0.171

9 months ago

0.0.170

10 months ago

0.0.186

9 months ago

0.0.185

9 months ago

0.0.184

9 months ago

0.0.183

9 months ago

0.0.189

9 months ago

0.0.188

9 months ago

0.0.187

9 months ago

0.0.182

9 months ago

0.0.181

9 months ago

0.0.180

9 months ago

0.0.238

7 months ago

0.0.237

7 months ago

0.0.236

7 months ago

0.0.235

7 months ago

0.0.239

6 months ago

0.0.230

7 months ago

0.0.234

7 months ago

0.0.233

7 months ago

0.0.232

7 months ago

0.0.231

7 months ago

0.0.249

6 months ago

0.0.248

6 months ago

0.0.247

6 months ago

0.0.246

6 months ago

0.0.241

6 months ago

0.0.240

6 months ago

0.0.245

6 months ago

0.0.244

6 months ago

0.0.243

6 months ago

0.0.242

6 months ago

0.0.258

5 months ago

0.0.257

6 months ago

0.0.252

6 months ago

0.0.251

6 months ago

0.0.250

6 months ago

0.0.256

6 months ago

0.0.255

6 months ago

0.0.254

6 months ago

0.0.253

6 months ago

0.0.149

10 months ago

0.0.148

10 months ago

0.0.147

10 months ago

0.0.146

10 months ago

0.0.145

10 months ago

0.0.139

10 months ago

0.0.138

10 months ago

0.0.137

10 months ago

0.0.136

10 months ago

0.0.135

10 months ago

0.0.134

10 months ago

0.0.142

10 months ago

0.0.141

10 months ago

0.0.140

10 months ago

0.0.144

10 months ago

0.0.143

10 months ago

0.0.128

11 months ago

0.0.127

11 months ago

0.0.129

11 months ago

0.0.131

11 months ago

0.0.130

11 months ago

0.0.133

11 months ago

0.0.132

11 months ago

0.0.119

11 months ago

0.0.126

11 months ago

0.0.125

11 months ago

0.0.120

11 months ago

0.0.124

11 months ago

0.0.123

11 months ago

0.0.122

11 months ago

0.0.121

11 months ago

0.0.106

11 months ago

0.0.105

11 months ago

0.0.104

11 months ago

0.0.103

11 months ago

0.0.109

11 months ago

0.0.108

11 months ago

0.0.107

11 months ago

0.0.102

11 months ago

0.0.101

11 months ago

0.0.117

11 months ago

0.0.116

11 months ago

0.0.115

11 months ago

0.0.114

11 months ago

0.0.118

11 months ago

0.0.113

11 months ago

0.0.112

11 months ago

0.0.111

11 months ago

0.0.110

11 months ago

0.0.84

12 months ago

0.0.85

12 months ago

0.0.86

12 months ago

0.0.87

12 months ago

0.0.88

12 months ago

0.0.89

12 months ago

0.0.80

12 months ago

0.0.81

12 months ago

0.0.82

12 months ago

0.0.83

12 months ago

0.0.73

12 months ago

0.0.74

12 months ago

0.0.75

12 months ago

0.0.76

12 months ago

0.0.77

12 months ago

0.0.78

12 months ago

0.0.79

12 months ago

0.0.100

11 months ago

0.0.95

11 months ago

0.0.96

11 months ago

0.0.97

11 months ago

0.0.98

11 months ago

0.0.99

11 months ago

0.0.90

12 months ago

0.0.91

12 months ago

0.0.92

12 months ago

0.0.93

11 months ago

0.0.94

11 months ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.47

1 year ago

0.0.70

1 year ago

0.0.71

1 year ago

0.0.72

1 year ago

0.0.62

1 year ago

0.0.63

1 year ago

0.0.64

1 year ago

0.0.65

1 year ago

0.0.66

1 year ago

0.0.67

1 year ago

0.0.68

1 year ago

0.0.69

1 year ago

0.0.60

1 year ago

0.0.61

1 year ago

0.0.59

1 year ago

0.0.51

1 year ago

0.0.52

1 year ago

0.0.53

1 year ago

0.0.54

1 year ago

0.0.55

1 year ago

0.0.56

1 year ago

0.0.57

1 year ago

0.0.58

1 year ago

0.0.50

1 year ago

0.0.48

1 year ago

0.0.49

1 year ago

0.0.40

1 year ago

0.0.41

1 year ago

0.0.42

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.37

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.0.32

1 year ago

0.0.33

1 year ago

0.0.34

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.14

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

2 years ago