-
Notifications
You must be signed in to change notification settings - Fork 3
/
00-start-machines.sh
83 lines (71 loc) · 2.66 KB
/
00-start-machines.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
export PARTITION="nbg-w8101"
export MACHINE_SIZE="c1-xlarge-x86"
export PROJECT_NAME="k8s-the-hard-way"
export FIREWALL_IMAGE="firewall-ubuntu-2.0.20200617"
export WORKER_IMAGE="ubuntu-20.04.20200331"
# Create Test-Project
cloudctl project create \
--name ${PROJECT_NAME} \
--description "${PROJECT_NAME}"
export PROJECT_ID=$(metalctl project ls --name ${PROJECT_NAME} -o template --template "{{ .meta.id }}")
# Create Network
metalctl network allocate \
--name ${PROJECT_NAME} \
--partition ${PARTITION} \
--project ${PROJECT_ID}
export NETWORK_ID=$(metalctl network ls --project ${PROJECT_ID} -o template --template "{{ .id }}" )
# Create Firewall
metalctl firewall create \
--project=${PROJECT_ID} \
--partition=${PARTITION} \
--image=${FIREWALL_IMAGE} \
--size=${MACHINE_SIZE} \
--networks=${NETWORK_ID},internet \
--hostname=fw01
# Create Controllers
for i in {0..2}; do \
metalctl machine create \
--project=${PROJECT_ID} \
--partition=${PARTITION} \
--image=${WORKER_IMAGE} \
--size=${MACHINE_SIZE} \
--networks=${NETWORK_ID},internet \
--userdata "@./machine.ign" \
--hostname=controller-${i};
done
# Create Workers
for i in {0..2}; do \
metalctl machine create \
--project=${PROJECT_ID} \
--partition=${PARTITION} \
--image=${WORKER_IMAGE} \
--size=${MACHINE_SIZE} \
--networks=${NETWORK_ID},internet \
--userdata "@./machine.ign" \
--hostname=worker-${i};
done
# List external internet IPs of the machines
metalctl machine ls \
--project=${PROJECT_ID} \
-o template --template "{{ .allocation.hostname }} {{ index (index .allocation.networks 1).ips 0 }}" | grep controller
metalctl machine ls \
--project=${PROJECT_ID} \
-o template --template "{{ .allocation.hostname }} {{ index (index .allocation.networks 1).ips 0 }}" | grep worker
# List internal IPs of the machines
metalctl machine ls \
--project=${PROJECT_ID} \
-o template --template "{{ .allocation.hostname }} {{ index (index .allocation.networks 0).ips 0 }}" | grep controller
metalctl machine ls \
--project=${PROJECT_ID} \
-o template --template "{{ .allocation.hostname }} {{ index (index .allocation.networks 0).ips 0 }}" | grep worker
# Allocate public ip address for kube-apiserver
metalctl network ip allocate \
--name kubeapiserver \
--network internet \
--project ${PROJECT_ID}
export KUBERNETES_PUBLIC_ADDRESS=$(
metalctl network ip list \
--project ${PROJECT_ID} \
--network internet \
-o template --template "{{ .ipaddress }} {{ .name }}" | grep kubeapiserver | cut -d" " -f1)