How to deploy an application on GKE private cluster with terraform?

1/17/2020

****I have made a bastion host VM(to be used as the master authorized network in private cluster) and a private cluster with Terraform which works fine.**** Now to deploy an application on the private cluster manually what we do is SSH into that bastion host VM first and then connect to the private cluster and then run the kubectl apply (deploy command) to deploy so how we can do this deployment procedure with Terraform script in GCP? Can anyone please help as I couldn't find the right example for doing this in GCP?

-- Yash Saini
google-cloud-platform
google-kubernetes-engine
terraform
terraform-provider-gcp

1 Answer

1/17/2020

Instead of ssh your master machine, you can - for example - just use Ansible. First you need to configure Ansible to access the machine. Then you can run your Ansible scripts which contain the kubectl commands for deployment. Preferably, you should use multiple Ansible roles to split your services deployment, then you can manage everything with a main Ansible Playbook. In addition, Ansible scripts can be hosted and integrated into a CI-CD server / tool like Gitlab CI or Jenkins and at the end of the day, you deploy your services on Kubernetes via your CI CD pipeline.

-- Aymen Segni
Source: StackOverflow