Skip to content

Instantly share code, notes, and snippets.

@JanKoppe
Forked from chrischdi/hetzner.tf
Created August 17, 2018 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanKoppe/e2c35061fca22af5dff4968e189d2602 to your computer and use it in GitHub Desktop.
Save JanKoppe/e2c35061fca22af5dff4968e189d2602 to your computer and use it in GitHub Desktop.
variable "hcloud_token" {
}
provider "hcloud" {
token = "${var.hcloud_token}"
}
resource "hcloud_server" "kube-master" {
name = "kube-master"
image = "ubuntu-18.04"
server_type = "cx11"
ssh_keys = ["${hcloud_ssh_key.default.id}"]
connection {
type = "ssh"
user = "root"
private_key = "${file("~/.ssh/id_rsa")}"
}
provisioner "file" {
source = "install-k8s.sh"
destination = "/opt/install-k8s.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /opt/install-k8s.sh",
"/opt/install-k8s.sh",
]
}
}
resource "hcloud_ssh_key" "default" {
name = "pubkey"
public_key = "${file("~/.ssh/id_rsa.pub")}"
}
output "ip" {
value = "${hcloud_server.kube-master.ipv4_address}"
}
#!/bin/bash
set -e
set -x
function _aptUpdate() {
set +e
apt-get clean
apt-get update
apt-get update
set -e
}
function prepare() {
sed -i 's/^\/swapfile/#\/swapfile/' /etc/fstab
swapoff /swapfile
# ugly workaround for hetzners image
rm /var/lib/apt/lists/lock
}
function dockerio() {
_aptUpdate
apt-get install -y docker.io
}
function install_kubeadm() {
# from https://kubernetes.io/docs/setup/independent/install-kubeadm/
_aptUpdate
apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
_aptUpdate
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
}
function init_kubeadm() {
kubeadm init --pod-network-cidr=192.168.0.0/16
kubectl --kubeconfig /etc/kubernetes/admin.conf apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl --kubeconfig /etc/kubernetes/admin.conf apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml
}
prepare
dockerio
install_kubeadm
init_kubeadm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment