Created
March 10, 2020 13:28
-
-
Save eladb/df13e24da96417a4c46b43417b30b6d9 to your computer and use it in GitHub Desktop.
cdk8s + EKS = ❤️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as eks from '@aws-cdk/aws-eks'; | |
import * as iam from '@aws-cdk/aws-iam'; | |
import * as cdk8s from 'cdk8s'; | |
import { Construct, Stack, StackProps } from '@aws-cdk/core'; | |
import * as k8s from '../imports/k8s'; | |
export class TestClusterStack extends Stack { | |
constructor(scope: Construct, id: string, props?: StackProps) { | |
super(scope, id, props); | |
const role = new iam.Role(this, 'Admin', { | |
assumedBy: new iam.AccountRootPrincipal() | |
}); | |
const cluster = new eks.Cluster(this, 'TestCluster', { mastersRole: role }); | |
const chart = new MyChart(this, 'HelloChart'); | |
cluster.addResource('HelloChart', ...chart.toJson()); | |
} | |
} | |
class MyChart extends cdk8s.Chart { | |
constructor(scope: Construct, id: string) { | |
super(scope, id); | |
const selector = { app: 'hello-kubernetes' }; | |
new k8s.Service(this, 'service', { | |
spec: { | |
type: 'LoadBalancer', | |
ports: [ { port: 80, targetPort: k8s.IntOrString.fromNumber(8080) } ], | |
selector: selector | |
} | |
}); | |
new k8s.Deployment(this, 'deployment', { | |
spec: { | |
replicas: 3, | |
selector: { | |
matchLabels: selector | |
}, | |
template: { | |
metadata: { | |
labels: selector | |
}, | |
spec: { | |
containers: [ | |
{ name: 'app', image: 'paulbouwer/hello-kubernetes:1.7', ports: [ { containerPort: 8080 }]} | |
] | |
} | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment