-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add persistent wordpress-mysql example
- Loading branch information
Showing
7 changed files
with
234 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# okteto-wordpress-mysql | ||
Example of running [wordpress-mysql](https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/) | ||
on [okteto-cloud](https://cloud.okteto.com/) using pure terraform | ||
|
||
Prerequisites | ||
* [Terraform > 0.12](https://www.terraform.io/downloads.html) | ||
* [Okteto Cloud account](https://cloud.okteto.com/#/login) | ||
|
||
Steps: | ||
1. Clone repo: `git clone [email protected]:jhole89/terraform-k8s-example.git` | ||
2. Change to this directory: `cd okteto-wordpress-mysql` | ||
3. Initialise terraform: `terraform init` | ||
4. Copy tfvars template: `cp terraform.tfvars.template terraform.tfvars` | ||
5. Fill in `terraform.tfvars` with Okteto values (found in your `okteto-kube.config` - make sure your | ||
`okteto-kube.config` is also in your `~/.kube/config`) | ||
6. Apply terraform plan: `terraform apply --auto-approve` - you should see the following output | ||
``` | ||
Apply complete! Resources: 7 added, 0 changed, 0 destroyed. | ||
Outputs: | ||
frontend_url = https://wordpress-jhole89.cloud.okteto.net/ | ||
``` | ||
6. The plan outputs the `url` exposed through the kubernetes service. You can now hit the | ||
endpoint using any web browser and set up your wordpress instance. | ||
7. Once no longer required you can remove all resources: `terraform destroy --auto-approve` |
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,98 @@ | ||
locals { | ||
mysql_labels = { | ||
app = var.app | ||
tier = "mysql" | ||
} | ||
} | ||
|
||
resource "kubernetes_deployment" "mysql" { | ||
metadata { | ||
name = "${local.mysql_labels.app}-mysql" | ||
namespace = var.okteto_cluster_namespace | ||
labels = { | ||
app = local.mysql_labels.app | ||
} | ||
} | ||
spec { | ||
selector { | ||
match_labels = local.mysql_labels | ||
} | ||
strategy { | ||
type = "Recreate" | ||
} | ||
template { | ||
metadata { | ||
labels = local.mysql_labels | ||
} | ||
spec { | ||
container { | ||
name = local.mysql_labels.tier | ||
image = "${local.mysql_labels.tier}:5.6" | ||
env { | ||
name = "MYSQL_ROOT_PASSWORD" | ||
value = kubernetes_secret.mysql.data.password | ||
} | ||
port { | ||
container_port = 3306 | ||
name = local.mysql_labels.tier | ||
} | ||
volume_mount { | ||
mount_path = "/var/lib/mysql" | ||
name = "mysql-persistent-storage" | ||
} | ||
} | ||
volume { | ||
name = "mysql-persistent-storage" | ||
persistent_volume_claim { | ||
claim_name = kubernetes_persistent_volume_claim.mysql.metadata[0].name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "kubernetes_persistent_volume_claim" "mysql" { | ||
metadata { | ||
name = "${var.app}-${local.mysql_labels.tier}-pv-claim" | ||
namespace = var.okteto_cluster_namespace | ||
labels = { | ||
app = var.app | ||
} | ||
} | ||
spec { | ||
access_modes = ["ReadWriteOnce"] | ||
resources { | ||
requests = { | ||
storage = "20Gi" | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "kubernetes_service" "mysql" { | ||
metadata { | ||
name = kubernetes_deployment.mysql.metadata[0].name | ||
namespace = kubernetes_deployment.mysql.metadata[0].namespace | ||
labels = { | ||
app = kubernetes_deployment.mysql.metadata[0].labels.app | ||
} | ||
} | ||
spec { | ||
port { | ||
port = 3306 | ||
} | ||
selector = kubernetes_deployment.mysql.spec[0].template[0].metadata[0].labels | ||
cluster_ip = "None" | ||
} | ||
} | ||
|
||
resource "kubernetes_secret" "mysql" { | ||
metadata { | ||
name = "${local.mysql_labels.tier}-pass" | ||
namespace = var.okteto_cluster_namespace | ||
} | ||
data = { | ||
password = var.mysql_password | ||
} | ||
} |
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,3 @@ | ||
output "frontend_url" { | ||
value = "https://${kubernetes_service.wordpress.metadata[0].name}-${var.okteto_cluster_namespace}.cloud.okteto.net/" | ||
} |
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,4 @@ | ||
provider "kubernetes" { | ||
config_context_auth_info = var.okteto_cluser_user | ||
config_context_cluster = var.okteto_cluster_name | ||
} |
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,3 @@ | ||
okteto_cluster_name = "" | ||
okteto_cluser_user = "" | ||
okteto_cluster_namespace = "" |
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,8 @@ | ||
variable "okteto_cluster_name" {} | ||
variable "okteto_cluser_user" {} | ||
variable "okteto_cluster_namespace" {} | ||
variable "mysql_password" {} | ||
|
||
variable "app" { | ||
default = "wordpress" | ||
} |
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,92 @@ | ||
locals { | ||
wordpress_labels = { | ||
app = var.app | ||
tier = "frontend" | ||
} | ||
} | ||
|
||
resource "kubernetes_deployment" "wordpress" { | ||
metadata { | ||
name = local.wordpress_labels.app | ||
namespace = var.okteto_cluster_namespace | ||
labels = { | ||
app = local.wordpress_labels.app | ||
} | ||
} | ||
spec { | ||
selector { | ||
match_labels = local.wordpress_labels | ||
} | ||
strategy { | ||
type = "Recreate" | ||
} | ||
template { | ||
metadata { | ||
labels = local.wordpress_labels | ||
} | ||
spec { | ||
container { | ||
name = local.wordpress_labels.app | ||
image = "wordpress:4.8-apache" | ||
env { | ||
name = "WORDPRESS_DB_HOST" | ||
value = "wordpress-mysql" | ||
} | ||
env { | ||
name = "WORDPRESS_DB_PASSWORD" | ||
value = kubernetes_secret.mysql.data.password | ||
} | ||
port { | ||
container_port = 80 | ||
name = local.wordpress_labels.app | ||
} | ||
volume_mount { | ||
name = "wordpress-persistent-storage" | ||
mount_path = "/var/www/html" | ||
} | ||
} | ||
volume { | ||
name = "wordpress-persistent-storage" | ||
persistent_volume_claim { | ||
claim_name = kubernetes_persistent_volume_claim.wordpress.metadata[0].name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "kubernetes_persistent_volume_claim" "wordpress" { | ||
metadata { | ||
name = "${var.app}-${local.wordpress_labels.tier}-pv-claim" | ||
namespace = var.okteto_cluster_namespace | ||
labels = { | ||
app = var.app | ||
} | ||
} | ||
spec { | ||
access_modes = ["ReadWriteOnce"] | ||
resources { | ||
requests = { | ||
storage = "20Gi" | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "kubernetes_service" "wordpress" { | ||
metadata { | ||
name = kubernetes_deployment.wordpress.metadata[0].name | ||
namespace = kubernetes_deployment.wordpress.metadata[0].namespace | ||
labels = { | ||
app = kubernetes_deployment.wordpress.metadata[0].labels.app | ||
} | ||
} | ||
spec { | ||
type = "LoadBalancer" | ||
port { | ||
port = 80 | ||
} | ||
selector = kubernetes_deployment.wordpress.spec[0].template[0].metadata[0].labels | ||
} | ||
} |