forked from limx59/deploy-ibm-cloud-private
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
1222 lines (1142 loc) · 46 KB
/
Vagrantfile
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Licensed under Apache License Version 2.0
#
# @ Authur Tim Pouyer [email protected]
# https://raw.githubusercontent.com/IBM/deploy-ibm-cloud-private/master/LICENSE
# Software License Terms Acceptence (see https://hub.docker.com/r/ibmcom/icp-inception/)
# If you accept the Software license terms please change the value below to 'accept'
license = "not accepted"
# most laptops have at least 8 cores nowadays (adjust based on your laptop hardware)
cpus = '4'
# this will cause memory swaping in the VM
# performance is decent with SSD drives but may not be with spinning disks
#memory = '4096'
# use this setting for better performance if you have the ram available on your laptop
# uncomment the below line and comment out the above line "#memory = '4096'"
memory = '10240'
# Update version to pull a specific version i.e. version = '2.1.0-beta-1'
version = "2.1.0.1"
# host-only network segment - in most cases you do not have to change this value
# on some systems this network segment may overlap another network already on your
# system. In those cases you will need to change this value to another value
# i.e. 192.168.56 or 192.168.16 etc...
base_segment = '192.168.27'
# enable/disable cluster federation
federation_enabled = 'true'
# enable the metering service
# only used if version < 2.1.0-beta-3 see disabled_management_services below
metering_enabled = 'true'
# disabled mgmt services list
# "va" turns off vulnerability advisor
# "metering" turns off prometheus and grafana metering
# "monitoring" turns off monitoring services
disabled_management_services = '["va"]'
# use apt-cacher-ng & docker registry cache servers
# see instructions in the `README.md` under #Advanced Cache Setup
use_cache = 'false'
cache_host = '192.168.27.99'
apt_cache_port = '3142'
docker_registry_port = '5000'
helm_version = '2.6.0'
k8s_version = '1.8.3'
etcd_version = '3.1.5'
###############################################################################
# DO NOT MODIFY ANYTHING BELOW THIS POINT #
###############################################################################
cfc_config = "
---
# Network CNI
network_type: calico
# Network in IPv4 CIDR format
network_cidr: 10.1.0.0/16
# Kubernetes service IP range
service_cluster_ip_range: 10.0.0.1/24
# Flag to enable ldap with true, disabled by default.
ldap_enabled: false
# Config federation cluster
federation_enabled: #{federation_enabled}
federation_cluster: federation-cluster
federation_domain: cluster.federation
# federation_apiserver_extra_args: []
# federation_controllermanager_extra_args: []
ansible_user: vagrant
ansible_become: true
# enabled/disable python docker install
install_docker_py: false
# enable the metering service
metering_enabled: #{metering_enabled}
# disabled mgmt services list
disabled_management_services: #{disabled_management_services}
# following variables are used to pickup internal builds
version: latest
image_tag: latest
image_repo: ibmcom
private_registry_enabled: false
private_registry_server: placeholder.com
docker_username: placeholder
docker_password: placeholder
"
vm_name = "IBM-Cloud-Private-dev-edition"
user_home_path = ENV['HOME']
if Vagrant::Util::Platform.windows?
user_home_path = Vagrant::Util::Platform.fs_real_path(ENV['USERPROFILE'])
end
base_storage_disk_path = Vagrant::Util::Platform.fs_real_path("#{user_home_path}/VirtualBox VMs/#{vm_name}/ubuntu-16.04-amd64-disk001.vmdk")
lxd_storage_disk_path = Vagrant::Util::Platform.fs_real_path("#{user_home_path}/VirtualBox VMs/#{vm_name}/lxd_storage_disk.vmdk")
extra_storage_disk_path = Vagrant::Util::Platform.fs_real_path("#{user_home_path}/VirtualBox VMs/#{vm_name}/nfs_storage_disk.vmdk")
rsa_private_key = IO.read(Vagrant::Util::Platform.fs_real_path("#{Vagrant.user_data_path}/insecure_private_key"))
if !license.eql? 'accept'
if !File.exists?("license_accepted")
puts("################################################################################")
puts("# You must accept the terms of the Software License under which we are #")
puts("# providing the IBM Cloud Private community edition software. #")
puts("# #")
puts("# See license terms here: https://hub.docker.com/r/ibmcom/icp-inception/ #")
puts("################################################################################")
puts("Do You Accept the Terms of the Software License? [Y|n]")
response = STDIN.gets.chomp
if ['y','accept',''].include?(response.downcase)
license = 'accept'
puts("License Terms Accepted!")
File.write('license_accepted', 'license accepted')
else
puts("License Terms Not Accepted... exiting.")
exit 1
end
else # if we found the license_accepted file then proceed
license = 'accept'
end
end
image_repo = 'ibmcom'
private_registry_enabled = 'false'
private_registry_server = 'placeholder.com'
docker_username = 'placeholder'
docker_password = 'placeholder'
if File.exist?(".private")
load File.expand_path(".private")
version = $version
image_repo = $image_repo
private_registry_enabled = $private_registry_enabled
private_registry_server = $private_registry_server
docker_username = $docker_username
docker_password = $docker_password
helm_version = $helm_version
k8s_version = $k8s_version
etcd_version = $etcd_version
end
docker_mirror = ''
apt_proxy_conf = ''
if use_cache.downcase.eql? 'true'
docker_mirror = ",
\"registry-mirrors\": [\"http://#{cache_host}:#{docker_registry_port}\"]"
apt_proxy_conf = "
Acquire {
http {
Proxy \"http://#{cache_host}:#{apt_cache_port}/\";
security.ubuntu.com \"DIRECT\";
get.docker.com \"DIRECT\";
};
};"
end
configure_master_ssh_keys = <<SCRIPT
echo "#{rsa_private_key}" >> /home/vagrant/.ssh/id_rsa
echo "$(cat /home/vagrant/.ssh/authorized_keys)" >> /home/vagrant/.ssh/id_rsa.pub
echo 'StrictHostKeyChecking no\nUserKnownHostsFile /dev/null\nLogLevel QUIET' >> /home/vagrant/.ssh/config
SCRIPT
configure_swap_space = <<SCRIPT
sudo rm -f /mnt/swap
sudo fallocate -l 8g /mnt/swap
sudo chmod 600 /mnt/swap
sudo mkswap /mnt/swap
sudo swapon /mnt/swap
echo "/mnt/swap swap swap defaults 0 0" | sudo tee --append /etc/fstab > /dev/null
echo "vm.swappiness = 60" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "vm.vfs_cache_pressure = 10" | sudo tee --append /etc/sysctl.conf > /dev/null
sudo sysctl -p
SCRIPT
configure_performance_settings = <<SCRIPT
echo "net.ipv4.ip_forward = 1" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.ipv4.conf.all.rp_filter = 0" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.ipv4.conf.default.rp_filter = 0" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.ipv4.tcp_mem = 182757 243679 365514" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.core.netdev_max_backlog = 182757" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.ipv4.conf.eth1.proxy_arp = 1" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "fs.inotify.max_queued_events = 1048576" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "fs.inotify.max_user_instances = 1048576" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "fs.inotify.max_user_watches = 1048576" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "vm.max_map_count = 262144" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "kernel.dmesg_restrict = 0" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.ipv4.tcp_keepalive_time = 600" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.ipv4.tcp_keepalive_intvl = 60" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.ipv4.tcp_keepalive_probes = 20" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "net.bridge.bridge-nf-call-iptables = 1" | sudo tee --append /etc/sysctl.conf > /dev/null
echo "* soft nofile 1048576" | sudo tee --append /etc/security/limits.conf > /dev/null
echo "* hard nofile 1048576" | sudo tee --append /etc/security/limits.conf > /dev/null
echo "root soft nofile 1048576" | sudo tee --append /etc/security/limits.conf > /dev/null
echo "root hard nofile 1048576" | sudo tee --append /etc/security/limits.conf > /dev/null
echo "* soft memlock unlimited" | sudo tee --append /etc/security/limits.conf > /dev/null
echo "* hard memlock unlimited" | sudo tee --append /etc/security/limits.conf > /dev/null
sudo sysctl -p
echo Y | sudo tee /sys/module/fuse/parameters/userns_mounts
echo Y | sudo tee /sys/module/ext4/parameters/userns_mounts
sudo sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory swapaccount=1 /g' /etc/default/grub
sudo update-grub
SCRIPT
configure_apt_proxy = <<SCRIPT
sudo bash -c 'cat > /etc/apt/apt.conf.d/02apt-cacher' <<'EOF'
Acquire::http::Proxy "http://#{cache_host}:#{apt_cache_port}/";
Acquire::http::Proxy::security.ubuntu.com "DIRECT";
Acquire::http::Proxy::get.docker.com "DIRECT";
EOF
SCRIPT
install_icp_prereqs = <<SCRIPT
export DEBIAN_FRONTEND=noninteractive
sudo bash -c 'cat > /etc/apt/apt.conf.d/01lean' <<'EOF'
APT::Install-Suggests "0";
APT::Install-Recommends "0";
APT::AutoRemove::SuggestsImportant "false";
APT::AutoRemove::RecommendsImportant "false";
Dir::Cache "";
Dir::Cache::archives "";
EOF
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] http://download.docker.com/linux/ubuntu $(lsb\_release -cs) stable"
sudo apt-get update --yes --quiet
sudo apt-get install --yes --quiet --target-release=xenial-backports lxd lxd-client bridge-utils dnsmasq thin-provisioning-tools \
curl linux-image-extra-$(uname -r) linux-image-extra-virtual apt-transport-https ca-certificates software-properties-common \
docker-ce python-setuptools python-pip build-essential python-dev nfs-kernel-server nfs-common aufs-tools ntp criu
sudo -H pip install --upgrade pip
sudo -H pip install docker
sudo usermod -aG lxd vagrant
newgrp lxd
sudo usermod -aG docker vagrant
newgrp docker
sudo bash -c 'cat > /etc/docker/daemon.json' <<'EOF'
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m"
}#{docker_mirror}
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo bash -c 'cat > /etc/ntp.conf' <<'EOF'
server time1.google.com
server time2.google.com
server time3.google.com
server time4.google.com
EOF
sudo systemctl restart ntp
SCRIPT
add_storage_vol = <<SCRIPT
sudo pvcreate /dev/sdb
sudo vgextend vagrant-vg /dev/sdb
sudo lvcreate -l 100%FREE -n storage vagrant-vg
sudo mkfs -t ext4 /dev/mapper/vagrant--vg-storage
sudo mkdir /storage
sudo mount -t ext4 /dev/mapper/vagrant--vg-storage /storage
echo "/dev/mapper/vagrant--vg-storage /storage ext4 defaults 0 0" | sudo tee --append /etc/fstab > /dev/null
sudo chmod 777 /storage
SCRIPT
setup_nfs_shares = <<SCRIPT
# share the '/storage' directory on the nfs server
sudo mkdir /storage/share01 -p
sudo chmod 777 /storage/share01
sudo mkdir /storage/share02 -p
sudo chmod 777 /storage/share02
sudo mkdir /storage/share03 -p
sudo chmod 777 /storage/share03
sudo mkdir /storage/share04 -p
sudo chmod 777 /storage/share04
sudo mkdir /storage/share05 -p
sudo chmod 777 /storage/share05
sudo mkdir /storage/share06 -p
sudo chmod 777 /storage/share06
sudo mkdir /storage/share07 -p
sudo chmod 777 /storage/share07
sudo mkdir /storage/share08 -p
sudo chmod 777 /storage/share08
sudo mkdir /storage/share09 -p
sudo chmod 777 /storage/share09
sudo mkdir /storage/share10 -p
sudo chmod 777 /storage/share10
sudo mkdir /storage/share11 -p
sudo chmod 777 /storage/share11
sudo mkdir /storage/share12 -p
sudo chmod 777 /storage/share12
sudo mkdir /storage/share13 -p
sudo chmod 777 /storage/share13
sudo mkdir /storage/share14 -p
sudo chmod 777 /storage/share14
sudo mkdir /storage/share15 -p
sudo chmod 777 /storage/share15
sudo mkdir /storage/share16 -p
sudo chmod 777 /storage/share16
sudo mkdir /storage/share17 -p
sudo chmod 777 /storage/share17
sudo mkdir /storage/share18 -p
sudo chmod 777 /storage/share18
sudo mkdir /storage/share19 -p
sudo chmod 777 /storage/share19
sudo mkdir /storage/share20 -p
sudo chmod 777 /storage/share20
echo "/storage *(rw,sync,no_subtree_check,async,insecure,no_root_squash)" | sudo tee --append /etc/exports > /dev/null
sudo systemctl restart nfs-kernel-server
SCRIPT
configure_nat_iptable_rules = <<SCRIPT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
SCRIPT
configure_lxd = <<SCRIPT
sudo bash -c 'cat >> /etc/network/interfaces' <<'EOF'
post-up ifconfig eth1 promisc on
iface eth1 inet manual
EOF
sudo ufw disable
mkdir -p /home/vagrant/cluster
cat <<EOF | sudo -H lxd init --preseed
config:
images.auto_update_interval: 15
storage_pools:
- name: lxd
driver: lvm
config:
volume.size: 100GB
source: /dev/sdc
networks:
- name: lxdbr0
type: bridge
config:
bridge.driver: native
bridge.external_interfaces: eth1
bridge.mode: standard
ipv4.address: "#{base_segment}.100/24"
ipv4.dhcp: true
ipv4.dhcp.ranges: "#{base_segment}.100-#{base_segment}.254"
ipv4.firewall: false
ipv4.nat: true
ipv4.routing: true
ipv6.address: none
dns.domain: icp
dns.mode: managed
raw.dnsmasq: |
dhcp-option-force=26,9000
server=127.0.0.1
profiles:
- name: default
config:
boot.autostart: true
linux.kernel_modules: bridge,br_netfilter,x_tables,ip_tables,ip6_tables,ip_vs,ip_set,ipip,xt_mark,xt_multiport,ip_tunnel,tunnel4,netlink_diag,nf_conntrack,nfnetlink,nf_nat,overlay
raw.lxc: |
lxc.aa_profile=unconfined
lxc.mount.auto=proc:rw sys:rw cgroup-full:rw
lxc.cap.drop=
lxc.cgroup.devices.allow=a
security.nesting: "true"
security.privileged: "true"
user.network-config: |
version: 1
config:
- type: physical
name: eth0
subnets:
- type: dhcp
user.user-data: |
#cloud-config
disable_root: false
disable_root_opts:
users:
- default
- name: vagrant
sudo: ['ALL=(ALL:ALL) NOPASSWD:ALL']
groups: sudo, admin, users, vagrant
primary-group: vagrant
home: /home/vagrant
shell: /bin/bash
ssh-authorized-keys:
- $(cat ~/.ssh/id_rsa.pub)
ntp:
servers:
- time1.google.com
- time2.google.com
- time3.google.com
- time4.google.com
apt:
preserve_sources_list: true
conf: |
APT {
Get {
Assume-Yes "true";
Fix-Broken "true";
};
Install-Suggests "false";
Install-Recommends "false";
AutoRemove {
SuggestsImportant "false";
RecommendsImportant "false";
};
};
Dir {
Cache {
archives "";
};
};#{apt_proxy_conf}
sources:
source1:
source: "deb [arch=amd64] http://download.docker.com/linux/ubuntu $(lsb\_release -cs) stable"
key: |
$(curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sed 's/^/ /')
package_update: true
package_upgrade: true
package_reboot_if_required: true
packages:
- linux-image-extra-$(uname -r)
- linux-image-extra-virtual
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- squashfuse
- docker-ce
- python-setuptools
- python-pip
- build-essential
- python-dev
- aufs-tools
- nfs-common
runcmd:
- [ mkdir, -p, /var/lib/kubelet ]
- [ mount, -o, bind, /var/lib/kubelet, /var/lib/kubelet ]
- [ mount, --make-shared, /var/lib/kubelet ]
- [ ln, -s, /bin/true, /usr/local/bin/udevadm ]
- [ pip, install, --upgrade, pip ]
- [ pip, install, docker ]
- [ usermod, -aG, docker, vagrant ]
- [ ufw, disable ]
- [ touch, /DONE ]
write_files:
- content: |
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m"
}#{docker_mirror}
}
path: /etc/docker/daemon.json
devices:
aadisable:
path: /sys/module/nf_conntrack/parameters/hashsize
source: /dev/null
type: disk
aadisable1:
path: /sys/module/apparmor/parameters/enabled
source: /dev/null
type: disk
eth0:
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
root:
path: /
pool: lxd
type: disk
mem:
type: unix-char
path: /dev/mem
- name: worker1
config:
boot.autostart.delay: 15
boot.autostart.priority: 4
user.meta-data: |
hostname: worker1
fqdn: worker1.icp
manage_etc_hosts: true
devices:
eth0:
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
ipv4.address: #{base_segment}.101
- name: worker2
config:
boot.autostart.delay: 15
boot.autostart.priority: 5
user.meta-data: |
hostname: worker2
fqdn: worker2.icp
manage_etc_hosts: true
devices:
eth0:
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
ipv4.address: #{base_segment}.102
- name: worker3
config:
boot.autostart.delay: 15
boot.autostart.priority: 6
user.meta-data: |
hostname: worker3
fqdn: worker3.icp
manage_etc_hosts: true
devices:
eth0:
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
ipv4.address: #{base_segment}.103
EOF
sudo sed -i 's/127.0.0.1\tmaster.icp/#{base_segment}.100\tmaster.icp/g' /etc/hosts
SCRIPT
bring_up_icp_host_interface = <<SCRIPT
sudo ip link set dev eth1 up
SCRIPT
set_dnsnameserver_to_lxd_dnsmasq = <<SCRIPT
echo "nameserver #{base_segment}.100\nsearch icp\n" | sudo tee /etc/resolv.conf > /dev/null
SCRIPT
configure_icp_install = <<SCRIPT
cat > /home/vagrant/cluster/hosts <<'EOF'
[master]
#{base_segment}.100 kubelet_extra_args='["--fail-swap-on=false","--eviction-hard=memory.available<1Mi,nodefs.available<1Mi,nodefs.inodesFree<1%,imagefs.available<1Mi,imagefs.inodesFree<1%", "--image-gc-high-threshold=100%", "--image-gc-low-threshold=100%"]'
[worker]
#{base_segment}.101 kubelet_extra_args='["--fail-swap-on=false"]'
#{base_segment}.102 kubelet_extra_args='["--fail-swap-on=false"]'
[proxy]
#{base_segment}.100 kube_proxy_extra_args='["--proxy-mode=iptables"]'
EOF
echo "#{rsa_private_key}" > /home/vagrant/cluster/ssh_key
echo '#{cfc_config}' > /home/vagrant/cluster/config.yaml
sed -i "s/image_tag\: latest/image_tag\: #{version}/g" /home/vagrant/cluster/config.yaml
sed -i "s/version\: latest/version\: #{version}/g" /home/vagrant/cluster/config.yaml
sed -i "s|federation_enabled\: false|federation_enabled\: #{federation_enabled}|g" /home/vagrant/cluster/config.yaml
sed -i "s|metering_enabled\: false|metering_enabled\: #{metering_enabled}|g" /home/vagrant/cluster/config.yaml
sed -i "s|image_repo\: ibmcom|image_repo\: #{image_repo}|g" /home/vagrant/cluster/config.yaml
sed -i "s|private_registry_enabled\: false|private_registry_enabled\: #{private_registry_enabled}|g" /home/vagrant/cluster/config.yaml
sed -i "s|private_registry_server\: placeholder.com|private_registry_server\: #{private_registry_server}|g" /home/vagrant/cluster/config.yaml
sed -i "s|docker_username\: placeholder|docker_username\: #{docker_username}|g" /home/vagrant/cluster/config.yaml
sed -i "s|docker_password\: placeholder|docker_password\: #{docker_password}|g" /home/vagrant/cluster/config.yaml
cat /home/vagrant/cluster/config.yaml
SCRIPT
boot_lxd_worker_nodes = <<SCRIPT
lxc launch -p default -p worker1 ubuntu:16.04 worker1
lxc launch -p default -p worker2 ubuntu:16.04 worker2
SCRIPT
wait_for_worker_nodes_to_boot = <<SCRIPT
echo ""
echo "Preparing nodes for IBM Cloud Private community edition cluster installation."
echo "This process will take approximately 10-20 minutes depending on network speeds."
echo "Take a break and go grab a cup of coffee, we'll keep working on this while you're away ;-)"
echo ""
FILES="/home/vagrant/worker1
/home/vagrant/worker2"
for file in $FILES
do
while [ ! -f "$file" ]
do
filename=$(basename "$file")
lxc file pull -p $filename/DONE /home/vagrant/$filename &> /dev/null
printf "."
sleep 10
done
done
# sanity check (eth0 should be assigned on all 4 lxc nodes)
if [ "2" -gt "$(lxc list | grep -o eth0 | wc -l)" ]; then
echo "Failed to assign IP to lxc nodes..."
lxc exec worker1 -- cat /var/log/cloud-init-output.log | grep -C 3 error
lxc exec worker2 -- cat /var/log/cloud-init-output.log | grep -C 3 error
echo "You may need to change the 'base_segment' value in the 'Vagrantfile' to another subnet like '192.168.56'."
exit 1
fi
# sanity check (docker0 should be assigned on all 4 lxc nodes)
if [ "2" -gt "$(lxc list | grep -o docker0 | wc -l)" ]; then
echo "Failed to install docker on lxc nodes..."
lxc exec worker1 -- cat /var/log/cloud-init-output.log | grep -C 3 error
lxc exec worker2 -- cat /var/log/cloud-init-output.log | grep -C 3 error
echo "You may need to change the 'base_segment' value in the 'Vagrantfile' to another subnet like '192.168.56'."
exit 1
fi
echo "worker1.icp\t\t ready"
echo "worker2.icp\t\t ready"
SCRIPT
docker_login = <<SCRIPT
curl -fsSL https://clis.ng.bluemix.net/install/linux | bash &> /dev/null
bx plugin install container-registry -r Bluemix &> /dev/null
docker login -u #{docker_username} -p #{docker_password} #{private_registry_server}
SCRIPT
precache_images = <<SCRIPT
echo ""
echo "Seeding IBM Cloud Private installation by pre-caching required docker images."
echo "This may take a few minutes depending on your connection speed and reliability."
echo "Pre-caching docker images...."
echo "Pulling #{image_repo}/icp-inception:#{version}..."
docker pull #{image_repo}/icp-inception:#{version} &> /dev/null
echo "Pulling #{image_repo}/icp-datastore:#{version}..."
docker pull #{image_repo}/icp-datastore:#{version} &> /dev/null
echo "Pulling #{image_repo}/icp-platform-auth:#{version}..."
docker pull #{image_repo}/icp-platform-auth:#{version} &> /dev/null
echo "Pulling #{image_repo}/iam-token-service:#{version}..."
docker pull #{image_repo}/iam-token-service:#{version} &> /dev/null
echo "Pulling #{image_repo}/kubernetes:v#{k8s_version}..."
docker pull #{image_repo}/kubernetes:v#{k8s_version} &> /dev/null
echo "Pulling #{image_repo}/helm:v#{helm_version}..."
docker pull #{image_repo}/helm:v#{helm_version} &> /dev/null
echo "Pulling #{image_repo}/etcd:v#{etcd_version}..."
docker pull #{image_repo}/etcd:v#{etcd_version} &> /dev/null
SCRIPT
install_icp = <<SCRIPT
exec 3>&1 1>>icp_install_log 2>&1
sudo docker run -e LICENSE=#{license} --net=host -v "$(pwd)/cluster":/installer/cluster #{image_repo}/icp-inception:#{version} install | tee /dev/fd/3
if grep -q fatal icp_install_log; then
echo "FATAL ERROR OCCURRED DURING INSTALLATION :-(" 1>&3
cat icp_install_log | grep -C 3 fatal 1>&3
echo "The install log can be view with: " 1>&3
echo "vagrant ssh" 1>&3
echo "cat icp_install_log" 1>&3
exit 1
fi
SCRIPT
install_kubectl = <<SCRIPT
echo "Pulling #{image_repo}/kubernetes:v#{k8s_version}..."
sudo docker run -e LICENSE=#{license} --net=host -v /usr/local/bin:/data #{image_repo}/kubernetes:v#{k8s_version} cp /kubectl /data &> /dev/null
kubectl config set-credentials icpadmin --username=admin --password=admin &> /dev/null
kubectl config set-cluster icp --server=http://127.0.0.1:8888 --insecure-skip-tls-verify=true &> /dev/null
kubectl config set-context icp --cluster=icp --user=admin --namespace=default &> /dev/null
kubectl config use-context icp &> /dev/null
SCRIPT
create_persistant_volumes = <<SCRIPT
sleep 120
cat > volumes.yaml <<EOF
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol01
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share01
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol02
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share02
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol03
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share03
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol04
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share04
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol05
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share05
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol06
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share06
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol07
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share07
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol08
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share08
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol09
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share09
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol10
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share10
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol11
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share11
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol12
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share12
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol13
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share13
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol14
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share14
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol15
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share15
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol16
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share16
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol17
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share17
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol18
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share18
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol19
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share19
server: #{base_segment}.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol20
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /storage/share20
server: #{base_segment}.100
EOF
kubectl create -f /home/vagrant/volumes.yaml
SCRIPT
install_helm = <<SCRIPT
sudo docker run -t --entrypoint=/bin/cp -v /usr/local/bin:/data #{image_repo}/helm:v#{helm_version} /helm /data/ &> /dev/null
sudo mkdir -p /var/lib/helm &> /dev/null
export HELM_HOME=/var/lib/helm &> /dev/null
echo "HELM_HOME=/var/lib/helm" >> ~/.bash_profile &> /dev/null
sudo chown -R vagrant:vagrant /var/lib/helm &> /dev/null
helm init --client-only &> /dev/null
SCRIPT
install_startup_script = <<SCRIPT
sudo bash -c 'cat > /usr/local/bin/icp-ce-startup.sh' <<'EOF'
#!/bin/bash
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo ip link set dev eth1 up
echo "nameserver #{base_segment}.100" | sudo tee /etc/resolv.conf > /dev/null
echo "search icp" | sudo tee --append /etc/resolv.conf > /dev/null
sudo docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs sudo docker rm > /dev/null || true
sleep 180
kubectl config set-credentials icpadmin --username=admin --password=admin &> /dev/null
kubectl config set-cluster icp --server=http://127.0.0.1:8888 --insecure-skip-tls-verify=true &> /dev/null
kubectl config set-context icp --cluster=icp --user=admin --namespace=default &> /dev/null
kubectl config use-context icp &> /dev/null
kubectl get pods -o wide -n kube-system | grep "icp-ds" | cut -d ' ' -f 1 | xargs kubectl -n kube-system delete pods
sleep 120
while [[ '' != $(kubectl get pods --namespace kube-system | sed -n '1!p' | grep -v Running) ]]
do
kubectl get pods -o wide -n kube-system | grep "CrashLoopBackOff\\|Init" | cut -d ' ' -f 1 | xargs kubectl -n kube-system delete pods
sleep 120
done
EOF
sudo chmod 744 /usr/local/bin/icp-ce-startup.sh
sudo bash -c 'cat > /etc/systemd/system/icp-ce-startup.service' <<'EOF'
[Unit]
After=network.target
[Service]
ExecStart=/usr/local/bin/icp-ce-startup.sh
[Install]
WantedBy=default.target
EOF
sudo chmod 644 /etc/systemd/system/icp-ce-startup.service
sudo systemctl daemon-reload
sudo systemctl enable icp-ce-startup.service
SCRIPT