This repository contains the Terraform code to build GKE (Google Kubernetes Engine) and Kubernetes components to create services and deployment that configure jenkins for CI/CD which can build and run containers and service loadbalancer.
- GNU/Linux
terraform
docker
kubernetes
https://github.com/mustafaabdelbadea/GCP-DevOps
cd GCP-DevOps
GCP-DevOps
├── configure_pod.sh
├── images
│ └── Trello.png
├── kubernetes
│ ├── 1_namespace.yml
│ ├── 2_roles.yml
│ ├── 3_jenkins-service-account.yml
│ ├── 4_role-binding.yml
│ ├── 5_jenkins-service.yml
│ ├── 6_jenkins-deploy.yml
│ └── apply.sh
├── README.md
└── terraform
├── apis
│ ├── main.tf
│ ├── outputs.tf
│ └── varibales.tf
├── apis.tf
├── cluster
│ ├── cluster.tf
│ ├── node-pool.tf
│ ├── outputs.tf
│ ├── service-account.tf
│ └── variables.tf
├── cluster.tf
├── network
│ ├── firewall.tf
│ ├── nat.tf
│ ├── outputs.tf
│ ├── router.tf
│ ├── subnets.tf
│ ├── variables.tf
│ └── vpc.tf
├── network..tf
├── prod.tfvars
├── provider.tf
└── variables.tf
Provider.tf
To configure the provider, project and the backend for the terraform (Bucket).Variables.tf
All terraform variables types definiation.- Create
variables
without type to act as typeany
.
- Create
prod.tfvars
Production variables.
apis module
Enable and disable apis
- Comopute api.
- Container api.
network module
Configure network on GCP
- Create VPC.
- Partation the network using subnets.
- Create route.
- Create nat .
- Configure firewall.
cluster module
Configure cluster
- Create service account .
- Create Cluster.
- Create node pool with image type
UBUNTU_CONTAINERD (Docker)
.
cd terraform
terraform init
terraform terraform workspace new production
terraform plan --var-file=prod.tfvars
terraform apply --var-file=pord.tfvars
- Starting the naming with number to make files ordered.
- Create
namespace
to isolate the components. - Create
role
to enable thejenkins pod
to create, list, deleteservices and deployments
. - Create
service account
to be attached in thedeployment
. - Create
role bind
to bind therole
withservice account
. - Create
service loadbalancer
to create loadbalacer with external ip to access the application. -
Create
deployment
that contains:- Container with
jenkins
image with container port8080
. - Mount volume to use the
Docker
of the node. - Attach the
service account
to make pod create deployments and services in the same cluster - Execute commands to install
docker cli and kubectl
after pod started usinglifecycle
. - Create the pod with
root
privilege.
- Container with
Execute all kubernetes files
cd kubernetes
./apply.sh