diff --git a/cdk8s-guestbook/Dockerfile b/cdk8s-guestbook/Dockerfile new file mode 100644 index 0000000..9dd5876 --- /dev/null +++ b/cdk8s-guestbook/Dockerfile @@ -0,0 +1,17 @@ +FROM argoproj/argocd:latest + +USER root + +RUN apt-get update && \ + apt-get install -y \ + curl \ + python3-pip && \ + apt-get clean && \ + pip3 install pipenv + +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +RUN apt-get update && apt-get install -y yarn +RUN yarn global add npm cdk8s-cli + +USER argocd diff --git a/cdk8s-guestbook/Pipfile b/cdk8s-guestbook/Pipfile new file mode 100644 index 0000000..ff11097 --- /dev/null +++ b/cdk8s-guestbook/Pipfile @@ -0,0 +1,10 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[requires] +python_version = "3.7" + +[packages] +cdk8s = "*" diff --git a/cdk8s-guestbook/cdk8s.yaml b/cdk8s-guestbook/cdk8s.yaml new file mode 100644 index 0000000..8c50d9c --- /dev/null +++ b/cdk8s-guestbook/cdk8s.yaml @@ -0,0 +1,4 @@ +language: python +app: pipenv run ./main.py +imports: + - k8s diff --git a/cdk8s-guestbook/config.yml b/cdk8s-guestbook/config.yml new file mode 100644 index 0000000..2e3090c --- /dev/null +++ b/cdk8s-guestbook/config.yml @@ -0,0 +1,19 @@ +apiVersion: v1 +data: + configManagementPlugins: | + - name: cdk8s + init: + command: ["bash"] + args: ["-c", "pipenv install && cdk8s import -l python && cdk8s synth"] + generate: + command: ["bash"] + args: ["-c", "cat dist/*"] +kind: ConfigMap +metadata: + annotations: + labels: + app.kubernetes.io/name: argocd-cm + app.kubernetes.io/part-of: argocd + name: argocd-cm + namespace: argocd + selfLink: /api/v1/namespaces/argocd/configmaps/argocd-cm diff --git a/cdk8s-guestbook/main.py b/cdk8s-guestbook/main.py new file mode 100755 index 0000000..f9c3b5f --- /dev/null +++ b/cdk8s-guestbook/main.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +from constructs import Construct +from cdk8s import App, Chart + +from imports import k8s + + +class MyChart(Chart): + def __init__(self, scope: Construct, ns: str): + super().__init__(scope, ns) + + label = {"app": "guestbook-ui"} + + k8s.Service(self, 'service', + spec=k8s.ServiceSpec( + type='LoadBalancer', + ports=[k8s.ServicePort(port=80, target_port=k8s.IntOrString.from_number(80))], + selector=label)) + + k8s.Deployment(self, 'deployment', + spec=k8s.DeploymentSpec( + replicas=1, + selector=k8s.LabelSelector(match_labels=label), + template=k8s.PodTemplateSpec( + metadata=k8s.ObjectMeta(labels=label), + spec=k8s.PodSpec(containers=[ + k8s.Container( + name='guestbook-ui', + image='gcr.io/heptio-images/ks-guestbook-demo:0.2', + ports=[k8s.ContainerPort(container_port=80)])])))) + + +app = App() +MyChart(app, "cdk8s-guestbook") + +app.synth()