📜 ⬆️ ⬇️

There is no time to explain! or how to make friends terraform with minikube and kubernetes


How to start using terraform by deploying the application locally on top of the minikube , and then run it on top of kubernetes in cloud.google.com


Minikube


To begin with, let's configure minikube and with the help of terraform we will deploy our application, for this we have already prepared a project. It only remains:


  1. Install VirtualBox
  2. Install Vagrant
  3. Make a copy of the ultral / terraform-example repository
  4. To make
    vagrant up 

At the output, we have a virtual machine at 192.168.56.123 with the vagrant / vagrant login / password and / or your public key for root and vagrant users.


Google cloud


Here everything becomes more interesting, we will connect to cloud.google.com and launch our application there.


  1. Sign up https://cloud.google.com to get $ 300
  2. On a deployed VM, we do gcloud init and follow the instructions.
     gcloud init 
  3. According to the instructions, we get the key in the developer console and add it to /root/.gcloud/terraform.json on the virtual machine
  4. Creating a cluster in cloud.google.com
     gcloud container clusters create gke-cluster gcloud container clusters list 
  5. We get attendances / 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. 
  6. Switch context kubectl
     [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". 
  7. Rename the context kubectl (it is listed in our 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". 
  8. Preparing variables in the image for terraform
     cp /vagrant/terraform/terraform.tfvars.example /vagrant/terraform/terraform.tfvars vi /vagrant/terraform/terraform.tfvars 
  9. Prepare and apply terraform
     terraform workspace new prod terraform init terraform plan terraform apply 
  10. Now you can get the address of our application and go through the browser. We are great.
     terraform output lb_ingress 
  11. We clean the tails
     terraform destroy gcloud container clusters delete gke-cluster 

Conclusion


Terraform was not so scary. Terraform opens the way for structuring and maintaining environments in an identical state.


')

Source: https://habr.com/ru/post/340884/


All Articles