Skip to content

Gcp project creator using Terraform, Kubernetes, Ansible, Jenkins, Helm, Docker

Notifications You must be signed in to change notification settings

Miou-zora/Whanos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prerequisites

First of all, you need to have a google account and a google cloud project. If you don't have one, you can create one here. You also have to enable billing for your project. You can find more information here.

Then, you need to create a service account name "terraform@$project_id.iam.gserviceaccount.com" with the following roles:

Alt text

You can find more information here.

Finally, you need to create a key for this service account and download it in json format. You can find more information here. This key will be used by terraform to create the infrastructure, so keep it safe.

On gcp, you also need to enable the following APIs:

  • Artifact Registry API
  • Compute Engine API
  • Identity and Access Management (IAM) API (you have already done it if you have created the service account)
  • Kubernetes Engine API

Deployement

Terraform

First, you need to install terraform. You can find the installation instructions here.

Then, you need to create a file named variables.tfvars with the following content (you can find values on GCP):

project_id = "your_project_id"
project_region = "your_project_region"
credentials_file = "path_to_your_credentials_file"
machine_type="your machine type"
machine_zone="your machine zone"

For kubernetes, you need to copy this file in kubernetes/terraform directory.

Put your credentials file in the terraform directory.

Finally, you can run the following commands (in the terraform directory):

terraform init
terraform apply --var-file="variables.tfvars"

Now, you have your compute engine instance and your kubernetes cluster. You can connect to the compute engine instance with the following command (optional):

gcloud compute ssh --project $project_id --zone $machine_zone jenkins-server

Ansible

First, you need to install ansible. You can find the installation instructions here.

Then, you need to create a file named inventory.yml with the following content:

all:
  children:
    jenkins:
      hosts:
        jenkins-1:
          ansible_user: "your_compute_engine_instance_ssh_user"
          ansible_host: "your_compute_engine_instance_ip"

Put it in the ansible directory.

Create user admin password:

ansible-vault encrypt_string 'admin_password' --name 'USER_ADMIN_PASSWORD' (change 'admin_password' with your password)

Create a file named group_vars/all.yml with the following content:

GOOGLE_KEY: "path_to_your_credentials_file" (same as terraform)
USER_ADMIN_PASSWORD: "your_password" (you previously created it with ansible-vault)

Put it in the ansible directory.

Create a file named .env with the following content:

REGION= "your project region on gcp"
PROJECT_NAME= "your project name on gcp"

Put it in the ansible/roles/jenkins/files directory.

Then run the following command (in the ansible directory):

ansible-playbook -i inventory.yml playbook.yml

Now, you have your jenkins server with docker and kubectl installed.

Jenkins

First, you need to connect to the jenkins server. Open web browser and go to http://your_compute_engine_instance_ip:8080. You can now connect to jenkins with the following credentials:

  • username: admin
  • password: "the password you have set in the ansible var file"

Now, enjoy your jenkins server !

About

Gcp project creator using Terraform, Kubernetes, Ansible, Jenkins, Helm, Docker

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published