-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from jugatsu/kubernetes-2
Add full app deployment in the Kubernetes cluster
- Loading branch information
Showing
15 changed files
with
457 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Ensure GKE cluster is present and configured | ||
resource "google_container_cluster" "cluster" { | ||
description = "GKE Cluster for Reddit-app" | ||
enable_legacy_abac = false | ||
initial_node_count = "${var.gke_node_count}" | ||
min_master_version = "${var.gke_version}" | ||
name = "${var.gke_name}" | ||
zone = "${var.gke_zone}" | ||
|
||
addons_config { | ||
kubernetes_dashboard { | ||
disabled = "${var.gke_dashboard_disabled}" | ||
} | ||
} | ||
|
||
node_config { | ||
disk_size_gb = "${var.gke_node_size}" | ||
image_type = "${var.gke_node_image}" | ||
machine_type = "${var.gke_node_machine_type}" | ||
|
||
oauth_scopes = [ | ||
"https://www.googleapis.com/auth/compute", | ||
"https://www.googleapis.com/auth/devstorage.read_only", | ||
"https://www.googleapis.com/auth/logging.write", | ||
"https://www.googleapis.com/auth/monitoring", | ||
] | ||
} | ||
|
||
// configure kubectl | ||
provisioner "local-exec" { | ||
command = "gcloud container clusters get-credentials ${var.gke_name} --zone ${var.gke_zone} --project ${var.google_project}" | ||
} | ||
} | ||
|
||
// Ensure firewall rule for application access is present and configured | ||
resource "google_compute_firewall" "firewall" { | ||
name = "gke-reddit-app" | ||
description = "Allow access to reddit-app deployed in the Kubernetes" | ||
network = "default" | ||
|
||
allow = { | ||
protocol = "tcp" | ||
ports = ["30000-32767"] | ||
} | ||
|
||
source_ranges = ["0.0.0.0/0"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Configure the Google Cloud provider | ||
provider "google" { | ||
version = "~> 1.3.0" | ||
|
||
project = "${var.google_project}" | ||
region = "${var.google_region}" | ||
} | ||
|
||
// Configure the Kubernetes provider | ||
provider "kubernetes" { | ||
version = "~> 1.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
################################# | ||
# Google Cloud Provider variables | ||
################################# | ||
|
||
google_project = "YOUR_PROJECT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
################################# | ||
# Google Cloud Provider variables | ||
################################# | ||
|
||
variable "google_project" { | ||
description = "The ID of the project" | ||
} | ||
|
||
variable "google_region" { | ||
default = "europe-west1" | ||
description = "The region to operate under" | ||
} | ||
|
||
################################# | ||
# Kubernetes Provider variables | ||
################################# | ||
|
||
variable "gke_dashboard_disabled" { | ||
default = true | ||
} | ||
|
||
variable "gke_name" { | ||
default = "cluster-1" | ||
description = "The name of GKE cluster" | ||
} | ||
|
||
variable "gke_node_count" { | ||
default = 3 | ||
description = "The number of nodes in GKE cluster" | ||
} | ||
|
||
variable "gke_version" { | ||
default = "1.8.3-gke.0" | ||
} | ||
|
||
variable "gke_zone" { | ||
default = "europe-west1-c" | ||
} | ||
|
||
variable "gke_node_size" { | ||
default = 20 | ||
description = "Size of the disk attached to each node" | ||
} | ||
|
||
variable "gke_node_machine_type" { | ||
default = "n1-standard-1" | ||
description = "The name of a Google Compute Engine machine type" | ||
} | ||
|
||
variable "gke_node_image" { | ||
default = "COS" | ||
description = "The image type to use for this node" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
# ------------------- Comment Deployment ------------------- # | ||
apiVersion: apps/v1beta2 | ||
kind: Deployment | ||
metadata: | ||
name: comment | ||
labels: | ||
app: reddit | ||
component: comment | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: reddit | ||
component: comment | ||
replicas: 3 | ||
template: | ||
metadata: | ||
name: comment | ||
labels: | ||
app: reddit | ||
component: comment | ||
spec: | ||
containers: | ||
- image: jugatsu/comment:latest | ||
name: comment | ||
env: | ||
- name: COMMENT_DATABASE_HOST | ||
value: comment-db | ||
|
||
--- | ||
# ------------------- Comment Service ------------------- # | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: comment | ||
labels: | ||
app: reddit | ||
component: comment | ||
spec: | ||
ports: | ||
- port: 9292 | ||
protocol: TCP | ||
targetPort: 9292 | ||
selector: | ||
app: reddit | ||
component: comment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
# ------------------- MongoDB Deployment ------------------- # | ||
apiVersion: apps/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: mongo | ||
labels: | ||
app: reddit | ||
component: mongo | ||
comment-db: "true" | ||
post-db: "true" | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: reddit | ||
component: mongo | ||
template: | ||
metadata: | ||
name: mongo | ||
labels: | ||
app: reddit | ||
component: mongo | ||
comment-db: "true" | ||
post-db: "true" | ||
spec: | ||
containers: | ||
- image: mongo:3.2 | ||
name: mongo | ||
volumeMounts: | ||
- name: mongo-persistent-storage | ||
mountPath: /data/db | ||
volumes: | ||
- name: mongo-persistent-storage | ||
emptyDir: {} | ||
|
||
--- | ||
# ------------------- Mongo-Comment Service ------------------- # | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: comment-db | ||
labels: | ||
app: reddit | ||
component: mongo | ||
comment-db: "true" | ||
spec: | ||
ports: | ||
- port: 27017 | ||
protocol: TCP | ||
targetPort: 27017 | ||
selector: | ||
app: reddit | ||
component: mongo | ||
comment-db: "true" | ||
|
||
--- | ||
# ------------------- Mongo-Post Service ------------------- # | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: post-db | ||
labels: | ||
app: reddit | ||
component: mongo | ||
post-db: "true" | ||
spec: | ||
ports: | ||
- port: 27017 | ||
protocol: TCP | ||
targetPort: 27017 | ||
selector: | ||
app: reddit | ||
component: mongo | ||
post-db: "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
# ------------------- Post Deployment ------------------- # | ||
apiVersion: apps/v1beta2 | ||
kind: Deployment | ||
metadata: | ||
name: post | ||
labels: | ||
app: reddit | ||
component: post | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: reddit | ||
component: post | ||
replicas: 3 | ||
template: | ||
metadata: | ||
name: post | ||
labels: | ||
app: reddit | ||
component: post | ||
spec: | ||
containers: | ||
- image: jugatsu/post:latest | ||
name: post | ||
env: | ||
- name: POST_DATABASE_HOST | ||
value: post-db | ||
|
||
--- | ||
# ------------------- Post Service ------------------- # | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: post | ||
labels: | ||
app: reddit | ||
component: post | ||
spec: | ||
ports: | ||
- port: 5000 | ||
protocol: TCP | ||
targetPort: 5000 | ||
selector: | ||
app: reddit | ||
component: post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
# ------------------- UI Deployment ------------------- # | ||
apiVersion: apps/v1beta2 | ||
kind: Deployment | ||
metadata: | ||
name: ui | ||
labels: | ||
app: reddit | ||
component: ui | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: reddit | ||
component: ui | ||
template: | ||
metadata: | ||
name: ui | ||
labels: | ||
app: reddit | ||
component: ui | ||
spec: | ||
containers: | ||
- image: jugatsu/ui:latest | ||
name: ui | ||
env: | ||
- name: ENV | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.namespace | ||
|
||
--- | ||
# ------------------- UI Service ------------------- # | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: ui | ||
labels: | ||
app: reddit | ||
component: ui | ||
spec: | ||
type: NodePort | ||
ports: | ||
- port: 9292 | ||
protocol: TCP | ||
targetPort: 9292 | ||
selector: | ||
app: reddit | ||
component: ui |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.