{"id":18789038,"url":"https://github.com/artemmkin/terraform-kubernetes","last_synced_at":"2025-08-21T20:32:53.591Z","repository":{"id":133973556,"uuid":"117360988","full_name":"Artemmkin/terraform-kubernetes","owner":"Artemmkin","description":"Example of deploying a Kubernetes cluster to Google Cloud using Terraform","archived":false,"fork":false,"pushed_at":"2018-01-31T06:06:04.000Z","size":51,"stargazers_count":167,"open_issues_count":0,"forks_count":74,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-10T11:25:28.358Z","etag":null,"topics":["gitlab-ci","google-cloud","helm","kubernetes","kubernetes-deployment","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Artemmkin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-01-13T16:54:47.000Z","updated_at":"2024-09-22T11:05:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"7b064632-ed57-4a7b-964f-0c04def128a3","html_url":"https://github.com/Artemmkin/terraform-kubernetes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Artemmkin%2Fterraform-kubernetes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Artemmkin%2Fterraform-kubernetes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Artemmkin%2Fterraform-kubernetes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Artemmkin%2Fterraform-kubernetes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Artemmkin","download_url":"https://codeload.github.com/Artemmkin/terraform-kubernetes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230532448,"owners_count":18240792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gitlab-ci","google-cloud","helm","kubernetes","kubernetes-deployment","terraform"],"created_at":"2024-11-07T21:06:30.534Z","updated_at":"2024-12-20T04:07:53.700Z","avatar_url":"https://github.com/Artemmkin.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Table of Contents\n* [About the repo](#about-the-repo)\n* [Quick start](#quick-start)\n* [Repository structure](#repository-structure)\n   * [terraform-modules](#terraform-modules)\n   * [my-cluster](#my-cluster)\n   * [accounts](#accounts)\n* [CI/CD example with Gitlab CI and Helm](#cicd-example-with-gitlab-ci-and-helm)\n\n## About the repo\nThis repository contains an example of deploying and managing [Kubernetes](https://kubernetes.io/) clusters to [Google Cloud Platform](https://cloud.google.com/) (GCP) in a reliable and repeatable way.\n\n[Terraform](https://www.terraform.io/) is used to describe the desired state of the infrastructure, thus implementing Infrastructure as Code (IaC) approach.\n\n[Google Kubernetes Engine](https://cloud.google.com/kubernetes-engine/) (GKE) service is used for cluster deployment. Since Google announced that [they had eliminated the cluster management fees for GKE](https://cloudplatform.googleblog.com/2017/11/Cutting-Cluster-Management-Fees-on-Google-Kubernetes-Engine.html), it became the safest and cheapest way to run a Kubernetes cluster on GCP, because you only pay for the nodes (compute instances) running in your cluster and Google abstracts away and takes care of the master control plane.  \n\n\n## Quick start\n**Prerequisite:** make sure you're authenticated to GCP via [gcloud](https://cloud.google.com/sdk/gcloud/) command line tool using either _default application credentials_ or _service account_ with proper access.\n\nCheck **terraform.tfvars.example** file inside `my-cluster` folder to see what variables you need to define before you can use terraform to create a cluster.\n\nYou can run the following command in `my-cluster` to make your variables definitions available to terraform:\n```bash\n$ mv terraform.tfvars.example terraform.tfvars # variables defined in terraform.tfvars will be automatically picked up by terraform during the run\n```\n\nOnce the required variables are defined, use the commands below to create a Kubernetes cluster:\n```bash\n$ terraform init\n$ terraform apply\n```\n\nAfter the cluster is created, run a command from terraform output to configure access to the cluster via `kubectl` command line tool. The command from terraform output will be in the form of:\n\n```bash\n$ gcloud container clusters get-credentials my-cluster --zone europe-west1-b --project example-123456\n```\n\n\n## Repository structure\n```bash\n├── accounts\n│   └── service-accounts\n├── my-cluster\n│   ├── deploy-app-example\n│   └── k8s-config\n│       ├── charts\n│       │   └── gitlab-omnibus\n│       │       ├── charts\n│       │       │   └── gitlab-runner\n│       │       │       └── templates\n│       │       └── templates\n│       │           ├── fast-storage\n│       │           ├── gitlab\n│       │           ├── ingress\n│       │           └── load-balancer\n│       │               └── nginx\n│       ├── env-namespaces\n│       ├── kube-lego\n│       └── storage-classes\n└── terraform-modules\n    ├── cluster\n    ├── firewall\n    │   └── ingress-allow\n    ├── node-pool\n    └── vpc\n```\n\n### terraform-modules\nThe folder contains reusable pieces of terraform code which help us manage our configuration more efficiently by avoiding code repetition and reducing the volume of configuration.\n\nThe folder contains 4 modules at the moment of writing:\n\n* `cluster` module allows to create new Kubernetes clusters.\n* `firewall/ingress-allow` module allows to create firewall rules to filter incoming traffic.\n* `node-pool` module is used to create [Node Pools](https://cloud.google.com/kubernetes-engine/docs/concepts/node-pools) which is mechanism to add extra nodes of required configuration to a running Kubernetes cluster. Note that nodes which configuration is specified in the `cluster` module become the _default_ node pool.  \n* `vpc` module is used to create new Virtual Private Cloud (VPC) networks.\n\n### my-cluster\nInside the **my-cluster** folder, I put terraform configuration for the creation and management of an example of Kubernetes cluster.\nImportant files here:\n\n* `main.tf` is the place where we define main configuration such as creation of a network for our cluster, creation of the cluster itself and node pools.\n* `firewall.tf` is used to describe the firewall rules regarding our cluster.\n* `dns.tf` is used to manage Google DNS service resources (again with regards to the services and applications which we will run in our cluster).\n* `static-ips.tf` is used to manage static IP addresses for services and applications which will be running in the cluster.\n* `terraform.tfvars.example` contains example terraform input variables which you need to define before you can start creating a cluster.\n* `outputs.tf` contains output variables\n* `variables.tf` contains input variables\n\n* `k8-confing` folder contains Kubernetes configuration files (**manifests**) which are used to define configuration of the running Kubernetes cluster.\nIt has 4 subdirectories inside:\n    * `env-namespaces` contains manifests for creating [namespaces](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/), or virtual environments within the cluster, for running our services. In this example, `raddit-namespaces.yml` file is used to describe 3 namespaces: `raddit-stage` and `raddit-prod` for running [example application](https://github.com/Artemmkin/kubernetes-gitlab-example) (which is called raddit in this case) in different virtual environments, and `infra` namespace for running services vital to our infrastructure like CI/CD, monitoring, or logging software.\n    * `storage-classes` folder is used to create storage classes that could be then used in [dynamic volume provisioning](http://blog.kubernetes.io/2017/03/dynamic-provisioning-and-storage-classes-kubernetes.html) for our applications.\n    * `kube-lego` folder has the configuration required to run [kube-lego](https://github.com/jetstack/kube-lego) service which is used for automatic SSL certificates requests for our services running inside the cluster.\n    * `charts` contains [Helm](https://github.com/kubernetes/helm) charts for deploying infra services. In this case it only has a chart for deploying [Gitlab CI](https://about.gitlab.com/features/gitlab-ci-cd/) along with a Runner.\n\n* `deploy-app-example` has an bunch of Kubernetes objects definitions which are used to deploy nginx to a Kubernetes cluster. You can use the command below to deploy nginx to the cluster once it is created:\n\t```bash\n\t$ kubectl apply -f ./deploy-app-example/nginx-example.yml\n\t```\n\n### accounts\nThis is another top level folder in this project. It has a separate set of terraform files which are used to manage access accounts to our clusters. For example, you may want to create a service account for your CI tool to allow it to deploy applications to the cluster.\n\n## CI/CD example with Gitlab CI and Helm\nFor an example of building a CI/CD pipeline with Kubernetes, Gitlab CI, and Helm see [this](http://artemstar.com/2018/01/15/cicd-with-kubernetes-and-gitlab/) blog post.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartemmkin%2Fterraform-kubernetes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartemmkin%2Fterraform-kubernetes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartemmkin%2Fterraform-kubernetes/lists"}