-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-cni-plugin.sh
executable file
·145 lines (125 loc) · 5.5 KB
/
get-cni-plugin.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
#!/bin/bash
####################################################################
# Kubernetes Installer for Master
# - Code by Jioh L. Jung
####################################################################
####################################################################
# Setup values
#- Log files
TMP_LOG_FILE=$(mktemp /tmp/output.XXXXXXXXXX)
#- Root Check
if (( EUID != 0 )); then
echo "You must be root to do this." 1>&2
exit 1
fi
#- Move Script directory as base
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "${BASE_DIR}"
#- Imports configure & functions
if [ -f "config" ]; then
chmod +x ./config
. ./config
fi
. ./default
. ./libs/functions
#command_exists docker || { echo ">> need docker install <<"; exit 1}
####################################################################
TIMESTAMPS="$(LC_ALL=c date)"
#- Functions
function get_docker_images() {
#> Fetch Images
CNI_PLUGINS="$1"
mkdir -p cni/${CNI_PLUGINS}
for j in $(cat cni/${CNI_PLUGINS}.yaml | grep "image:" | tr "'" ' ' | tr '"' ' ' | awk '{print $NF}')
do
case "$j" in
*:*)
# Do stuff
echo ">> Tag Existed"
;;
*)
# None
echo ">> No Tags"
j="$j:latest"
;;
esac
FN="cni/${CNI_PLUGINS}/$(echo "$j" | tr '[/]' '_' | tr '[:]' '+').tgz"
if [ -f "${FN}" ]; then
echo "> already exist. skipping..: $j"
continue
fi
echo "> trying pull image: $j"
docker pull "$j"
if [ -f "${FN}" ]; then
echo ">> File Existed: ${FN}"
if [ "${FN: -10}" == "latest.tgz" ]; then
echo ">> Overwrite (latest tag)"
echo "> ${j} Saving -> ${FN}.."
docker save ${j} | gzip -c > ${FN}
echo "> ${j} Done.."
fi
else
echo "> ${j} Saving -> ${FN}.."
docker save ${j} | gzip -c > ${FN}
echo "> ${j} Done.."
fi
docker rmi -f "$j"
done
}
#- Calico
#> Need URL Update from: https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/
#> For Calico to work correctly, you need to pass --pod-network-cidr=192.168.0.0/16 to kubeadm init or update the calico.yml file to match your Pod network. Note that Calico works on amd64 only.
echo "# Created: ${TIMESTAMPS}" > cni/calico.yaml
echo "#>> RBAC <<" >> cni/calico.yaml
curl -L https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml | \
sed "s,192.168.0.0/16,${K8S_POD_CIDR},g" | \
cat >> cni/calico.yaml
echo "---" >> cni/calico.yaml
echo "#>> Calico <<" >> cni/calico.yaml
curl -L https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml | \
sed "s,192.168.0.0/16,${K8S_POD_CIDR},g" | \
cat >> cni/calico.yaml
get_docker_images "calico"
#- Canal
#> Need URL Update from: https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/
#> For Canal to work correctly, --pod-network-cidr=10.244.0.0/16 has to be passed to kubeadm init. Note that Canal works on amd64 only.
echo "# Created: ${TIMESTAMPS}" > cni/canal.yaml
echo "#>> RBAC <<" >> cni/canal.yaml
curl -L https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/canal/rbac.yaml | \
sed "s,10.244.0.0/16,${K8S_POD_CIDR},g" | \
cat >> cni/canal.yaml
echo "---" >> cni/canal.yaml
curl -L https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/canal/canal.yaml | \
sed "s,10.244.0.0/16,${K8S_POD_CIDR},g" | \
cat >> cni/canal.yaml
get_docker_images "canal"
#- Flannel
#> Need URL Update from: https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/
#> For flannel to work correctly, you must pass --pod-network-cidr=10.244.0.0/16 to kubeadm init.
#> Set /proc/sys/net/bridge/bridge-nf-call-iptables to 1 by running sysctl net.bridge.bridge-nf-call-iptables=1 to pass bridged IPv4 traffic to iptables’ chains. This is a requirement for some CNI plugins to work, for more information please see here.
echo "# Created: ${TIMESTAMPS}" > cni/flannel.yaml
echo "#>> Flannel <<" >> cni/flannel.yaml
curl -L https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml | \
sed "s,10.244.0.0/16,${K8S_POD_CIDR},g" | \
cat >> cni/flannel.yaml
get_docker_images "flannel"
#- Romana
#> Set /proc/sys/net/bridge/bridge-nf-call-iptables to 1 by running sysctl net.bridge.bridge-nf-call-iptables=1 to pass bridged IPv4 traffic to iptables’ chains. This is a requirement for some CNI plugins to work, for more information please see here.
echo "# Created: ${TIMESTAMPS}" > cni/romana.yaml
echo "#>> Romana <<" >> cni/romana.yaml
curl -L https://raw.githubusercontent.com/romana/romana/master/containerize/specs/romana-kubeadm.yml | \
cat >> cni/romana.yaml
get_docker_images "romana"
#- Weave
#> Set /proc/sys/net/bridge/bridge-nf-call-iptables to 1 by running sysctl net.bridge.bridge-nf-call-iptables=1 to pass bridged IPv4 traffic to iptables’ chains. This is a requirement for some CNI plugins to work, for more information please see here.
echo "# Created: ${TIMESTAMPS}" > cni/weave.yaml
#>> fetch latest kubectl
curl -L --remote-name-all https://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION_TMP}/bin/linux/amd64/kubectl
chmod +x kubectl
mv -f kubectl /tmp/
echo "#>> Weave Net <<" >> cni/weave.yaml
curl -L "https://cloud.weave.works/k8s/net?k8s-version=$(/tmp/kubectl version | base64 | tr -d '\n')" | \
cat >> cni/weave.yaml
get_docker_images "weave"
curl -L git.io/weave -o cni/weave/weave
chmod a+x cni/weave/weave