Skip to content

Build and deploy on k3d with cdk8s.io by using a python script

Notifications You must be signed in to change notification settings

atrakic/k3d-cdk8s-demo

Repository files navigation

Hello cdk8s (in Python!)

cdk8s-k3d

This example application deploys hello-kubernetes using cdk8s.

You can apply this example into your own k8s cluster with these step by step commands:

Import

$ pipenv install
$ cdk8s import --language python

Synthesize the CDK into a k8s template

$ cdk8s synth

Apply the k8s template to your cluster

$ kubectl apply -f dist/hello.k8s.yaml

Demo

After apply step, hello-svc can be reached at localhost:8080:

$ make status
NAME                             TYPE           CLUSTER-IP    EXTERNAL-IP                   PORT(S)        AGE     SELECTOR
service/kubernetes               ClusterIP      10.43.0.1     <none>                        443/TCP        2m40s   <none>
service/hello-service-c8685ad9   LoadBalancer   10.43.174.4   192.168.240.2,192.168.240.3   80:32694/TCP   2m8s    app=hello

NAME                                             READY   STATUS    RESTARTS   AGE    IP          NODE                       NOMINATED NODE   READINESS GATES
pod/svclb-hello-service-c8685ad9-mvrxw           1/1     Running   0          2m8s   10.42.1.4   k3d-k3s-default-agent-0    <none>           <none>
pod/svclb-hello-service-c8685ad9-kg2pk           1/1     Running   0          2m8s   10.42.0.5   k3d-k3s-default-server-0   <none>           <none>
pod/hello-deployment-c8aab50d-586bd8cf75-rs827   1/1     Running   0          2m8s   10.42.0.3   k3d-k3s-default-server-0   <none>           <none>
pod/hello-deployment-c8aab50d-586bd8cf75-6d967   1/1     Running   0          2m8s   10.42.0.4   k3d-k3s-default-server-0   <none>           <none>

For more details see: gh-ction demo, Source gh-action, K3d config

Credits

https://github.com/cdk8s-team/cdk8s/tree/master/examples/python/web-service