Last active
April 25, 2019 12:07
-
-
Save chrischdi/a6464fc398ae916b16616675150c58a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
set -x | |
VERSION="$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)" | |
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=$(apt-cache madison kubelet | grep $VERSION | head -1 | awk '{print $3}') \ | |
kubeadm=$(apt-cache madison kubeadm | grep $VERSION | head -1 | awk '{print $3}') \ | |
kubectl=$(apt-cache madison kubectl | grep $VERSION | head -1 | awk '{print $3}') | |
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 | |
kubectl --kubeconfig /etc/kubernetes/admin.conf taint node kube-master node-role.kubernetes.io/master- | |
} | |
prepare | |
dockerio | |
install_kubeadm | |
init_kubeadm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment