Created
August 28, 2021 22:22
-
-
Save chris-cmsoft/c598206ad2c4204ff79095bd12846b37 to your computer and use it in GitHub Desktop.
TLDR - Laravel In Kubernetes Part 4
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
# Local .terraform directories | |
**/.terraform/* | |
# .tfstate files | |
*.tfstate | |
*.tfstate.* | |
# Crash log files | |
crash.log | |
# Exclude all .tfvars files, which are likely to contain sentitive data, such as | |
# password, private keys, and other secrets. These should not be part of version | |
# control as they are data points which are potentially sensitive and subject | |
# to change depending on the environment. | |
# | |
*.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* | |
# Ignore CLI configuration files | |
.terraformrc | |
terraform.rc |
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
# Create a new infrastructure repository alongside your app directory | |
mkdir -p laravel-in-kubernetes-infra | |
cd laravel-in-kubernetes-infra/ | |
# Initialise Terraform | |
terraform init | |
# Validate Terraform Settings and files | |
terraform validate | |
# Apply Terraform configuration | |
terraform apply | |
# Get Cluster access details | |
CLUSTER_ID=$(doctl kubernetes clusters get laravel-in-kubernetes --format=ID --no-header) | |
doctl k8s cluster kubeconfig save ${CLUSTER_ID} |
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
data "digitalocean_kubernetes_versions" "kubernetes-version" { | |
version_prefix = "1.21." | |
} | |
data "digitalocean_sizes" "small" { | |
filter { | |
key = "slug" | |
values = [ | |
"s-2vcpu-2gb"] | |
} | |
} | |
resource "digitalocean_kubernetes_cluster" "laravel-in-kubernetes" { | |
name = "laravel-in-kubernetes" | |
region = var.do_region | |
# Latest patched version of DigitalOcean Kubernetes. | |
# We do not want to update minor or major versions automatically. | |
version = data.digitalocean_kubernetes_versions.kubernetes-version.latest_version | |
# We want any Kubernetes Patches to be added to our cluster automatically. | |
# With the version also set to the latest version, this will be covered from two perspectives | |
auto_upgrade = true | |
maintenance_policy { | |
# Run patch upgrades at 4AM on a Sunday morning. | |
start_time = "04:00" | |
day = "sunday" | |
} | |
node_pool { | |
name = "default-pool" | |
size = "${element(data.digitalocean_sizes.small.sizes, 0).slug}" | |
# We can autoscale our cluster according to use, and if it gets high, | |
# We can auto scale to maximum 5 nodes. | |
auto_scale = true | |
min_nodes = 1 | |
max_nodes = 5 | |
# These labels will be available in the node objects inside of Kubernetes, | |
# which we can use as taints and tolerations for workloads. | |
labels = { | |
pool = "default" | |
size = "small" | |
} | |
} | |
} |
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
do_token = "XXX" | |
do_region="fra1" |
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
provider "digitalocean" { | |
token = var.do_token | |
} |
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
variable "do_token" { | |
type = string | |
} | |
variable "do_region" { | |
type = string | |
default = "fra1" | |
} |
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
terraform { | |
required_providers { | |
digitalocean = { | |
source = "digitalocean/digitalocean" | |
version = "~> 2.11" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment