Skip to content
This repository was archived by the owner on Oct 31, 2019. It is now read-only.

Commit f228b77

Browse files
committed
Clean up bootstrap shell scripts a bit.
1 parent 7d7fa24 commit f228b77

File tree

5 files changed

+63
-99
lines changed

5 files changed

+63
-99
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ $ terraform output ssh_private_key > generated/instances_id_rsa
165165
# Retrieve public IP for etcd nodes
166166
$ terraform output etcd_public_ips
167167
# Log in as user opc to the OEL OS
168-
$ ssh -i `pwd`/generated/instances_id_rsa oel@ETCD_INSTANCE_IP
168+
$ ssh -i `pwd`/generated/instances_id_rsa opc@ETCD_INSTANCE_IP
169169
# Retrieve public IP for k8s masters
170170
$ terraform output master_public_ips
171-
$ ssh -i `pwd`/generated/instances_id_rsa oel@K8SMASTER_INSTANCE_IP
171+
$ ssh -i `pwd`/generated/instances_id_rsa opc@K8SMASTER_INSTANCE_IP
172172
# Retrieve public IP for k8s workers
173173
$ terraform output worker_public_ips
174-
$ ssh -i `pwd`/generated/instances_id_rsa oel@K8SWORKER_INSTANCE_IP
174+
$ ssh -i `pwd`/generated/instances_id_rsa opc@K8SWORKER_INSTANCE_IP
175175
```
176176

177177
### Mandatory Input Variables:
@@ -232,7 +232,7 @@ worker_nodeport_ingress | 10.0.0.0/16 (VCN only) | A CIDR notation
232232
#### Software Versions Installed on OCI Instances
233233
name | default | description
234234
------------------------------------|--------------------|------------
235-
docker_ver | 17.03 | Version of Docker to install
235+
docker_ver | 17.03.1 | Version of Docker to install
236236
etcd_ver | v3.2.2 | Version of etcd to install
237237
flannel_ver | v0.7.1 | Version of Flannel to install
238238
k8s_ver | 1.7.4 | Version of K8s to install (master and workers)
@@ -356,7 +356,7 @@ See [CONTRIBUTING](CONTRIBUTING.md) for details.
356356
* Oracle Linux Enterprise (7.4)
357357
* etcd - (default v3.2.2)
358358
* flannel - (default v0.7.1)
359-
* docker - (default 17.03.0-ce)
359+
* docker - (default 17.03.1.ce)
360360
* apt-transport-https - (default 1.2.20)
361361
* kubernetes - (default v1.7.4)
362362
* master(s) (`kube-apiserver`, `kube-controller-manager`, `kube-scheduler`, `kubernetes-cni`, `kubectl`)

instances/etcd/cloud_init/bootstrap.template.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ iptables -F
2626
###################
2727
# etcd
2828

29-
# Get IP Adress of self
29+
# Get IP Address of self
3030
IP_LOCAL=$(ip route show to 0.0.0.0/0 | awk '{ print $5 }' | xargs ip addr show | grep -Po 'inet \K[\d.]+')
3131
SUBNET=$(getent hosts $IP_LOCAL | awk '{print $2}' | cut -d. -f2)
3232

@@ -45,11 +45,11 @@ docker run -d \
4545
-listen-peer-urls http://0.0.0.0:2380 \
4646
-discovery ${etcd_discovery_url}
4747

48-
# download etcdctl client etcd_ver
48+
# Download etcdctl client etcd_ver
4949
curl -L --retry 3 https://github.com/coreos/etcd/releases/download/${etcd_ver}/etcd-${etcd_ver}-linux-amd64.tar.gz -o /tmp/etcd-${etcd_ver}-linux-amd64.tar.gz
5050
tar zxf /tmp/etcd-${etcd_ver}-linux-amd64.tar.gz -C /tmp/ && cp /tmp/etcd-${etcd_ver}-linux-amd64/etcd* /usr/local/bin/
5151

52-
# Generate a flannel configuration that we will store into etcd using curl.
52+
# Generate a flannel configuration JSON that we will store into etcd using curl.
5353
cat >/tmp/flannel-network.json <<EOF
5454
{
5555
"Network": "${flannel_network_cidr}",

instances/k8smaster/scripts/setup.template.sh

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ export IP_LOCAL=$(ip route show to 0.0.0.0/0 | awk '{ print $5 }' | xargs ip add
1111

1212
SUBNET=$(getent hosts $IP_LOCAL | awk '{print $2}' | cut -d. -f2)
1313

14-
## download etcdctl client
14+
## etcd
1515
######################################
16+
17+
# Download etcdctl client
1618
curl -L --retry 3 https://github.com/coreos/etcd/releases/download/${etcd_ver}/etcd-${etcd_ver}-linux-amd64.tar.gz -o /tmp/etcd-${etcd_ver}-linux-amd64.tar.gz
1719
tar zxf /tmp/etcd-${etcd_ver}-linux-amd64.tar.gz -C /tmp/ && cp /tmp/etcd-${etcd_ver}-linux-amd64/etcd* /usr/local/bin/
1820

19-
# wait for etcd to become active (through the LB)
21+
# Wait for etcd to become active (through the LB)
2022
until [ $(/usr/local/bin/etcdctl --endpoints ${etcd_lb} cluster-health | grep '^cluster ' | grep -c 'is healthy$') == "1" ]; do
21-
echo "Waiting for cluster to be healthy"
23+
echo "Waiting for etcd cluster to be healthy"
2224
sleep 1
2325
done
2426

@@ -31,47 +33,20 @@ echo "IP_LOCAL: $IP_LOCAL ETCD_SERVER: $ETCD_SERVER"
3133
envsubst </root/services/flannel.service >/etc/systemd/system/flannel.service
3234
systemctl daemon-reload && systemctl enable flannel && systemctl start flannel
3335

34-
## INSTALL CNI PLUGIN
35-
######################################
36-
mkdir -p /opt/cni/bin /etc/cni/net.d
37-
curl -L --retry 3 https://github.com/containernetworking/cni/releases/download/v0.5.2/cni-amd64-v0.5.2.tgz -o /tmp/cni-plugin.tar.gz
38-
tar zxf /tmp/cni-plugin.tar.gz -C /opt/cni/bin/
39-
printf '{\n "name": "podnet",\n "type": "flannel",\n "delegate": {\n "isDefaultGateway": true\n }\n}\n' >/etc/cni/net.d/10-flannel.conf
40-
36+
# Create cni bridge interface w/ IP from flannel
4137
cp /root/services/cni-bridge.service /etc/systemd/system/cni-bridge.service
4238
cp /root/services/cni-bridge.sh /usr/local/bin/cni-bridge.sh && chmod +x /usr/local/bin/cni-bridge.sh
4339
systemctl enable cni-bridge && systemctl start cni-bridge
4440

45-
# Install Docker prereqs
46-
until yum -y install aufs-tools cgroupfs-mount libltdl7 unzip; do sleep 1 && echo -n "."; done
47-
48-
# Stage master certs
49-
unzip /tmp/k8s-certs.zip -d /etc/kubernetes/ssl/
50-
51-
# enable ol7 addons
52-
yum-config-manager --disable ol7_UEKR3
53-
yum-config-manager --enable ol7_addons ol7_latest ol7_UEKR4 ol7_optional ol7_optional_latest
54-
55-
# Install Docker
41+
## Docker
42+
######################################
5643
until yum -y install docker-engine-${docker_ver}; do sleep 1 && echo -n "."; done
5744

58-
systemctl stop docker
59-
60-
# Disable irqbalance for performance
61-
service irqbalance stop
62-
yum -y erase irqbalance
63-
45+
# Configure Docker to use flannel
6446
rm -f /lib/systemd/system/docker.service && cat /root/services/docker.service >/lib/systemd/system/docker.service
65-
systemctl enable docker
6647
systemctl daemon-reload
67-
systemctl restart docker
68-
69-
# re-enable autostart
70-
rm -f /usr/sbin/policy-rc.d
71-
72-
# Add default DNS
73-
echo "nameserver 169.254.169.254" >>/etc/resolvconf/resolv.conf.d/base
74-
resolvconf -u
48+
systemctl enable docker
49+
systemctl start docker
7550

7651
# Output /etc/environment_params
7752
echo "IPV4_PRIVATE_0=$IP_LOCAL" >>/etc/environment_params
@@ -97,10 +72,22 @@ setenforce 0
9772
systemctl stop firewalld.service
9873
systemctl disable firewalld.service
9974

75+
# Configure pod network:
76+
mkdir -p /etc/cni/net.d
77+
cat >/etc/cni/net.d/10-flannel.conf <<EOF
78+
{
79+
"name": "podnet",
80+
"type": "flannel",
81+
"delegate": {
82+
"isDefaultGateway": true
83+
}
84+
}
85+
EOF
86+
10087
## Install kubelet, kubectl, and kubernetes-cni
10188
###############################################
10289
yum-config-manager --add-repo http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
103-
until yum install -y kubelet-${k8s_ver}-0 kubectl-${k8s_ver}-0; do sleep 1 && echo -n ".";done
90+
until yum install -y kubelet-${k8s_ver}-0 kubectl-${k8s_ver}-0 kubernetes-cni; do sleep 1 && echo -n ".";done
10491

10592
# Pull etcd docker image from registry
10693
docker pull quay.io/coreos/etcd:${etcd_ver}
@@ -116,9 +103,7 @@ docker run -d \
116103
-discovery ${etcd_discovery_url} \
117104
--proxy on
118105

119-
## Kubelet for the master
120-
systemctl stop kubelet
121-
rm /lib/systemd/system/kubelet.service
106+
## kubelet for the master
122107
systemctl daemon-reload
123108
sed -e "s/__FQDN_HOSTNAME__/$FQDN_HOSTNAME/g" /root/services/kubelet.service >/etc/systemd/system/kubelet.service
124109
systemctl daemon-reload
@@ -127,7 +112,7 @@ systemctl start kubelet
127112

128113
until kubectl get all; do sleep 1 && echo -n "."; done
129114

130-
## wait for k8smaster to be healthy. possible race on pod networks otherwise
115+
## Wait for k8s master to be available. There is a possible race on pod networks otherwise.
131116
until [ "$(curl localhost:8080/healthz 2>/dev/null)" == "ok" ]; do
132117
sleep 3
133118
done
@@ -138,4 +123,4 @@ kubectl create -f /root/services/kube-dns.yaml
138123
## install kubernetes-dashboard
139124
kubectl create -f /root/services/kubernetes-dashboard.yaml
140125

141-
echo "Finished running setup.sh"
126+
echo "Finished running setup.sh"

instances/k8sworker/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "oci_core_instance" "TFInstanceK8sWorker" {
2323
when = "destroy"
2424

2525
inline = [
26-
"nodeName=`getent hosts $(ip route get 1 | awk '{print $NF;exit}') | awk '{print $2}'`",
26+
"nodeName=`getent hosts $(/usr/sbin/ip route get 1 | awk '{print $NF;exit}') | awk '{print $2}'`",
2727
"[ -e /usr/bin/kubectl ] && sudo kubectl --kubeconfig /etc/kubernetes/manifests/worker-kubeconfig.yaml drain $nodeName --force",
2828
"[ -e /usr/bin/kubectl ] && sudo kubectl --kubeconfig /etc/kubernetes/manifests/worker-kubeconfig.yaml delete node $nodeName",
2929
"exit 0",

instances/k8sworker/scripts/setup.template.sh

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ EXTERNAL_IP=$(curl -s -m 10 http://whatismyip.akamai.com/)
44
NAMESPACE=$(echo -n "${domain_name}" | sed "s/\.oraclevcn\.com//g")
55
FQDN_HOSTNAME=$(getent hosts $(ip route get 1 | awk '{print $NF;exit}') | awk '{print $2}')
66

7-
# pull instance metadata
7+
# Pull instance metadata
88
curl -sL --retry 3 http://169.254.169.254/opc/v1/instance/ | tee /tmp/instance_meta.json
99

10-
## create policy file that blocks autostart of services on install
10+
## Create policy file that blocks autostart of services on install
1111
printf '#!/bin/sh\necho "All runlevel operations denied by policy" >&2\nexit 101\n' >/tmp/policy-rc.d && chmod +x /tmp/policy-rc.d
1212
export K8S_API_SERVER_LB=${master_lb}
1313
export ETCD_LB=${etcd_lb}
@@ -19,14 +19,16 @@ export IP_LOCAL=$(ip route show to 0.0.0.0/0 | awk '{ print $5 }' | xargs ip add
1919
SUBNET=$(getent hosts $IP_LOCAL | awk '{print $2}' | cut -d. -f2)
2020
export WORKER_IP=$IP_LOCAL
2121

22-
## download etcdctl client
22+
## etcd
2323
######################################
24+
25+
# Download etcdctl client
2426
curl -L --retry 3 https://github.com/coreos/etcd/releases/download/${etcd_ver}/etcd-${etcd_ver}-linux-amd64.tar.gz -o /tmp/etcd-${etcd_ver}-linux-amd64.tar.gz
2527
tar zxf /tmp/etcd-${etcd_ver}-linux-amd64.tar.gz -C /tmp/ && cp /tmp/etcd-${etcd_ver}-linux-amd64/etcd* /usr/local/bin/
2628

27-
# wait for etcd to become active (through the LB)
29+
# Wait for etcd to become active (through the LB)
2830
until [ $(/usr/local/bin/etcdctl --endpoints ${etcd_lb} cluster-health | grep '^cluster ' | grep -c 'is healthy$') == "1" ]; do
29-
echo "Waiting for cluster to be healthy"
31+
echo "Waiting for etcd cluster to be healthy"
3032
sleep 1
3133
done
3234

@@ -39,47 +41,21 @@ echo "IP_LOCAL: $IP_LOCAL ETCD_SERVER: $ETCD_SERVER"
3941
envsubst </root/services/flannel.service >/etc/systemd/system/flannel.service
4042
systemctl daemon-reload && systemctl enable flannel && systemctl start flannel
4143

42-
## INSTALL CNI PLUGIN
44+
## Create cni bridge interface w/ IP from flannel
4345
######################################
44-
mkdir -p /opt/cni/bin /etc/cni/net.d
45-
curl -L --retry 3 https://github.com/containernetworking/cni/releases/download/v0.5.2/cni-amd64-v0.5.2.tgz -o /tmp/cni-plugin.tar.gz
46-
tar zxf /tmp/cni-plugin.tar.gz -C /opt/cni/bin/
47-
printf '{\n "name": "podnet",\n "type": "flannel",\n "delegate": {\n "isDefaultGateway": true\n }\n}\n' >/etc/cni/net.d/10-flannel.conf
4846
cp /root/services/cni-bridge.service /etc/systemd/system/cni-bridge.service
4947
cp /root/services/cni-bridge.sh /usr/local/bin/cni-bridge.sh && chmod +x /usr/local/bin/cni-bridge.sh
5048
systemctl enable cni-bridge && systemctl start cni-bridge
5149

52-
###################################### DOCKER ######################################
53-
54-
## Install Docker prereqs
50+
## Docker
5551
######################################
56-
until yum -y install aufs-tools cgroupfs-mount libltdl7 unzip; do sleep && echo -n "."; done
57-
58-
# Stage worker certs
59-
unzip /tmp/k8s-certs.zip -d /etc/kubernetes/ssl/
60-
61-
# enable ol7 addons
62-
yum-config-manager --disable ol7_UEKR3
63-
yum-config-manager --enable ol7_addons ol7_latest ol7_UEKR4 ol7_optional ol7_optional_latest
64-
65-
# Install Docker
6652
until yum -y install docker-engine-${docker_ver}; do sleep 1 && echo -n "."; done
67-
systemctl stop docker
68-
69-
# Disable irqbalance for performance
70-
service irqbalance stop
71-
yum -y erase irqbalance
7253

54+
# Configure Docker to use flannel
7355
rm -f /lib/systemd/system/docker.service && cat /root/services/docker.service >/lib/systemd/system/docker.service
74-
systemctl enable docker
7556
systemctl daemon-reload
76-
systemctl restart docker
77-
78-
79-
## Add default DNS
80-
######################################
81-
echo "nameserver 169.254.169.254" >>/etc/resolvconf/resolv.conf.d/base
82-
resolvconf -u
57+
systemctl enable docker
58+
systemctl start docker
8359

8460
## Output /etc/environment_params
8561
######################################
@@ -92,7 +68,6 @@ echo "FQDN_HOSTNAME=$FQDN_HOSTNAME" >>/etc/environment_params
9268
######################################
9369
iptables -F
9470

95-
9671
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
9772
[kubernetes]
9873
name=Kubernetes
@@ -109,17 +84,22 @@ setenforce 0
10984
systemctl stop firewalld.service
11085
systemctl disable firewalld.service
11186

87+
# Configure pod network:
88+
mkdir -p /etc/cni/net.d
89+
cat >/etc/cni/net.d/10-flannel.conf <<EOF
90+
{
91+
"name": "podnet",
92+
"type": "flannel",
93+
"delegate": {
94+
"isDefaultGateway": true
95+
}
96+
}
97+
EOF
98+
11299
## Install kubelet, kubectl, and kubernetes-cni
113100
###############################################
114101
yum-config-manager --add-repo http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
115-
until yum install -y kubelet-${k8s_ver}-0 kubectl-${k8s_ver}-0; do sleep 1 && echo -n ".";done
116-
117-
until systemctl stop kubelet; do sleep 1; done
118-
mkdir -p /opt/cni/bin /etc/cni/net.d
119-
tar zxf /tmp/cni-plugin.tar.gz -C /opt/cni/bin/
120-
printf '{\n "name": "podnet",\n "type": "flannel",\n "delegate": {\n "isDefaultGateway": true\n }\n}\n' >/etc/cni/net.d/10-flannel.conf
121-
122-
###################################### ETCD ######################################
102+
until yum install -y kubelet-${k8s_ver}-0 kubectl-${k8s_ver}-0 kubernetes-cni; do sleep 1 && echo -n ".";done
123103

124104
## Pull etcd docker image from registry
125105
docker pull quay.io/coreos/etcd:${etcd_ver}
@@ -140,9 +120,8 @@ docker run -d \
140120
sed -e "s/__FQDN_HOSTNAME__/$FQDN_HOSTNAME/g" /etc/kubernetes/manifests/kube-proxy.yaml >/tmp/kube-proxy.yaml
141121
cat /tmp/kube-proxy.yaml >/etc/kubernetes/manifests/kube-proxy.yaml
142122

143-
## Kubelet for the worker
123+
## kubelet for the worker
144124
######################################
145-
rm /lib/systemd/system/kubelet.service
146125
systemctl daemon-reload
147126

148127
AVAILABILITY_DOMAIN=$(jq -r '.availabilityDomain' /tmp/instance_meta.json | sed 's/:/-/g')
@@ -160,7 +139,7 @@ sed -e "s/__FQDN_HOSTNAME__/$FQDN_HOSTNAME/g" \
160139
-e "s/__NODE_SHAPE__/$NODE_SHAPE/g" \
161140
/root/services/kubelet.service > /etc/systemd/system/kubelet.service
162141

163-
## wait for k8smaster to be available. possible race on pod networks otherwise
142+
## Wait for k8s master to be available. There is a possible race on pod networks otherwise.
164143
until [ "$(curl -k --cert /etc/kubernetes/ssl/apiserver.pem --key /etc/kubernetes/ssl/apiserver-key.pem $K8S_API_SERVER_LB/healthz 2>/dev/null)" == "ok" ]; do
165144
sleep 3
166145
done

0 commit comments

Comments
 (0)