This is a demo repository for the Deploying public and private applications in Kubernetes blog post. All detailed information and explanations about this repository can be found in the blog post.
Make sure you have Devbox installed. This will manage all the dependencies of the project.
- Install dependencies of the project
devbox shell
- Export your Vultr credentials
export VULTR_API_KEY=BRYAAFNWHYEFY2ZHGTQSDZCHEA
- Create the Kubernetes cluster
cd infrastructure
tofu init
tofu apply
This will create the Kubernetes cluster for you using Opentofu.
- Create kube-config file
vultr-cli kubernetes config $(tofu output -raw cluster_id) | base64 -d >> ~/.kube/config
cd ..
- Install Kubernetes Reflector
devbox run reflector
- Create Vultr secrets and namespaces that will be used later
kubectl create namespace cert-manager
kubectl create namespace ingress-nginx
kubectl create secret generic vultr-credentials -n ingress-nginx --from-literal=apiKey=$VULTR_API_KEY
kubectl label secret vultr-credentials -n ingress-nginx created-manually=true
kubectl annotate secret vultr-credentials -n ingress-nginx reflector.v1.k8s.emberstack.com/reflection-auto-namespaces=kube-system,cert-manager
kubectl annotate secret vultr-credentials -n ingress-nginx reflector.v1.k8s.emberstack.com/reflection-allowed="true"
kubectl annotate secret vultr-credentials -n ingress-nginx reflector.v1.k8s.emberstack.com/reflection-auto-enabled="true"
- Install NGINX Ingress
devbox run nginx-ingress
- Install Cert Manager
devbox run cert-manager
It might take a while for the certificate to get healthy.
- Install External-DNS
devbox run external-dns
It might take a while for records to be created and propagated by the DNS provider.
- Deploy public application
devbox run public-app
Make sure you can access the public application using your browser.
- Deploy private application
devbox run private-app
The private app will be accessible only within the Kubernetes network. You can test this by running:
kubectl run curl --image=nginx:alpine
kubectl exec -it curl -- curl https://private-app.demosfelipetrindade.top