apt install snapd -y >> microk8s_install.log
snap install core >> microk8s_install.log
export PATH=$PATH:/snap/bin
- snap install microk8s --classic >> microk8s_install.log
+ snap install microk8s --classic --channel=1.21 >> microk8s_install.log
microk8s status --wait-ready
microk8s enable dns >> microk8s_install.log
+ microk8s enable storage >> microk8s_install.log
microk8s add-node > microk8s.join_token
- microk8s config > configFile
+ microk8s config > configFile-master
EOF
key_name = "terraform"
tags = {
"sudo sed -i 's/#MOREIPS/IP.7 = ${self.public_ip}\\n#MOREIPS/g' /var/snap/microk8s/current/certs/csr.conf.template",
"sudo sleep 1m",
"sudo microk8s stop",
- "sudo microk8s start"
+ "sudo microk8s start",
]
}
provisioner "local-exec" {
command = <<EOT
+ touch token
+ mkdir /root/.ssh && chmod 0700 /root/.ssh
ssh-keyscan -H ${self.public_dns} >> ~/.ssh/known_hosts
scp -i terraform.pem ubuntu@${self.public_dns}:/microk8s.join_token .
tail -n1 microk8s.join_token >> token
- scp -i terraform.pem ubuntu@${self.public_dns}:/configFile .
+ scp -i terraform.pem ubuntu@${self.public_dns}:/configFile-master .
EOT
}
}
-output "master_ip" {
+resource "null_resource" "cluster" {
+ provisioner "remote-exec" {
+ inline = ["sudo microk8s kubectl get no >> kubectl.info"]
+ }
+
+ connection {
+ host = aws_instance.master.public_ip
+ type = "ssh"
+ user = "ubuntu"
+ password = ""
+ private_key = "${file("terraform.pem")}"
+ }
+
+ provisioner "local-exec" {
+ command = <<EOT
+ echo ${aws_instance.master.private_ip}
+ export privateIP=${aws_instance.master.private_ip}
+ export publicIP=${aws_instance.master.public_ip}
+ ssh-keyscan -H ${aws_instance.worker.public_dns} >> ~/.ssh/known_hosts
+ scp -i terraform.pem ubuntu@${aws_instance.worker.public_dns}:/configFile-worker .
+ EOT
+ }
+
+ lifecycle {
+ create_before_destroy = true
+ }
+
+ depends_on = [
+ aws_instance.worker,
+ ]
+}
+
+output "public_ip" {
value = aws_instance.master.public_ip
}
+output "private_ip" {
+ value = aws_instance.master.private_ip
+}
+
+++ /dev/null
- microk8s join 172.31.21.68:25000/7bbce642aec6aafd22028238f1114c88
- microk8s join 172.31.18.98:25000/629d7bf742ec927cc21963b2ff404def
- microk8s join 172.31.3.108:25000/48fb4f98b7427abd52c45f522defc268
- microk8s join 172.31.30.69:25000/ce3caa0dcffb57b71741dd4f95b8306d
- microk8s join 172.31.22.56:25000/d60f8e7fb55b5e478a634095fb1c270f
- microk8s join 172.31.16.138:25000/297050fa5e93c71e9fda831ba64b99f9
- microk8s join 172.31.10.54:25000/f9b66e02527274bd62996de9e04da30b
variable "aws_region" {
description = "aws_region"
- default = "us-east-2"
}
variable "aws_instance" {
description = "instance_type"
- default = "t2.small"
}
variable "aws_ami" {
description = "aws_ami"
- default = "ami-026141f3d5c6d2d0c"
}
variable "aws_subnet_id" {
description = "subnet_id"
- default = "<insertsubnetID>"
}
variable "vpc_id" {
description = "vpc_id"
- default = "<insertVpcID>"
}
variable "access_key" {
description = "access_key"
- default = "<insertAccessKey>"
}
variable "secret_key" {
description = "secret_key"
- default = "<insertSecretKey>"
}
sudo apt update -y >> microk8s_install.log
sudo apt install snapd -y >> microk8s_install.log
-sudo snap install microk8s --classic >> microk8s_install.log
+snap install microk8s --classic --channel=1.20/stable >> microk8s_install.log
sudo microk8s enable dns >> microk8s_install.log
sudo ${token} >> microk8s_install.log
+microk8s config > configFile-worker
sudo touch microk8s.complete
-