2019-09-06 08:12:09 +02:00
|
|
|
# Secure copy assets to controllers. Activates kubelet.service
|
2018-03-26 07:32:09 +02:00
|
|
|
resource "null_resource" "copy-controller-secrets" {
|
2019-05-28 00:37:36 +02:00
|
|
|
count = var.controller_count
|
2019-05-06 09:38:23 +02:00
|
|
|
|
2019-05-17 12:52:16 +02:00
|
|
|
depends_on = [
|
2019-09-15 01:24:32 +02:00
|
|
|
module.bootstrap,
|
2019-05-28 00:37:36 +02:00
|
|
|
digitalocean_firewall.rules
|
2019-05-17 12:52:16 +02:00
|
|
|
]
|
2017-09-14 05:08:28 +02:00
|
|
|
|
|
|
|
connection {
|
|
|
|
type = "ssh"
|
2019-09-06 08:12:09 +02:00
|
|
|
host = digitalocean_droplet.controllers.*.ipv4_address[count.index]
|
2017-09-14 05:08:28 +02:00
|
|
|
user = "core"
|
|
|
|
timeout = "15m"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
2019-09-15 01:24:32 +02:00
|
|
|
content = module.bootstrap.kubeconfig-kubelet
|
2017-09-14 05:08:28 +02:00
|
|
|
destination = "$HOME/kubeconfig"
|
|
|
|
}
|
|
|
|
|
2017-10-04 09:07:48 +02:00
|
|
|
provisioner "file" {
|
2019-09-15 01:24:32 +02:00
|
|
|
content = module.bootstrap.etcd_ca_cert
|
2017-10-04 09:07:48 +02:00
|
|
|
destination = "$HOME/etcd-client-ca.crt"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
2019-09-15 01:24:32 +02:00
|
|
|
content = module.bootstrap.etcd_client_cert
|
2017-10-04 09:07:48 +02:00
|
|
|
destination = "$HOME/etcd-client.crt"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
2019-09-15 01:24:32 +02:00
|
|
|
content = module.bootstrap.etcd_client_key
|
2017-10-04 09:07:48 +02:00
|
|
|
destination = "$HOME/etcd-client.key"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
2019-09-15 01:24:32 +02:00
|
|
|
content = module.bootstrap.etcd_server_cert
|
2017-10-04 09:07:48 +02:00
|
|
|
destination = "$HOME/etcd-server.crt"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
2019-09-15 01:24:32 +02:00
|
|
|
content = module.bootstrap.etcd_server_key
|
2017-10-04 09:07:48 +02:00
|
|
|
destination = "$HOME/etcd-server.key"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
2019-09-15 01:24:32 +02:00
|
|
|
content = module.bootstrap.etcd_peer_cert
|
2017-10-04 09:07:48 +02:00
|
|
|
destination = "$HOME/etcd-peer.crt"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
2019-09-15 01:24:32 +02:00
|
|
|
content = module.bootstrap.etcd_peer_key
|
2017-10-04 09:07:48 +02:00
|
|
|
destination = "$HOME/etcd-peer.key"
|
|
|
|
}
|
2019-09-06 08:12:09 +02:00
|
|
|
|
|
|
|
provisioner "file" {
|
|
|
|
source = var.asset_dir
|
|
|
|
destination = "$HOME/assets"
|
|
|
|
}
|
2017-10-04 09:07:48 +02:00
|
|
|
|
2017-09-14 05:08:28 +02:00
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
2017-10-04 09:07:48 +02:00
|
|
|
"sudo mkdir -p /etc/ssl/etcd/etcd",
|
|
|
|
"sudo mv etcd-client* /etc/ssl/etcd/",
|
|
|
|
"sudo cp /etc/ssl/etcd/etcd-client-ca.crt /etc/ssl/etcd/etcd/server-ca.crt",
|
|
|
|
"sudo mv etcd-server.crt /etc/ssl/etcd/etcd/server.crt",
|
|
|
|
"sudo mv etcd-server.key /etc/ssl/etcd/etcd/server.key",
|
|
|
|
"sudo cp /etc/ssl/etcd/etcd-client-ca.crt /etc/ssl/etcd/etcd/peer-ca.crt",
|
|
|
|
"sudo mv etcd-peer.crt /etc/ssl/etcd/etcd/peer.crt",
|
|
|
|
"sudo mv etcd-peer.key /etc/ssl/etcd/etcd/peer.key",
|
|
|
|
"sudo chown -R etcd:etcd /etc/ssl/etcd",
|
|
|
|
"sudo chmod -R 500 /etc/ssl/etcd",
|
2019-09-06 08:12:09 +02:00
|
|
|
"sudo mv $HOME/assets /opt/bootstrap/assets",
|
2019-09-19 08:56:17 +02:00
|
|
|
"sudo mkdir -p /etc/kubernetes/manifests"
|
2019-09-06 08:12:09 +02:00
|
|
|
"sudo mkdir -p /etc/kubernetes/bootstrap-secrets",
|
2019-09-19 08:56:17 +02:00
|
|
|
"sudo mv $HOME/kubeconfig /etc/kubernetes/kubeconfig",
|
2019-09-06 08:12:09 +02:00
|
|
|
"sudo cp -r /opt/bootstrap/assets/tls/* /etc/kubernetes/bootstrap-secrets/",
|
|
|
|
"sudo cp /opt/bootstrap/assets/auth/kubeconfig /etc/kubernetes/bootstrap-secrets/",
|
|
|
|
"sudo cp -r /opt/bootstrap/assets/static-manifests/* /etc/kubernetes/manifests/",
|
2018-03-26 07:32:09 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Secure copy kubeconfig to all workers. Activates kubelet.service.
|
|
|
|
resource "null_resource" "copy-worker-secrets" {
|
2019-05-28 00:37:36 +02:00
|
|
|
count = var.worker_count
|
2018-03-26 07:32:09 +02:00
|
|
|
|
|
|
|
connection {
|
|
|
|
type = "ssh"
|
2019-09-06 08:12:09 +02:00
|
|
|
host = digitalocean_droplet.workers.*.ipv4_address[count.index]
|
2018-03-26 07:32:09 +02:00
|
|
|
user = "core"
|
|
|
|
timeout = "15m"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
2019-09-15 01:24:32 +02:00
|
|
|
content = module.bootstrap.kubeconfig-kubelet
|
2018-03-26 07:32:09 +02:00
|
|
|
destination = "$HOME/kubeconfig"
|
|
|
|
}
|
2018-03-26 09:01:47 +02:00
|
|
|
|
2018-03-26 07:32:09 +02:00
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
|
|
|
"sudo mv $HOME/kubeconfig /etc/kubernetes/kubeconfig",
|
2017-09-14 05:08:28 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2017-09-18 06:43:00 +02:00
|
|
|
|
2019-09-06 08:12:09 +02:00
|
|
|
# Connect to a controller to perform one-time cluster bootstrap.
|
|
|
|
resource "null_resource" "bootstrap" {
|
2018-03-26 07:32:09 +02:00
|
|
|
depends_on = [
|
2019-05-28 00:37:36 +02:00
|
|
|
null_resource.copy-controller-secrets,
|
|
|
|
null_resource.copy-worker-secrets,
|
2018-03-26 07:32:09 +02:00
|
|
|
]
|
2017-07-29 20:35:53 +02:00
|
|
|
|
|
|
|
connection {
|
|
|
|
type = "ssh"
|
2019-05-28 00:37:36 +02:00
|
|
|
host = digitalocean_droplet.controllers[0].ipv4_address
|
2017-07-29 20:35:53 +02:00
|
|
|
user = "core"
|
|
|
|
timeout = "15m"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
2019-09-06 08:12:09 +02:00
|
|
|
"sudo systemctl start bootstrap",
|
2017-07-29 20:35:53 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2019-05-28 00:37:36 +02:00
|
|
|
|