Skip to content

Commit

Permalink
inital example of deploying echoserver using TF
Browse files Browse the repository at this point in the history
  • Loading branch information
jhole89 committed Mar 21, 2020
0 parents commit 8b9910c
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 0 deletions.
121 changes: 121 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@

# Created by https://www.gitignore.io/api/terraform,intellij+all
# Edit at https://www.gitignore.io/?templates=terraform,intellij+all

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint

### Terraform ###
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# End of https://www.gitignore.io/api/terraform,intellij+all
64 changes: 64 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
resource "kubernetes_namespace" "example_namespace" {
metadata {
name = "${var.label}-namespace"
}
}

resource "kubernetes_service" "example_service" {
metadata {
name = "${var.label}-service"
namespace = kubernetes_namespace.example_namespace.metadata[0].name
labels = {
app = kubernetes_deployment.example_deployment.metadata[0].labels.app
}
}

spec {
selector = {
app = kubernetes_deployment.example_deployment.metadata[0].labels.app
}

port {
port = var.service_internal_port
target_port = kubernetes_deployment.example_deployment.spec[0].template[0].spec[0].container[0].port[0].container_port
}

type = var.service_exposure
}
}

resource "kubernetes_deployment" "example_deployment" {
metadata {
name = "${var.label}-deployment"
namespace = kubernetes_namespace.example_namespace.metadata[0].name
labels = {
app = var.label
}
}

spec {
replicas = 2

selector {
match_labels = {
app = var.label
}
}
template {
metadata {
labels = {
app = var.label
}
}
spec {
container {
name = var.label
image = var.image
port {
container_port = var.container_port
}
}
}
}
}
}
3 changes: 3 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "node_port" {
value = kubernetes_service.example_service.spec[0].port[0].node_port
}
5 changes: 5 additions & 0 deletions provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider "kubernetes" {

config_context_auth_info = "minikube"
config_context_cluster = "minikube"
}
19 changes: 19 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "label" {
default = "example-app"
}

variable "image" {
default = "gcr.io/google_containers/echoserver:1.4"
}

variable "service_exposure" {
default = "NodePort"
}

variable "service_internal_port" {
default = 8080
}

variable "container_port" {
default = 8080
}

0 comments on commit 8b9910c

Please sign in to comment.