init
This commit is contained in:
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Terraform
|
||||
.terraform/
|
||||
terraform.*
|
||||
.terraform.*
|
||||
|
||||
# Nix
|
||||
flake.lock
|
||||
31
README.md
Normal file
31
README.md
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
# Kube Playground
|
||||
|
||||
## Getting started
|
||||
|
||||
Start a developer console in NixOS with all need dependencies
|
||||
|
||||
```bash
|
||||
nix develop
|
||||
```
|
||||
|
||||
Run Terraform to deploy needed VMs
|
||||
|
||||
First init
|
||||
|
||||
```bash
|
||||
terraform init
|
||||
```
|
||||
|
||||
Then apply
|
||||
|
||||
|
||||
```bash
|
||||
terraform apply
|
||||
```
|
||||
|
||||
## Misc
|
||||
|
||||
Good extension for Openlens
|
||||
|
||||
for the extension: go to File-->Extensions--> use `@alebcay/openlens-node-pod-menu` for url, hit install
|
||||
24
flake.nix
Normal file
24
flake.nix
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
description = "A flake for Terraform development";
|
||||
|
||||
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
|
||||
outputs = { self, nixpkgs }: {
|
||||
devShells.x86_64-linux.default =
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
in
|
||||
pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
terraform
|
||||
cdrtools
|
||||
kubectl
|
||||
openlens
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
91
main.tf
Normal file
91
main.tf
Normal file
@@ -0,0 +1,91 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
libvirt = {
|
||||
source = "dmacvicar/libvirt"
|
||||
version = "0.7.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "libvirt" {
|
||||
uri = "qemu:///system"
|
||||
}
|
||||
|
||||
variable "vms" {
|
||||
description = "Map of VMs to create"
|
||||
type = map(object({
|
||||
name = string
|
||||
memory = string
|
||||
vcpu = number
|
||||
}))
|
||||
default = {
|
||||
"vm1" = {
|
||||
name = "kube-master"
|
||||
memory = "2048"
|
||||
vcpu = 1
|
||||
},
|
||||
"vm2" = {
|
||||
name = "kube-worker-01"
|
||||
memory = "2048"
|
||||
vcpu = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "base-kube-qcow2" {
|
||||
name = "base-kube"
|
||||
source = "/home/alex/ISOs/ubuntu-22.04-server-cloudimg-amd64.img"
|
||||
format = "qcow2"
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "kube-qcow2" {
|
||||
for_each = var.vms
|
||||
name = each.value.name
|
||||
base_volume_id = libvirt_volume.base-kube-qcow2.id
|
||||
size = 25 * 1024 * 1024 * 1024
|
||||
format = "qcow2"
|
||||
}
|
||||
|
||||
resource "libvirt_domain" "kube-vm" {
|
||||
for_each = var.vms
|
||||
name = each.value.name
|
||||
memory = each.value.memory
|
||||
vcpu = each.value.vcpu
|
||||
|
||||
network_interface {
|
||||
network_name = "default"
|
||||
}
|
||||
|
||||
disk {
|
||||
volume_id = libvirt_volume.kube-qcow2[each.key].id
|
||||
}
|
||||
|
||||
cloudinit = libvirt_cloudinit_disk.commoninit.id
|
||||
}
|
||||
|
||||
resource "libvirt_cloudinit_disk" "commoninit" {
|
||||
name = "commoninit.iso"
|
||||
user_data = <<-EOF
|
||||
#cloud-config
|
||||
password: passw0rd
|
||||
chpasswd: { expire: False }
|
||||
ssh_pwauth: True
|
||||
runcmd:
|
||||
- swapoff -a
|
||||
- sed -i '/ swap / s/^/#/' /etc/fstab
|
||||
- apt-get update && apt-get install -y apt-transport-https curl
|
||||
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
||||
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||
- apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io
|
||||
- curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
|
||||
- echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list
|
||||
- apt-get update
|
||||
- apt-get install -y kubelet kubeadm
|
||||
EOF
|
||||
network_config = <<-EOF
|
||||
version: 2
|
||||
ethernets:
|
||||
ens3:
|
||||
dhcp4: true
|
||||
EOF
|
||||
}
|
||||
Reference in New Issue
Block a user