This is a companion repository for the Hashicorp Deploy Applications with CDK for Terraform tutorial. The Cloud Development Kit for Terraform (CDKTF) allows you to manage Terraform configuration with code in your preferred programming language.
- Start a local Docker registry to store container images
docker run -d --restart always -p "127.0.0.1:5000:5000" --name local-registry registry:2
- use kind to create a kubernetes cluster running in Docker locally
kind create cluster --name=cdktf-app --config kind-config.yaml
- verify cluster by listing kind clusters
kind get clusters
- use kubectl to print out info about your cluster; context is kind- followed by your cluster name
kubectl cluster-info --context=kind-cdktf-app
- create kubeconfig file to allow access to kubernetes cluster
kubectl config view --raw --context kind-cdktf-app > kubeconfig.yaml
- attach your local Docker registry to your kind cluster
- Docker registry name is local-registry
- kind cluster network name is kind
- This command puts the local-registry on the kind network
- Another way of thinking of this is: the kind kubernetes cluster network has the docker registry attached to it
docker network connect kind local-registry
- configure your Kubernetes cluster to use the local registry
kubectl apply -f local-registry-configmap.yaml --kubeconfig kubeconfig.yaml
- build and push the container image to the local registry (frontend and backend)
cd frontend
yarn deploy
cd ../backend
yarn deploy
-
deploy cdktf app stacks separately (install the app dependencies first)
cd app
yarn
cdktf deploy app
cdktf deploy app-test
cdktf deploy [stack] # deploy stack
cdktf destroy [stack] # destroy stack
kubectl get deployments
kubectl get services
cdktf destroy app-test
>approve
cdktf destroy app
>approve
kind delete cluster --name=cdktf-app
docker stop local-registry
docker rm local-registry