Skip to content

Instantly share code, notes, and snippets.

@chris-cmsoft
Created August 28, 2021 22:22
Show Gist options
  • Save chris-cmsoft/c598206ad2c4204ff79095bd12846b37 to your computer and use it in GitHub Desktop.
Save chris-cmsoft/c598206ad2c4204ff79095bd12846b37 to your computer and use it in GitHub Desktop.
TLDR - Laravel In Kubernetes Part 4
# 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
# 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}
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"
}
}
}
do_token = "XXX"
do_region="fra1"
provider "digitalocean" {
token = var.do_token
}
variable "do_token" {
type = string
}
variable "do_region" {
type = string
default = "fra1"
}
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