-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.sh
executable file
·188 lines (159 loc) · 5.96 KB
/
install.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
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
#!/usr/bin/env bash
set -e -o pipefail
# Usage:
# ./install.sh
# Get the latest release version number
if [[ -z "${VERSION}" ]]; then
VERSION=$(curl -s https://api.github.com/repos/openshift/microshift/releases | grep tag_name | grep -v nightly | head -n 1 | cut -d '"' -f 4)
fi
echo "Install MicroShift version: ${VERSION}"
# Function to get Linux distribution
get_distro() {
DISTRO=$(grep -E '^(ID)=' /etc/os-release| sed 's/"//g' | cut -f2 -d"=")
if [[ $DISTRO != @(ubuntu) ]]; then
echo "This Linux distro is not supported by the install script: ${DISTRO}"
exit 1
fi
}
# Function to get system architecture
get_arch() {
ARCH=$(uname -m | sed "s/x86_64/amd64/" | sed "s/aarch64/arm64/")
if [[ $ARCH != @(amd64|arm64) ]]; then
printf "arch %s unsupported" "$ARCH" >&2
exit 1
fi
}
# Function to get OS version
get_os_version() {
OS_VERSION=$(grep -E '^(VERSION_ID)=' /etc/os-release | sed 's/"//g' | cut -f2 -d"=")
}
# Install dependencies
install_dependencies() {
case $DISTRO in
"ubuntu")
sudo apt-get install -y \
policycoreutils-python-utils \
conntrack \
firewalld
;;
esac
}
# Establish Iptables rules
establish_firewall () {
sudo systemctl enable firewalld --now
sudo firewall-cmd --zone=public --permanent --add-port=6443/tcp
sudo firewall-cmd --zone=public --permanent --add-port=30000-32767/tcp
sudo firewall-cmd --zone=public --permanent --add-port=2379-2380/tcp
sudo firewall-cmd --zone=public --add-masquerade --permanent
sudo firewall-cmd --zone=public --add-port=10250/tcp --permanent
sudo firewall-cmd --zone=public --add-port=10251/tcp --permanent
sudo firewall-cmd --permanent --zone=trusted --add-source=10.42.0.0/16
sudo firewall-cmd --reload
}
# Install CRI-O depending on the distro
install_crio() {
case $DISTRO in
"ubuntu")
CRIOVERSION=1.21
OS=xUbuntu_$OS_VERSION
KEYRINGS_DIR=/usr/share/keyrings
sudo apt-get update -y
sudo apt-get install -y ca-certificates curl gnupg
echo "deb [signed-by=$KEYRINGS_DIR/libcontainers-archive-keyring.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list > /dev/null
echo "deb [signed-by=$KEYRINGS_DIR/libcontainers-crio-archive-keyring.gpg] http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIOVERSION/$OS/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$CRIOVERSION.list > /dev/null
sudo mkdir -p $KEYRINGS_DIR
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | sudo gpg --batch --yes --dearmor -o $KEYRINGS_DIR/libcontainers-archive-keyring.gpg
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIOVERSION/$OS/Release.key | sudo gpg --batch --yes --dearmor -o $KEYRINGS_DIR/libcontainers-crio-archive-keyring.gpg
sudo apt-get update -y
# Vagrant Ubuntu VMs don't provide containernetworking-plugins by default
sudo apt-get install -y \
cri-o cri-o-runc cri-tools \
containernetworking-plugins
;;
esac
}
# CRI-O config to match MicroShift networking values
crio_conf() {
sudo sh -c 'cat << EOF > /etc/cni/net.d/100-crio-bridge.conf
{
"cniVersion": "0.4.0",
"name": "crio",
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"hairpinMode": true,
"ipam": {
"type": "host-local",
"routes": [
{ "dst": "0.0.0.0/0" }
],
"ranges": [
[{ "subnet": "10.42.0.0/24" }]
]
}
}
EOF'
}
# Start CRI-O
verify_crio() {
sudo systemctl enable crio
sudo systemctl restart crio
}
# Download and install oc/kubectl
get_oc_kubectl() {
curl -O https://mirror.openshift.com/pub/openshift-v4/$ARCH/clients/ocp/stable/openshift-client-linux.tar.gz
sudo tar -xf openshift-client-linux.tar.gz -C /usr/local/bin oc kubectl
}
# Download and install microshift
get_microshift() {
curl -LO https://github.com/openshift/microshift/releases/download/$VERSION/microshift-linux-$ARCH
curl -LO https://github.com/openshift/microshift/releases/download/$VERSION/release.sha256
BIN_SHA="$(sha256sum microshift-linux-$ARCH | awk '{print $1}')"
KNOWN_SHA="$(grep "microshift-linux-$ARCH" release.sha256 | awk '{print $1}')"
if [[ "$BIN_SHA" != "$KNOWN_SHA" ]]; then
echo "SHA256 checksum failed"
exit 1
fi
sudo chmod +x microshift-linux-$ARCH
sudo mv microshift-linux-$ARCH /usr/local/bin/microshift
cat << EOF | sudo tee /usr/lib/systemd/system/microshift.service
[Unit]
Description=Microshift
After=crio.service
[Service]
WorkingDirectory=/usr/local/bin/
ExecStart=microshift run
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
if [[ "$DISTRO" == "ubuntu" ]] && [[ "$OS_VERSION" == "18.04" ]]; then
sudo sed -i 's|^ExecStart=microshift|ExecStart=/usr/local/bin/microshift|' /usr/lib/systemd/system/microshift.service
fi
sudo systemctl enable microshift.service --now
}
# Locate kubeadmin configuration to default kubeconfig location
prepare_kubeconfig() {
mkdir -p $HOME/.kube
if [[ -f $HOME/.kube/config ]]; then
mv $HOME/.kube/config $HOME/.kube/config.orig
fi
sudo KUBECONFIG=/var/lib/microshift/resources/kubeadmin/kubeconfig:$HOME/.kube/config.orig /usr/local/bin/kubectl config view --flatten | sudo tee $HOME/.kube/config > /dev/null
}
# Script execution
get_distro
get_arch
get_os_version
install_dependencies
#establish_firewall
install_crio
crio_conf
verify_crio
get_oc_kubectl
get_microshift
until sudo test -f /var/lib/microshift/resources/kubeadmin/kubeconfig; do
sleep 2
done
prepare_kubeconfig