There is no time to explain! or how to make friends terraform with minikube and kubernetes
- Tutorial
How to start using terraform by deploying the application locally on top of minikube and then running it on top of kubernetes in cloud.google.com
Minikube
To get started, configure minikube and use our terraform to deploy our application, for this I have already prepared a project. It remains only:
- Install VirtualBox
- Install Vagrant
- Make a copy of the ultral / terraform-example repository
- Make
vagrant up
At the output, we have a virtual machine at 192.168.56.123 with the username / password vagrant / vagrant and / or your public key for root and vagrant users.
Google cloud
Everything becomes more interesting here, we will connect to cloud.google.com and launch our application there.
- Register https://cloud.google.com to get $ 300
- On the deployed VM, we do
gcloud init
and follow the instructionsgcloud init
- According to the instructions, we get the key in the developer console and put it in /root/.gcloud/terraform.json on the virtual machine
- Create a cluster in cloud.google.com
gcloud container clusters create gke-cluster gcloud container clusters list
- We receive turnouts / passwords for connecting kubectl to cloud.google.com
[root@terraform-adm terraform]# gcloud container clusters get-credentials gke-cluster Fetching cluster endpoint and auth data. kubeconfig entry generated for gke-cluster.
- Switch kubectl context
[root@terraform-adm terraform]# kubectl config use-context gke_tutorial-project-183818_europe-west1-d_gke-cluster Switched to context "gke_tutorial-project-183818_europe-west1-d_gke-cluster".
- Rename the kubectl context (it is specified in terraform)
[root@terraform-adm terraform]# kubectl config rename-context gke_tutorial-project-183818_europe-west1-d_gke-cluster gke_tutorial Context "gke_tutorial-project-183818_europe-west1-d_gke-cluster" was renamed to "gke_tutorial".
- Preparing variables in the image and likeness for terraform
cp /vagrant/terraform/terraform.tfvars.example /vagrant/terraform/terraform.tfvars vi /vagrant/terraform/terraform.tfvars
- Prepare and apply terraform
terraform workspace new prod terraform init terraform plan terraform apply
- Now you can get the address of our application and go through the browser. We are well done.
terraform output lb_ingress
- We clean the tails behind us
terraform destroy gcloud container clusters delete gke-cluster
Conclusion
Terraform was not so scary. Terraform opens up the space for structuring and maintaining environments in an identical state.