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.20/stable >> microk8s_install.log
microk8s status --wait-ready
microk8s enable dns >> microk8s_install.log
microk8s add-node > microk8s.join_token
- microk8s config > configFile
+ microk8s config > configFile-master
EOF
key_name = "terraform"
tags = {
provisioner "local-exec" {
command = <<EOT
+ touch token
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
}
]
}
+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
+ }
-output "master_ip" {
+ 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
-From the node you wish to join to this cluster, run the following:
-microk8s join 172.31.10.54:25000/f9b66e02527274bd62996de9e04da30b
-
-If the node you are adding is not reachable through the default interface you can use one of the following:
- microk8s join 172.31.10.54:25000/f9b66e02527274bd62996de9e04da30b
- 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
+ microk8s join 172.31.1.7:25000/f9248352b1c01fd71b52c29880a177b5
+ microk8s join 172.31.10.73:25000/23c77c9fff9e96b8cb5599aa6ac38eac
+ microk8s join 172.31.3.101:25000/34d8296750d285c7deba6b62e8d12e44
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
+sudo 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
-