A GitOps based Anthos Multi Cloud installer framework.
Note: This is not an officially supported Google product.
- Provide starter scripts to install Anthos components with minimal manual steps.
- Use CFT Terraform modules that follow GCP best practices.
- Adding/modifying/removing Anthos/GCP components should be painless.
- Use of small modules so each one can be deployed and debugged independently
- GitOps enabled.
-
A Regional GKE Cluster on GCP in a dedicated VPC with Workload Identity, GKE Connect, Anthos Config Management (ACM) and Anthos Service Mesh (ACM) enabled.
-
An EKS Cluster on AWS in a dedicated VPC with GKE Connect and Anthos Config Management (ACM) enabled. Also creates a Kubernetes Service Account to use to login to the GCP console.
The quickest way to get an environment without installing any tools except git and gcloud is to use CloudBuild. See README-CloudBuild.md for details.
Install gcloud, Terraform, Terragrunt, awscli (if EKS required). Check the pre-requisites
# Clone the repo
git clone https://github.com/GoogleCloudPlatform/simple-anthos-installer
cd simple-anthos-installer
# Make sure authenticate with Application default login as this required for the google provider. See https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#authentication
gcloud auth application-default login # Mandatory
# Setup Project Env variables
export PROJECT_ID="<GCP_PROJECTID>" # Mandatory
gcloud config set core/project ${PROJECT_ID} # Mandatory
export GCP_REGION="gcp-region" # Optional, Defaults to us-east1
export GCP_AZS="az-1,az-2" # Optional. Defaults to us-east1-b,us-east1-c,us-east1-d
# Install kpt tool required for ASM install
sudo apt-get install google-cloud-sdk-kpt
# Specify the ACM repo to use. You can clone this one https://github.com/GoogleCloudPlatform/csp-config-management
export ACM_REPO="git@github.com:your-git-repo/csp-config-management.git" # Mandatory if using ACM
# Create the GKE Cluster with Workload Identity, GKE Connect(Hub), ACM and ASM enabled.
cd terragrunt/gke-gcp
terragrunt run-all apply --terragrunt-non-interactive
# Setup AWS credentials
export AWS_ACCESS_KEY_ID="aws-secret-key-id" # Mandatory
export AWS_SECRET_ACCESS_KEY="aws-secret-key" # Mandatory
export AWS_REGION="aws-region" # Optional. Defaults to us-east-1
# Create the EKS Cluster connected with GKE Connect(Hub) and ACM enabled.
cd terragrunt/eks-aws
terragrunt run-all apply --terragrunt-non-interactive
This will create 2 clusters named gke-dev-01
and eks-dev-01
in GKE and EKS respectively connected to GKE Hub.
- A Simple Anthos Installer
- β What can it Install?
- π Quickest Quickstart
- π€ Quickstart (tested on Linux)
- Detailed Instructions
- Pre-requisites
- Detailed Usage
- Customization and Extending
- Development and Testing
- Known Issues
- Contributing
- References
- Related Projects
- Licence
- Terraform 0.13.x
- Terragrunt 0.28.x
- gcloud
- awscli
- gcloud installed and configured with a GCP project.
export PROJECT_ID="<GCP_PROJECTID>"
gcloud config set core/project ${PROJECT_ID}
- kpt installed using
sudo apt-get install google-cloud-sdk-kpt
see this for more details. You may need to install the other tools manually depending on how gcloud was installed.
- Following APIs are Enabled:
- Compute
- Cloud Build
- Kubernetes
- Anthos
- Secrets Manager (to store AWS credentials)
By default it uses the reference repo git@github.com:GoogleCloudPlatform/csp-config-management.git
To change this to use your own repo, clone the above repo and modify the sync_repo
variable in the files gke-gcp/us-central1/dev/5_acm/terragrunt.hcl and eks-aws/us-east-1/dev/5_acm/terragrunt.hcl to point to your repo.
From the root git folder
cd terragrunt/gke-gcp
terragrunt run-all apply --terragrunt-non-interactive
Go get some β and if all goes well, in about 20 minutes, you should see this on the Anthos console in the Clusters view:
You will need to configure the cluster's ACM SSH public key on your git config management repo you created earlier. The install script outputs a value git_creds_public
which is the public key to use with you git provider.
Once you have updated the SSH public key successfully, in the Anthos Config Management screen, you should see the following:
You will have to enable sidecar injection into the namespaces you want by following the directions here: https://cloud.google.com/service-mesh/docs/scripted-install/gke-install#deploying_and_redeploying_workloads
# Setup AWS credentials
export AWS_ACCESS_KEY_ID="aws-secret-key-id"
export AWS_SECRET_ACCESS_KEY="aws-secret-key"
# Create the EKS Cluster connected with GKE Connect(Hub) and ACM enabled.
cd terragrunt/eks-aws
terragrunt run-all apply --terragrunt-non-interactive
In order to see the EKS cluster details in the Anthos Dashbaord, you have to Login to the Cluster using a KSA token.
Go to the Cloud Build output for the EKS Hub module and look for the output value for ksa_token
. Use this token to Login to the GCP console from the Kubernetes Clusters page.
Follow the steps from GKE above to enable ACM
Now you have a 2 clusters connected to an envrion (your GCP project) with ACM enabled.
# From terragrunt/eks-aws or terragrunt/gke-gcp directory
cd terragrunt/eks-aws
terragrunt run-all destroy --terragrunt-non-interactive --terragrunt-ignore-dependency-errors
The above cleanup will fail deleting the vpc if your project adds additional firewall rules that this script did not create which will prevent the VPC from being deleted. Easier way would be to use a dedicated project and delete the project when you are finished with it.
Terragrunt is used to call the CFT Terraform modules as it simplifies dependency management and makes use of DRY pattern.
This project creates a dev environment
The terragrunt/gke-gcp
directory is structured as follows:
βββ account.hcl
βββ us-east1
βββ dev
β βββ 0_activate-apis
β β βββ terragrunt.hcl
β βββ 1_vpc
β β βββ terragrunt.hcl
β βββ 2_gke
β β βββ terragrunt.hcl
β βββ 3_hub
β β βββ terragrunt.hcl
β βββ 4_acm
β β βββ terragrunt.hcl
β βββ 5_asm
β β βββ terragrunt.hcl
β βββ env.hcl
βββ region.hcl
It is organized by region (us-east1 in this case) and under that an environment (dev).
account.hcl
: contains GCP project detailsregion.hcl
: contains GCP region and AZ detailsenv.hcl
: environment name set todev
by default
These .hcl
provide sensible defaults which can be overriden using environment variables.
The numbering scheme for the directories is a best practice to document the order of deployment.
- Change
region
variable in the region.hcl - Rename the directory
us-central1
to your desired region. This has no effect on the code. This is for purely documenting your code to reflect the region.
- Change
environment_name
variable in the env.hcl - Copy the directory
dev
and rename it to your desired environment name. Reanming the directory has no effect on the code. This is for purely documenting your code to reflect the environment. It is best practice to name the directories (region and environment) to the same as the one in the.hcl
files.
The terragrunt/aws-eks
directory is structured as similarly:
βββ account.hcl
βββ us-east-1
βββ dev
β βββ 1_vpc
β β βββ terragrunt.hcl
β βββ 2_eks
β β βββ terragrunt.hcl
β βββ 3_hub
β β βββ terragrunt.hcl
β βββ 4_hub_login
β β βββ terragrunt.hcl
β βββ 5_acm
β β βββ terragrunt.hcl
β βββ env.hcl
βββ region.hcl
The Terraform state is stored in GCS bucket with the naming convention terraform-state-dev-$PROJECT_ID-$REGION
. The directory structure will match the directory structure above.
From the gke-gcp
or eks-aws
directory run:
terragrunt run-all validate
A terragrunt plan
can be done but it needs to be done separately in each numbered folder since there are dependencies in the some of the modules that needs to exist for a plan
command to work.
You can deploy all the infrastructure for a specific cloud provider or one module at a time.
From a numbered directory (1_xx)
or its parent, run:
terragrunt run-all apply --terragrunt-non-interactive
- Clean Upgrade and Uninstall of ASM is not supported as the asm install scripts do not support this yet. See GoogleCloudPlatform/anthos-service-mesh-packages#480
- Install of ASM is not supported for non GKE clusters.
- There are some Cloud Build scripts, you read the instructions here
Bug reports and feedback welcome. Please see CONTRIBUTING.md
Videos:
- Automated, modularized and versioned infrastructure with Terraform and Terragrunt
- 5 Lessons Learned From Writing Over 300,000 Lines of Infrastructure Code
Apache 2.0