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:


  1. Install VirtualBox
  2. Install Vagrant
  3. Make a copy of the ultral / terraform-example repository
  4. 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.


  1. Register https://cloud.google.com to get $ 300
  2. On the deployed VM, we do gcloud initand follow the instructions
    gcloud init
  3. According to the instructions, we get the key in the developer console and put it in /root/.gcloud/terraform.json on the virtual machine
  4. Create a cluster in cloud.google.com
    gcloud container clusters create gke-cluster
    gcloud container clusters list
  5. 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.
  6. 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".
  7. 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".
  8. Preparing variables in the image and likeness 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 well done.
    terraform output lb_ingress
  11. 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.


Also popular now: