In this article, I’ll demonstrate an implementation of building a K8s stack in GCP using gcloud command line, terraform and kubectl. The application was made using Python. Every process will be executed in Docker.

The source code is available on Github.

Application

Thi app runs commands using gcloud, terraform and kubectl command lines. The sequence of executions is:

  1. Configure gcloud: Configures the GCP project to authenticate using the CREDENTIALS.json file, enabling Computing and Containers features.
  2. Initialize and run Terraform scripts: Apply the infraestructure of the Terraform files at GCP.
  3. Apply K8s files: Obtain gcloud credentials and use the kubectl command line to set up all services and resources that are configured in the .yaml files.

Terraform scripts

In the Terraform scripts, the simplest possible infrastructure was created to build a K8s environment. They contain the services:

  • Virtual private network (VPC).
  • Subnetwork.
  • Cluster K8s.
  • Cluster K8s node-pool.

The K8s cluster was built using only one node and e2-medium instance, using the K8s managed services from GCP.

#python #kubernetes #gcp #terraform #k8s

Docker image to build K8s stack in GCP cloud
1.20 GEEK