mirror of
https://github.com/Dannecron/netology-devops.git
synced 2025-12-25 15:22:37 +03:00
add terraform config for mini k8s cluster
This commit is contained in:
38
src/terraform/k8s-mini-cluster/.gitignore
vendored
Normal file
38
src/terraform/k8s-mini-cluster/.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Local .terraform directories
|
||||||
|
**/.terraform/*
|
||||||
|
|
||||||
|
# .tfstate files
|
||||||
|
*.tfstate
|
||||||
|
*.tfstate.*
|
||||||
|
|
||||||
|
# Crash log files
|
||||||
|
crash.log
|
||||||
|
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
|
||||||
|
.terraform.lock.hcl
|
||||||
|
|
||||||
|
variables.tf
|
||||||
92
src/terraform/k8s-mini-cluster/main.tf
Normal file
92
src/terraform/k8s-mini-cluster/main.tf
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
yandex = {
|
||||||
|
source = "yandex-cloud/yandex"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
required_version = ">= 0.13"
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "yandex" {
|
||||||
|
token = var.yandex_cloud_token
|
||||||
|
cloud_id = var.yandex_cloud_id
|
||||||
|
folder_id = var.yandex_folder_id
|
||||||
|
zone = "ru-central1-a"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "yandex_vpc_network" "network-1" {
|
||||||
|
name = "network1"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "yandex_vpc_subnet" "subnet-1" {
|
||||||
|
name = "subnet1"
|
||||||
|
zone = "ru-central1-a"
|
||||||
|
network_id = yandex_vpc_network.network-1.id
|
||||||
|
v4_cidr_blocks = ["192.168.10.0/24"]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "yandex_compute_instance" "k8s-control" {
|
||||||
|
name = "control"
|
||||||
|
|
||||||
|
resources {
|
||||||
|
cores = 2
|
||||||
|
memory = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
boot_disk {
|
||||||
|
initialize_params {
|
||||||
|
image_id = "fd8kdq6d0p8sij7h5qe3" # ubuntu-20-04-lts-v20220822
|
||||||
|
size = "20"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
subnet_id = yandex_vpc_subnet.subnet-1.id
|
||||||
|
nat = true
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
ssh-keys = "ubuntu:${file("~/.ssh/id_rsa.pub")}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "yandex_compute_instance" "k8s-node" {
|
||||||
|
for_each = toset(["node01"])
|
||||||
|
|
||||||
|
name = each.key
|
||||||
|
|
||||||
|
resources {
|
||||||
|
cores = 2
|
||||||
|
memory = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
boot_disk {
|
||||||
|
initialize_params {
|
||||||
|
image_id = "fd8kdq6d0p8sij7h5qe3" # ubuntu-20-04-lts-v20220822
|
||||||
|
size = "20"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
subnet_id = yandex_vpc_subnet.subnet-1.id
|
||||||
|
nat = true
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
ssh-keys = "ubuntu:${file("~/.ssh/id_rsa.pub")}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output "control_ips" {
|
||||||
|
value = {
|
||||||
|
internal = yandex_compute_instance.k8s-control.network_interface.0.ip_address
|
||||||
|
external = yandex_compute_instance.k8s-control.network_interface.0.nat_ip_address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output "node_ips" {
|
||||||
|
value = {
|
||||||
|
internal = values(yandex_compute_instance.k8s-node)[*].network_interface.0.ip_address
|
||||||
|
external = values(yandex_compute_instance.k8s-node)[*].network_interface.0.nat_ip_address
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/terraform/k8s-mini-cluster/variables.tf.example
Normal file
16
src/terraform/k8s-mini-cluster/variables.tf.example
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Заменить на ID своего облака
|
||||||
|
# https://console.cloud.yandex.ru/cloud?section=overview
|
||||||
|
variable "yandex_cloud_id" {
|
||||||
|
default = "b1gu1gt5nqi6lqgu3t7s"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Заменить на Folder своего облака
|
||||||
|
# https://console.cloud.yandex.ru/cloud?section=overview
|
||||||
|
variable "yandex_folder_id" {
|
||||||
|
default = "b1gaec42k169jqpo02f7"
|
||||||
|
}
|
||||||
|
|
||||||
|
# OAuth токен, используемый утилитой yc. Применялся на этапе с packer.
|
||||||
|
variable "yandex_cloud_token" {
|
||||||
|
default = ""
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user