Creating & Deploying own image to Google Kubernetes Engine(GKE) using Terraform(Part 2)

For Part 1, Click Here……

Overview

  • How to create a simple Docker container image using Dockerfile(Completed in Part 1)
  • General use of Docker Container registry DockerHub(Completed in Part 1)
  • Deployment of own docker image to Kubernetes using YAML file(Completed in Part 1)
  • Google Kubernetes Engine Cluster Creation using Terraform Script
  • How to deploy our own image deployment file with the help of Kubernetes configuration file(YAML)
  • Some optional deployment using terraform like Google Virtual Private Cloud(VPC) Network & more.

Step 4: Google Kubernetes Engine Cluster Creation using Terraform Script

  • Firstly create a terraform script file which defines your cloud provider like google cloud, AWS & other cloud providers, which some optional version specifications.
nano provider.tf
  • Next, we create a variable file for our zone & project ID definition.
nano terraform.tfvars
  • Now, we’re going to create a file for your cluster creation.
nano cluster.tf
  • Now create one more file, for displaying the information about the cluster with some specifications.
nano output.tf
terraform init
terraform plan
terraform apply

Step 5: How to deploy our own image deployment file with the help of Kubernetes configuration file(YAML)

mkdir deploymentcd deployment
nano cluster-deployment.tf
  • Here terraform remote state section fetches all details about your existing cluster, we have created previously, so you have to give the path to the previously terraform initialized directory, where you found one folder created by terraform called terraform.tfstate from where it takes all details about your cluster. To edit the path accordingly.
  • You can see that deployment & services section is looking the same as our Part 1 Kubernetes configuration file (YAML). So comparing both changes the file & it is very easy to create this script if you already have a Kubernetes configuration file that’s why I took this in Part 1.
terraform initterraform planterraform apply
terraform destroy

Optional: Some optional deployment using terraform like Google Virtual Private Cloud(VPC) Network & more.

terraform validate

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store